Skip to content

Source Layout

The FIRMWARE
PlatformIO-based ESP32 application in `firmware/` — connects to Wi-Fi, syncs time, and publishes MQTT telemetry and events.
application lives in the demo repository
esp32-aws-iot-demo — source repository for firmware, provisioning scripts, Terraform, and dashboard code. Commands run from its root unless stated otherwise.
under firmware/, not in this walkthrough site. Browse the source on GitHub: esp32-aws-iot-demo/firmware.

For module behavior details, see Architecture and Modules.

firmware/
├── platformio.ini
├── include/
│ ├── config.example.h # template; generated → config.h
│ └── certs.example.h # template; generated → certs.h
├── src/
│ ├── main.cpp # entry point
│ ├── wifi_manager.*
│ ├── ntp_sync.*
│ ├── mqtt_manager.*
│ ├── telemetry_publisher.*
│ ├── event_publisher.*
│ ├── status_led.*
│ ├── watchdog_supervisor.*
│ ├── payload_codec.h
│ ├── logger.h
│ └── *_utils.h # shared helpers
└── test/ # native unit tests (optional; not part of walkthrough)

firmware/src/main.cpp orchestrates the runtime.

Compile-time guards — the build fails fast if generated headers are missing:

  • config.h — run Device Provisioning (generate-headers.sh with WIFI_SSID, WIFI_PASSWORD, THING_NAME)
  • certs.h — same flow after ./aws/provision.sh and generate-headers.sh

setup() init order:

  1. Logger — serial at 115200 baud
  2. WatchdogSupervisor — task WDT (30 s)
  3. WiFiManager — connect using credentials from config.h
  4. NTPSync — SNTP server from config.h
  5. MQTTManager — TLS endpoint, thing name, and PEM material from certs.h
  6. TelemetryPublisher — publish interval from config.h
  7. EventPublisher — GPIO0 BOOT button
  8. StatusLed — onboard RGB

loop() tick (~10 ms):

  1. watchdog.feed()
  2. wifi_manager.loop() — reconnect with backoff when needed
  3. ntp_sync.loop() — when Wi-Fi is up and time not yet synced
  4. mqtt_manager.loop() — maintain TLS MQTT
    Message Queuing Telemetry Transport — lightweight publish/subscribe protocol used between ESP32 and AWS IoT Core.
    session
  5. telemetry_publisher.loop() — periodic connectivity publish
  6. event_publisher.loop() — debounced button events
  7. watchdog.checkConnectivityTimeout() — reset if Wi-Fi + MQTT stall
  8. status_led.loop() — RGB animation
PathPurposeUsed by
src/main.cppOrchestrates setup and loopEntry
src/wifi_manager.*Wi-Fi connect and exponential backoffmain
src/ntp_sync.*

SNTP sync; ts=0 fallback when unsynced

main, publishers

src/mqtt_manager.*

TLS MQTT to IoT Core
AWS IoT Core — managed MQTT broker with X.509 device authentication for ESP32 telemetry and events.

main, publishers

src/telemetry_publisher.*60 s connectivity payloadmain
src/event_publisher.*GPIO0 BOOT button, debouncedmain
src/status_led.*Blue RGB flash on successful publishtelemetry
src/watchdog_supervisor.*Task WDT and connectivity timeout resetmain
src/payload_codec.h

TelemetryData / EventData JSON serialization

publishers
src/logger.h

[millis][tag] message serial logs

all modules
src/backoff_utils.hShared exponential backoff mathWiFiManager
src/debounce_utils.hButton debounceEventPublisher
src/connectivity_timeout_utils.hDual-connect timeout logicWatchdogSupervisor
src/interval_utils.hPublish interval timingTelemetryPublisher
include/config.hWi-Fi, thing name, endpoint, interval (generated)

main, managers

include/certs.hPEM certificate material (generated)MQTTManager
platformio.ini

Board env esp32-s3-n16r8, library pins

PlatformIO
PlatformIO — build, upload, and serial monitor toolchain (`pio`) for ESP32 firmware.