Most ESP32 + AWS IoT tutorials show you how to publish a temperature reading. This guide shows you how to build something you can actually put into production — with mutual TLS, certificate rotation, dead-letter queues, and proper observability.
The Architecture
Our target architecture: ESP32 devices communicate with AWS IoT Core over MQTT with mutual TLS. IoT Core routes messages through IoT Rules to a Kinesis Data Stream, which feeds a Lambda function that writes to TimescaleDB (PostgreSQL with time-series extensions). A Grafana dashboard sits on top for visualisation.
Device Identity and Certificates
Every device gets a unique X.509 certificate provisioned via AWS IoT Fleet Provisioning. Certificates have a 1-year lifetime and are automatically rotated 30 days before expiry using a Just-In-Time Registration (JITR) flow.
The Firmware Side
We use ESP-IDF (not Arduino) for production firmware. The key libraries are esp-mqtt for the MQTT client and esp-tls for the TLS stack. We store the device certificate and private key in NVS with encryption enabled via the esp-idf NVS encryption feature.
Handling Connectivity Loss
Production devices will lose connectivity. Our firmware implements a local circular buffer that stores up to 72 hours of sensor readings in flash. On reconnection, a backfill task publishes queued messages in batches, respecting MQTT QoS 1 for at-least-once delivery.
0 Comments
Leave a Comment