Skip to content
You Start with one site
Amounts in Start with one site
IoT & AIoT · Course

Your first telemetry

Lesson 3 of 4 Beginner 12 min read
Found this useful?

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.

#IoT #MQTT #TLS

Your broker or ours. The steps below work with any MQTT broker. On one you run, such as Mosquitto, you create the username and password yourself, the host is your server's address, and you choose the topic. The worked example here is siliconwit.io, our monitoring service, because it needs no server of your own. It works with any MQTT client, so moving a device away means changing the host, port, username and password. You can finish this lesson without an account: the questions ask about MQTT, not about the service.

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:

broker hostmqtt.siliconwit.io
port8883 (TLS, encrypted, required)
usernameSWD-XXXXXX (your Device ID)
passwordyour Access Token
publish tod/SWD-XXXXXX/t (your telemetry topic)
payload{"temperature": 23.4, "humidity": 51.0} (JSON)

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.

Why 8883 and TLS? Port 8883 is MQTT over an encrypted connection. Your Access Token travels on every connect, so sending it in the clear would hand your device to anyone listening on the network. The platform requires TLS for exactly this reason.

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.

Make it public when you are ready. On siliconwit.io a device can be flipped to public, which puts it on the public-devices wall where anyone, a teammate, a client, an employer, can watch it run live. That is proof that outlasts a screenshot.

Check yourself

Question 1

In the MQTT connection, what is the Access Token used as?

Question 2

Why does the platform require port 8883 with TLS?

Question 3

Your device connects fine but nothing appears on the dashboard. What is the first thing to check?

Question 4

Which topic does a device publish its telemetry to?

Key points
  • 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.

Found this useful?

Discussion

    Comments show your name. Be kind, stay on the topic.