Your first telemetry
On this page
Everything so far has been groundwork. Now the payoff: a real number leaving your device, crossing the internet, and appearing on a dashboard you can open from your phone. You will do it with the mental model you already have, a broker, a topic, and a publish, plus real credentials.
Step 1: Create a device and get its credentials
On siliconwit.io, open Add Device and choose Define my own device. You give it a name and it hands you two things that are the entire security model:
- a Device ID that looks like
SWD-XXXXXX, which doubles as the MQTT username, and - an Access Token, which is the MQTT password.
Treat the Access Token like a password, because it is one. Anyone who has it can publish as your device.
Step 2: The four facts you connect with
Every device on siliconwit.io connects with the same handful of facts, and a broker you run needs the same ones. Write them down once and reuse them:
Notice the topic is exactly the d/<id>/t pattern from the last lesson: d for device, your ID, and t for telemetry. The payload is plain JSON, so anything, a dashboard, an alert rule, another program, can read it.
Step 3: Publish a reading
With a TLS MQTT client connected (the capstone walks through the full Wi-Fi and TLS setup on an ESP32), publishing is a few lines. You build the JSON, build the topic from your Device ID, and hand it to the broker:
// once Wi-Fi and a TLS MQTT client are connected
// (the capstone has the full setup, this is the part that matters)
const char* DEVICE_ID = "SWD-XXXXXX"; // your Device ID = the MQTT username
const char* ACCESS_TOKEN = "your-access-token"; // = the MQTT password
const char* MQTT_HOST = "mqtt.siliconwit.io";
const int MQTT_PORT = 8883; // TLS is required
void publishReading(float tempC, float humidity) {
char payload[64];
snprintf(payload, sizeof(payload),
"{\"temperature\":%.1f,\"humidity\":%.1f}",
tempC, humidity);
String topic = String("d/") + DEVICE_ID + "/t"; // your telemetry topic
mqtt.publish(topic.c_str(), payload); // push it to the broker
} Call publishReading() every 30 seconds or so with a fresh sensor value. That is it. You push to a topic, and whatever subscribes to it, the service or your own database, takes it from there.
Step 4: Watch it move
Back on siliconwit.io, open your device. Within a few seconds of the first publish you will see the reading land, and then update live as each new one arrives. On a broker you run, mosquitto_sub -t 'd/#' -v shows the same reading arrive. That live number is the whole point of this course: your device is no longer a thing on a bench you have to trust blindly, it is a thing you can see from anywhere.
Check yourself
In the MQTT connection, what is the Access Token used as?
Why does the platform require port 8883 with TLS?
Your device connects fine but nothing appears on the dashboard. What is the first thing to check?
Which topic does a device publish its telemetry to?
- A device gets a Device ID (the MQTT username) and an Access Token (the password); guard the token.
- Connect over TLS on port 8883, publish JSON to
d/<id>/t. - Any MQTT broker takes the same publish; only the host, port, username and password change.
You just took a device from offline to streaming live. The natural next step is to build the whole thing end to end, real sensor, real wiring, full firmware, on a broker you run. That is the flagship capstone.
Discussion
No comments yet. Questions, results from your own build, a better way to explain it: all welcome.
My notes on this page
Kept on this device only. Nothing is sent anywhere.
Tip: select words in the lesson, or tap a figure or an equation, to put a note right there.
Notes on earlier wording
The lesson has changed and these words are no longer in it. Your notes are kept, with the words you chose.