IoT
The Internet of Things connects embedded devices to the cloud. Learn IoT architecture, wireless technologies (Wi-Fi, BLE, Zigbee, LoRaWAN, NB-IoT), MQTT, power budgets, security, OTA updates and edge computing.
An IoT device measures or controls something physical and shares data over a network: a smart meter reporting consumption, a soil sensor on a farm, a factory machine streaming vibration data, a thermostat controlled from a phone.
Designing one means balancing four constraints at once: connectivity (range, bandwidth), power (often years on a battery), cost and — critically — security, because every connected device is a potential entry point.
An analogy
An IoT system is like a postal network: sensors write postcards (data), gateways are local post offices, the cloud is the sorting centre, and security is the sealed, signed envelope that stops forgeries.
Architecture
Device (sensor/actuator + MCU + radio) → gateway or access point → network → cloud platform (ingest, storage, analytics, dashboards, rules) → users and applications. Edge computing processes data locally to reduce bandwidth and latency.
Choosing connectivity
Each radio technology targets a different range, data rate and power budget.
- Wi-Fi: high bandwidth, mains or large batteries, local range.
- BLE: phone connectivity, low power, ~10–50 m.
- Zigbee/Thread: low-power mesh for home and buildings.
- LoRaWAN: km range, tiny payloads, years on battery, duty-cycle limits.
- NB-IoT/LTE-M: cellular coverage, operator-managed, moderate power.
MQTT and data design
MQTT's lightweight publish/subscribe model suits constrained devices: devices publish to topics, applications subscribe. Choose QoS (0 at most once, 1 at least once, 2 exactly once), retain flags and last-will messages. Send compact payloads (CBOR, binary) and only when data changes meaningfully.
Security by design
Unique per-device credentials (no shared passwords), TLS/DTLS encryption, secure boot so only signed firmware runs, signed OTA updates with rollback, hardware secure elements for keys, minimal open ports, and a plan for patching over the device's lifetime. Regulations (EU Cyber Resilience Act, ETSI EN 303 645) now require much of this.
Fleet operations
Real deployments involve provisioning thousands of devices, monitoring health (battery, RSSI, reboots), staged OTA rollouts, and digital twins/device shadows that store the desired and reported state of each device in the cloud.
Formulas
- Average current:
I_avg = I_sleep + (Q_event / T_interval) - Charge per event:
Q_event = Σ I_k · t_k (radio, sensor, CPU) - Minimum interval (duty cycle):
T_min = ToA / DC - Daily data volume:
bytes/day = payload × 86 400 / T_interval
Worked example: LoRaWAN duty-cycle limit
Given: Packet time on air = 50 ms; Duty-cycle limit = 1 %
Find: Shortest allowed interval between packets.
- T_min = 0.05 s/0.01 = 5 s
Answer: One packet every 5 s at most
Worked example: MQTT data volume
Given: 100-byte message every 60 s
Find: Daily data.
- Messages/day = 1440
- Data = 1440 × 100 = 144 kB/day (plus protocol overhead)
Answer: ≈ 144 kB/day
Publishing a sensor reading over MQTT (ESP-IDF style)
#include "mqtt_client.h"
static void publish_reading(esp_mqtt_client_handle_t client, float temp_c) {
char payload[64];
int n = snprintf(payload, sizeof payload,
"{\"temp\":%.2f,\"ts\":%lld}", temp_c, (long long)time(NULL));
// topic hierarchy: site/device/metric ; QoS 1 = at-least-once delivery
esp_mqtt_client_publish(client, "farm1/node17/temperature", payload, n, 1, 0);
}
void app_main(void) {
esp_mqtt_client_config_t cfg = {
.broker.address.uri = "mqtts://broker.example.com:8883", // TLS
.credentials.client_id = "node17",
};
esp_mqtt_client_handle_t client = esp_mqtt_client_init(&cfg);
esp_mqtt_client_start(client);
publish_reading(client, read_temperature());
esp_deep_sleep(15ULL * 60 * 1000000); // sleep 15 minutes, then reboot & repeat
}MQTT decouples devices from applications via topics on a broker; mqtts:// adds TLS. Deep sleep between reports is what makes battery operation possible.
Common mistakes
- Wrong: Shipping every device with the same default password. — Right: Use unique per-device credentials provisioned at manufacture (ideally in a secure element).
- Wrong: Estimating battery life from sleep current only. — Right: Include every wake event — radio TX/RX, sensor warm-up, CPU — and the battery's self-discharge and temperature derating.
Applications
- Smart agriculture: Soil-moisture and weather nodes on LoRaWAN guide irrigation across large farms.
- Industrial IoT: Vibration and temperature sensors enable predictive maintenance of motors and pumps.
- Smart buildings & energy: Connected meters, thermostats and EV chargers enable demand response and energy optimisation.
Key takeaways
- Device → gateway → broker → cloud, with edge processing where useful.
- Choose connectivity by range, bandwidth, power and cost.
- Battery life = capacity/(sleep + charge per event ÷ interval).
- Security (unique keys, TLS, secure boot, signed OTA) is mandatory.
Going further
- Energy harvesting: Solar cells, thermoelectric and vibration harvesters with supercapacitors can power sensors indefinitely when average consumption is in the tens of µW.
- TinyML at the edge: Quantised neural networks on MCUs classify vibration, audio or images locally, sending only events instead of raw data — saving bandwidth and power.
- Matter and interoperability: The Matter standard (over Thread/Wi-Fi) unifies smart-home device control across ecosystems with built-in security and local control.