You Want Electronic Components for your project. 

For more information, contact us at: 

Establish Connectivity Between IoT Devices and Cloud Platforms


Connecting an IoT device to the cloud transforms a standalone sensor node into a networked IoT asset. This lesson covers the architecture of IoT cloud platforms, how connectivity is established, and the practical steps to connect an ESP32 to ThingsBoard and ThingSpeak.

IoT Cloud Platform Architecture

Layer Function Examples
Device layer IoT devices (ESP32, Arduino, sensors). Collect data and connect to cloud via MQTT, HTTP, or CoAP. Units 1–5: sensors, firmware, protocols
Edge / gateway layer Local hubs that aggregate device data before forwarding to cloud. Reduces bandwidth and latency. Raspberry Pi, LoRaWAN gateway, AWS Greengrass
Cloud broker layer Receives device messages (MQTT broker). Routes data to storage and processing services. AWS IoT Core, Azure IoT Hub, EMQX Cloud
Data storage layer Time-series databases store sensor readings with timestamps. Optimised for IoT query patterns. InfluxDB, TimescaleDB, ThingsBoard Cassandra
Processing layer Rules engines, stream processors, and analytics run on incoming data to trigger alerts and actions. AWS Lambda, Node-RED, ThingsBoard Rule Engine
Application layer Dashboards, APIs, and mobile apps expose data to end users and downstream systems. ThingsBoard, Grafana, custom web apps
KEY
In this course you primarily work at the Device layer (ESP32 firmware) and Application layer (dashboards and APIs). The cloud platform (ThingsBoard or ThingSpeak) handles the layers in between as a managed service.

Cloud Platform Comparison

Platform Description Best For / Free Tier
ThingsBoard Open-source IoT platform. Rich dashboards, rule engine, device management. MQTT and HTTP ingestion. Self-host or cloud. Full-featured IoT projects, real-time dashboards, remote control. Free Community Edition.
ThingSpeak MathWorks IoT analytics service. Simple HTTP API, built-in MATLAB analytics, time-series charts. Quick sensor data logging, data analysis. Free tier: 3M msg/year, 8 fields/channel.
AWS IoT Core Amazon enterprise IoT service. X.509 certificate auth, MQTT broker, Lambda triggers, S3 storage. Production-scale deployments, enterprise integration. Free tier: 500,000 messages/month.
Azure IoT Hub Microsoft IoT hub service. Device-to-cloud and cloud-to-device messaging, device twins. Microsoft ecosystem integration, large-scale deployments.
Adafruit IO Simple IoT dashboard service. MQTT and HTTP, feeds and dashboards. Beginner-friendly. Simple dashboards, educational projects. Free: 30 data points/min.
Node-RED Visual flow programming for IoT. Runs on local server or cloud. Connects any protocol to any dashboard. Rapid prototyping, integration between platforms, custom logic flows.

ThingsBoard — Platform Setup and Device Provisioning

Creating a ThingsBoard Account and Device

ThingsBoard Community Edition is available at thingsboard.io. For this course we use thingsboard.cloud (free community tier).

Step Action Result / Note
Step 1 Create account at thingsboard.cloud. Confirm email. Sign in to the ThingsBoard dashboard.
Step 2 Go to Devices → Add Device. Enter a name (e.g. ‘ESP32-Weather-01’). Select device type. A device is created with a unique Device ID.
Step 3 Click the device → Credentials tab. Note the Access Token (a 20-character string). This is your MQTT password. Keep this token private — it authenticates your device.
Step 4 Note the MQTT broker address: mqtt.thingsboard.cloud. Port: 1883 (unencrypted) or 8883 (TLS). Use 8883 + TLS in production.
Step 5 MQTT username = your Access Token. Password = empty. Topic for publishing telemetry = v1/devices/me/telemetry. ThingsBoard uses the access token as username for device authentication.

ESP32 to ThingsBoard — MQTT Telemetry Publisher

C/C++ — ESP32 Publishing DHT22 + LDR Data to ThingsBoard via MQTT
#include <WiFi.h>
#include <PubSubClient.h>
#include <DHT.h>
#include <ArduinoJson.h>

const char* WIFI_SSID = "YourNetwork";
const char* WIFI_PASS = "YourPassword";
const char* TB_HOST   = "mqtt.thingsboard.cloud";
const int   TB_PORT   = 1883;
const char* TB_TOKEN  = "YOUR_ACCESS_TOKEN";  // ThingsBoard device token
const char* TB_TELEM  = "v1/devices/me/telemetry";
const char* TB_ATTR   = "v1/devices/me/attributes";

#define DHT_PIN 4
#define LDR_PIN 34  // ADC1 pin — safe to use with Wi-Fi

DHT dht(DHT_PIN, DHT22);
WiFiClient   wifiClient;
PubSubClient mqtt(wifiClient);
unsigned long lastSend = 0;
const long INTERVAL = 15000;

void connectMQTT() {
  while (!mqtt.connected()) {
    Serial.print("Connecting to ThingsBoard...");
    // ThingsBoard: username = token, password = empty string
    if (mqtt.connect("esp32-weather-01", TB_TOKEN, "")) {
      Serial.println(" Connected!");
      // Publish device attributes (static info) once on connect
      StaticJsonDocument<128> attr;
      attr["firmware"] = "v1.0.2";
      attr["location"] = "Kigali-Lab01";
      attr["sensor"]   = "DHT22+LDR";
      char attrBuf[128];
      serializeJson(attr, attrBuf);
      mqtt.publish(TB_ATTR, attrBuf);
    } else {
      Serial.print(" Failed rc="); Serial.print(mqtt.state());
      Serial.println(" retry in 5s");
      delay(5000);
    }
  }
}

void setup() {
  Serial.begin(115200);
  dht.begin();
  analogSetAttenuation(ADC_11DB);  // Full 0–3.3 V ADC range on ESP32
  WiFi.begin(WIFI_SSID, WIFI_PASS);
  while (WiFi.status() != WL_CONNECTED) delay(500);
  Serial.println("Wi-Fi: " + WiFi.localIP().toString());
  mqtt.setServer(TB_HOST, TB_PORT);
  connectMQTT();
}

void loop() {
  if (!mqtt.connected()) connectMQTT();
  mqtt.loop();
  if (millis() - lastSend >= INTERVAL) {
    lastSend = millis();
    float temp = dht.readTemperature();
    float hum  = dht.readHumidity();
    int   ldr  = analogRead(LDR_PIN);
    if (!isnan(temp) && !isnan(hum)) {
      StaticJsonDocument<128> doc;
      doc["temperature"] = round(temp * 10) / 10.0;
      doc["humidity"]    = round(hum  * 10) / 10.0;
      doc["light"]       = ldr;
      doc["rssi"]        = WiFi.RSSI();  // Wi-Fi signal strength
      char payload[128];
      serializeJson(doc, payload);
      mqtt.publish(TB_TELEM, payload);
      Serial.println(payload);
    }
  }
}

TRY
After uploading, go to ThingsBoard → your Device → Latest Telemetry tab. You should see ‘temperature’, ‘humidity’, ‘light’, and ‘rssi’ values updating every 15 seconds. If nothing appears, check: correct access token, correct broker hostname, and Serial Monitor for error messages.

ThingSpeak — Quick HTTP Data Logging

ThingSpeak is a simpler alternative for projects that primarily need data logging and basic charting. It accepts sensor data via HTTP POST and displays it in auto-generated time-series charts.

Step Action Note
Step 1 Create account at thingspeak.com. Go to Channels → New Channel. Name your channel and enable fields (Field 1 = Temperature, Field 2 = Humidity, etc.). Each field maps to one sensor value.
Step 2 Note your Write API Key from Channel → API Keys tab. This key authenticates HTTP POST requests to your channel.
Step 3 Endpoint: POST to https://api.thingspeak.com/update Include api_key, field1, field2… as form-encoded parameters.
Step 4 Minimum publish interval: 15 seconds (free tier). HTTP 429 = publishing too fast. Use millis() timer with INTERVAL ≥ 15000 ms.
COMPARE
ThingSpeak: quick setup, built-in charts, HTTP-only, limited free tier. ThingsBoard: richer dashboards, MQTT + HTTP, device management, more complex setup but far more powerful. For a real IoT project, ThingsBoard is the professional choice. Use ThingSpeak for quick experimentation.

Verifying Cloud Connectivity

Verification Step What to check What it tells you
1. Serial Monitor Confirm the device prints a successful JSON payload before the mqtt.publish() or http.POST() call. If not printing: sensor error. Fix sensor code first.
2. MQTT client tool Use MQTT Explorer or mosquitto_sub to subscribe to the device’s topic and confirm messages arrive at the broker. If broker sees messages but platform doesn’t: platform MQTT config issue.
3. Platform Latest Telemetry Check the cloud platform’s raw data view. ThingsBoard: Device → Latest Telemetry. ThingSpeak: Data Import/Export. If data appears here but not on dashboard: dashboard widget config issue.
4. Platform logs Most platforms have a Device Connectivity Log or Activity Log that shows connection events and errors. Look for authentication failures (wrong token) or disconnects.

Check Your Understanding — Lesson 6.1

?
1. An ESP32 connects to ThingsBoard and publishes to ‘v1/devices/me/telemetry’ but the Latest Telemetry tab shows no data. Serial Monitor shows the JSON payload printing correctly. List three things you should check in order.
?
2. What is the difference between a ThingsBoard ‘telemetry’ topic and an ‘attributes’ topic? When would you publish to each?
?
3. A student using ThingSpeak receives HTTP 429 every second publish attempt. They have INTERVAL = 10000 ms. What is wrong and how should it be fixed?

I'm an Embedded & AIoT Systems Engineer and the Founder & CEO of Nyereka Tech, a Rwanda-based startup enabling access to STEM tools, training, and innovation. I'm passionate about empowering young innovators through practical technology education and local manufacturing solutions.