This project is a production-ready firmware for ESP32-S3 microcontrollers that securely connects to the ThingsBoard IoT platform. It includes a robust web-based provisioning system with ThingsBoard access token authentication, enterprise-grade security features, and comprehensive real-time telemetry capabilities with professional dashboard visualization.
- Web-Based Wi-Fi Provisioning:
- On first boot, the device starts in Access Point mode.
- Connect to the
ESP32-ProvisioningWi-Fi network (password:password). - Navigate to
http://192.168.4.1. The page comes pre-filled with default credentials for quick setup.
- Dynamic Wi-Fi Scanning:
- The provisioning page includes a "Scan for Networks" button with an improved UI that gracefully handles long network names.
- ThingsBoard Integration:
- Access Token Authentication: Web-based provisioning with ThingsBoard device access tokens
- Smart Protocol Detection: Automatic MQTT (port 1883) vs MQTTS (port 8883) selection
- Pre-configured Setup: Default ThingsBoard server (193.164.4.51) and demo access token
- Seamless Telemetry: Compatible with ThingsBoard's
v1/devices/me/telemetryformat - Enterprise Security: Full MQTTS/TLS implementation with certificate management
- Enhanced LED Status Indicator:
- The onboard ARGB LED (GPIO 48) provides detailed visual indication of device status:
- White: Provisioning mode active
- Blue: Connecting to Wi-Fi network
- Green: Fully connected to Wi-Fi and MQTT/ThingsBoard
- Red: Connection error (Wi-Fi or MQTT connection failure)
- Brightness: Configurable (0-255, default 25)
- The onboard ARGB LED (GPIO 48) provides detailed visual indication of device status:
- Real-Time Telemetry:
- Temperature Monitoring: Built-in ESP32-S3 sensor (Range: -10Β°C ~ 80Β°C, Β±1Β°C accuracy)
- System Metrics: RSSI, heap memory, uptime tracking
- Transmission: JSON payload every 5 seconds over MQTT to ThingsBoard
- Current Memory: ~323KB free heap at startup
- Certificate Management System:
- Secure certificate storage in NVS with integrity checking
- Automatic certificate initialization on first boot
- Development certificate fallback for testing
- Certificate rotation support without firmware updates
- Professional Dashboard System:
- Comprehensive dashboard creation guide
- Custom widget bundle with professionally designed visualization components
- Responsive design that works on both desktop and mobile devices
- Support for importing pre-built widgets or manual creation
- Flash Firmware:
idf.py -p /dev/ttyUSB0 flash monitor - First Boot: Device automatically starts in provisioning mode (no credentials stored)
- Connect to Wi-Fi: Join
ESP32-Provisioningnetwork (password:password) - Configure Device: Navigate to
http://192.168.4.1- all ThingsBoard settings are pre-filled! - Smart Boot: After restart, device connects directly to stored Wi-Fi and ThingsBoard
- LED Status: Green = fully connected to ThingsBoard, transmitting telemetry every 5 seconds
- First Boot: Automatic provisioning mode (no Wi-Fi credentials stored)
- After Configuration: Smart boot directly to Wi-Fi connection (credentials stored)
- ThingsBoard Ready: Pre-configured with server IP and demo access token for instant testing
- Reset to Provisioning: Use
idf.py erase-flashto clear credentials and return to provisioning mode
π― New User? Start Here: Complete Setup Guide β Thingsboard_Complete_Setup.md
- Device creation & access token setup
- ESP32 provisioning with ThingsBoard connection
- Professional dashboard creation with custom widgets
- Advanced monitoring with alerts & Mattermost integration
π Dashboard Only: Quick Dashboard Guide β Thingsboard_Dashboard.md
- For existing ThingsBoard devices
- Widget import and configuration
- Professional styling and layouts
- Real-time telemetry: Temperature, RSSI, heap memory, uptime (5-second updates)
- Professional widgets: Glass-morphism design with animations
- Mobile responsive: Works on desktop, tablet, and mobile
- Smart alerts: RSSI thresholds with Mattermost notifications
- Easy import: Pre-built widget JSON files included
- ESP-IDF v5.4.1
- An ESP32-S3 development board
-
Set the Target Chip:
idf.py set-target esp32s3
-
Build and Flash the Firmware: Connect the ESP32-S3 board and run the following command, replacing
/dev/ttyUSB0with your device's serial port if necessary.idf.py -p /dev/ttyUSB0 flash
-
Monitor the Output: To view the log output from the device, run:
idf.py -p /dev/ttyUSB0 monitor
Expected Log Messages (Success):
First Boot (Initial Setup):
I (451) PROVISIONING_EXAMPLE: CA certificate not found in NVS, initializing...
I (451) PROVISIONING_EXAMPLE: CA certificate stored in NVS successfully
I (451) PROVISIONING_EXAMPLE: ThingsBoard/Mosquitto CA certificate initialized successfully
I (451) PROVISIONING_EXAMPLE: No Wi-Fi credentials found, starting provisioning mode
I (621) PROVISIONING_EXAMPLE: WiFi AP started. SSID:ESP32-Provisioning password:password
Subsequent Boots (Smart Boot):
I (451) PROVISIONING_EXAMPLE: CA certificate already exists in NVS, skipping initialization
I (451) PROVISIONING_EXAMPLE: Wi-Fi credentials found, connecting directly
I (451) PROVISIONING_EXAMPLE: Connecting to stored Wi-Fi network: YourSSID
I (24391) PROVISIONING_EXAMPLE: CA certificate loaded from security NVS namespace
I (24881) PROVISIONING_EXAMPLE: MQTT_EVENT_CONNECTED
Common SSL/TLS Errors:
-
"CA certificate not found in NVS"
- Cause: Certificate not properly stored or NVS corruption
- Solution: Flash updated firmware with automatic certificate initialization
-
"SSL/TLS error occurred - error code: 0x8010"
- Cause: Certificate validation failure or expired certificate
- Solution: Verify MQTT broker certificate matches stored CA certificate
-
"MQTT connection failed"
- Cause: Incorrect MQTTS port or SSL configuration
- Solution: Ensure MQTT broker uses port 8883 and matches certificate
- Low heap warning: Device has ~323KB free at startup
- Certificate storage: Requires ~2KB NVS space per certificate (one-time write)
- Boot optimization: Certificate initialization skipped on subsequent boots for faster startup
- Monitor: Use
esp_get_free_heap_size()for memory tracking
- First Boot: Automatically initializes and stores CA certificate in NVS
- Subsequent Boots: Detects existing certificate and skips initialization (faster boot time)
- Memory Efficient: Certificate written only once, reducing NVS wear
- Manual Reset: To force certificate re-initialization, erase NVS:
idf.py erase-flash
- Wi-Fi connection: LED shows blue during connection, green when successful
- MQTTS connection: LED turns red on SSL/TLS failures
- Telemetry: Check for
MQTT_EVENT_PUBLISHEDmessages every 5 seconds
This project is production-ready with enterprise-grade security features:
- β SSL/TLS Security: Full MQTTS encryption with certificate validation
- β Automatic Certificate Management: One-time certificate initialization with NVS optimization
- β Real-Time Telemetry: Temperature monitoring and system metrics transmission
- β Robust Provisioning: Web-based Wi-Fi and MQTT configuration
- β LED Status Indicators: Visual feedback for all connection states
- β Memory Optimized: ~323KB free heap with efficient certificate storage
- β Professional Dashboard System: Comprehensive visualization with custom widgets
- β³ RPC Control Features: Partially implemented (see Day 3 tasks)
- Day 1: Core firmware with Wi-Fi provisioning and basic telemetry
- Day 2: UI/UX enhancements, security features, and ThingsBoard integration
- Dashboard System: Professional visualization components and documentation
- Day 3: RPC control functionality for remote device control
- REST API Integration: Examples for retrieving telemetry via REST APIs
- Enhanced Widget Library: Additional specialized widgets for specific use cases
A:
- MQTT (port 1883) = Unencrypted, insecure communication
- MQTTS (port 8883) = Encrypted with SSL/TLS certificates (what this project uses)
A: The ESP32 firmware includes the CA certificate automatically. You only need to generate server certificates for your MQTT broker.
A: The firmware implements smart boot logic:
- First boot: No credentials β starts provisioning mode
- After setup: Credentials stored β connects directly to Wi-Fi
- Certificate optimization: CA certificate stored once, reused on subsequent boots
A: Run idf.py erase-flash to clear all NVS data (Wi-Fi credentials and certificates). The device will return to provisioning mode on next boot.
A: No! The device only starts provisioning mode if no Wi-Fi credentials are stored. After initial setup, it connects directly to the configured network.