Connecting Your Device
Connect a device to Sensorclouds, send its first reading, and set up online/offline status
This page takes a registered device from "nothing" to "first reading in Live Data".
Before you begin
- A registered device. See Registering Devices.
- Its Device Token and MQTT password, from Device → Settings.
- Its topics, from Device → Overview → MQTT Topics (use the copy buttons).
- A device profile using the CUSTOM codec with a decoder for your payload. For JSON, use the JSON decoder.
Step 1: Configure the connection
| Parameter | Value |
|---|---|
| Host | mqtt.sensorclouds.app |
| Port | 8883 |
| TLS | On. Trust the Let's Encrypt ISRG Root X1 certificate (most systems already do) |
| Username | Device Token, for example dev_9f2c41a7… |
| Password | The generated MQTT password |
| Client ID | Device Token |
| Keep-alive | The same as the profile (60 seconds by default) |
Step 2: Set the Last Will (before connecting)
Registering a Last Will lets the broker mark the device offline automatically if it drops.
| Setting | Value |
|---|---|
| Will topic | tenant/{tenantId}/app/{applicationId}/device/{deviceToken}/status |
| Will payload | {"status": "offline"} |
| Will QoS | 1 |
| Will retain | true |
Step 3: Connect and publish your first reading
Publish JSON to the data topic:
tenant/{tenantId}/app/{applicationId}/device/{deviceToken}/data{"temperature": 21.5, "humidity": 48}Quick test from a computer (with the mosquitto_pub MQTT command-line client installed):
mosquitto_pub \
-h mqtt.sensorclouds.app -p 8883 \
--capath /etc/ssl/certs \
-i "dev_9f2c41a7..." -u "dev_9f2c41a7..." -P "YOUR_MQTT_PASSWORD" \
-q 1 \
-t "tenant/TENANT_ID/app/APP_ID/device/dev_9f2c41a7.../data" \
-m '{"temperature": 21.5, "humidity": 48}'On Windows or macOS, replace --capath /etc/ssl/certs with
--cafile isrgrootx1.pem (download it from letsencrypt.org).
Step 4: Set up online / offline status
Right after connecting, publish to the status topic with retain = true:
{"status": "online"}Together with the Last Will, this gives you accurate online/offline status. See Device Status.
Step 5: Subscribe to commands
Subscribe to the command topic (QoS 1) so the device can receive commands and firmware updates:
tenant/{tenantId}/app/{applicationId}/device/{deviceToken}/cmdSee Command Lifecycle for the message format and how to acknowledge.
Step 6: Verify
Open the application's Live Data page. You should see Uplink received within a second or two.
Click the row. Decoded payload should show your fields.
The device's status should read ONLINE.
| You see | Next step |
|---|---|
| Uplink received with fields | You're done. Build a dashboard |
| Uplink received, but no decoded fields | Set the profile's codec to CUSTOM with a decoder |
| Decode failed | Fix the decoder. See Payload Decoder |
| Nothing at all | See Connection Troubleshooting |