Quickstart -> Devices
Let's add a few devices for our wildlife sanctuary. We will have the following devices in our wildlife sanctuary to begin with:
- Environment Monitoring Sensors
- Drones
- Gate Controllers
For now, we'll just get these devices connected to Fostrom, and in the subsequent sections, we'll get the first two to send data and messages, and get the gate controllers to receive messages and act accordingly.
Adding a Device
Head over the Devices
tab in your fleet, and click on the New Device
button. You need to provide a unique name to each device. Device names, as with all the other resources inside the fleet, are unique to the fleet.
You can also provide a set of tags, and a description. We'll use tags to easily broadcast certain messages to other devices. Tags are also helpful to group devices together while filtering.
Create the following devices:
env-sensor-1 # tags: `env-sensors zone-a`
env-sensor-2 # tags: `env-sensors zone-b`
env-sensor-3 # tags: `env-sensors zone-b`
drone-1 # tags: `drones`
drone-2 # tags: `drones`
drone-3 # tags: `drones`
zone-a-gate # tags: `gates zone-a`
zone-b-small-gate # tags: `gates zone-b`
zone-b-large-gate # tags: `gates zone-b`
Connecting a Device to Fostrom
Now that we've added a few devices, we can get the actual device connected to Fostrom. Currently, we have two protocols to connect over: MQTT or HTTP. Since its easier to demonstrate using curl
, we'll use HTTP here, but you can use any MQTT client in any language to connect to Fostrom. Head over to the MQTT for more details.
Since we're using HTTP, all we need to do is to send a heartbeat to Fostrom with the correct device credentials. Get the device credentials from your device page by clicking the Connection
button. There are three credentials shown there, all three we need: Fleet ID
, Device ID
, and Device Secret
.
For example, these are our connection details for one of the drones:
Fleet ID: 3VJSKCXX
Device ID: 63MKS3EA07
Device Secret: FOS-FF9F9B89C66453490F062CC49622F5F3
To send a heartbeat, simply run this on the command line:
curl https://device.fostrom.dev/v1/heartbeat \
-XPOST \
-H 'X-Fleet-ID: <your-fleet-id>' \
-H 'X-Device-ID: <your-device-id>' \
-H 'X-Device-Secret: <your-device-secret>'
You should get the following response:
{"ok": true}
You'll see a blue dot after a few seconds in the Devices tab, next to your device. The blue dot indicates the device is active, but does not hold an open socket with Fostrom (since HTTP closes the connection immediately). If you connect over MQTT and keep a long-running connection open, you will see a green dot instead.
You can send heartbeats for other devices over HTTP, or try connecting some of them over MQTT. MQTT libraries usually automatically send a PINGREQ
packet periodically, so you don't need to worry about sending heartbeats manually.
Now that we've got our devices setup and connected to Fostrom, let's get our devices to send datapoints to Fostrom.