First Device Setup
From zero to live data: create an application, register a device, connect it, and see its readings
By the end of this guide, a device (or your laptop pretending to be one) will be sending readings that you can see in Sensorclouds.
What you'll need
- The Admin or Engineer role
- Either a real device with MQTT, or a computer with an MQTT command-line client
(
mosquitto_pub) or Python
Step 1: Create an application
Open Applications and click Add Application.
Enter an Application ID, for example weather-stations (lowercase letters, numbers, and
hyphens; it can't be changed later).
Enter an Application Name, for example "Weather Stations".
Click Create Application.
Step 2: Create a device profile
Open Device Profiles and click Add Device Profile.
Enter a Profile Name, for example "Weather Node (JSON)". The Profile Key fills in for you.
Choose Device Type Sensor and Transport Type MQTT, then click Create Profile.
Click the new profile, open its Payload Formatter tab, and set Codec Type to CUSTOM - JavaScript decoder function.
Replace the sample script in Decoder Script with the JSON decoder:
function decodeUplink(input) {
var text = String.fromCharCode.apply(null, input.bytes);
return { data: JSON.parse(text) };
}Click Save Configuration.
Don't skip steps 4–6. A new profile starts on codec NONE, which shows messages in Live Data but stores no fields.
To test the decoder before any device exists, paste
eyJ0ZW1wZXJhdHVyZSI6MjEuNX0= (that's {"temperature":21.5} in base64) into Sample
Payload and click Run Test. You should see temperature: 21.5 under Decoded Output.
Step 3: Register the device
Open your application, then End Devices, and click Add Device.
Select the profile, enter a Name such as Station-001, and click Create Device.
Step 4: Get the credentials
Open the device and go to Settings.
Copy the Device Token. It's the MQTT username and client ID.
Click Generate Password and copy it now. It's shown only once.
Go to the Overview tab and copy the Telemetry and Status topics from MQTT Topics.
Step 5: Send a reading
Option A - command line:
mosquitto_pub -h mqtt.sensorclouds.app -p 8883 --capath /etc/ssl/certs \
-i "DEVICE_TOKEN" -u "DEVICE_TOKEN" -P "MQTT_PASSWORD" -q 1 \
-t "PASTE_DATA_TOPIC" \
-m '{"temperature": 23.5, "humidity": 60}'Option B - Python or ESP32: use the complete clients in Code Examples.
Step 6: See it arrive
Open the application's Live Data page.
You should see Uplink received for Station-001.
Click the row. Decoded payload shows temperature: 23.5 and humidity: 60.
On the device's Overview tab, Latest Telemetry shows the same values.
Stuck?
| You see | Do this |
|---|---|
| Nothing in Live Data | Check the topic, token, and password. See Connection Troubleshooting |
| Uplink received, but no decoded fields | The profile is on NONE, or the decoder isn't saved. Repeat step 2 |
| Decode failed | The payload isn't valid JSON. Check the quotes in your -m message |
Step 7: Make status accurate (recommended)
For a real device, set a Last Will of {"status":"offline"} on the status topic, and publish
{"status":"online"} after connecting. The Code Examples do this for you. See
Device Status.