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 |
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
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. |
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. |


