A comprehensive ESP32-based itercom system with WiFi connectivity, MQTT communication, GPIO monitoring, and RGB status indication.
- WiFi Connectivity: Automatic connection to WiFi networks with reconnection handling
- MQTT Communication: MQTT5 client with automatic reconnection and message handling
- GPIO Monitoring: ADC monitoring with threshold-based alerts
- RGB Status Indicator: Visual status indication through RGB LED
- Remote Control: GPIO control via MQTT messages
- Over-The-Air Updates (OTA): Remote firmware updates via HTTP
- Modular Architecture: Clean separation of concerns with task-based design
- ESP32 development board
- RGB LED (Common Cathode)
- ADC input sensor/potentiometer (Connect to your Intercom Tube LED)
- GPIO output device (Connect to button to open door)
- Red: GPIO 13
- Green: GPIO 12
- Blue: GPIO 14
- Output Pin: GPIO 2
- Input Channel: ADC1_Channel_6 (GPIO 34)
main/
├── app_main.c # Main application entry point
├── credentials.example.h # WiFi and MQTT credentials template
├── intercom_constants.h # Hardware pin definitions and constants
├── color.h # Color utility definitions
└── tasks/
├── rgb_state_task.h/.c # RGB LED control and status indication
├── wifi_task.h/.c # WiFi connection management
├── mqtt_task.h/.c # MQTT client implementation
├── gpio_monitor_task.h/.c # ADC monitoring and GPIO control
└── ota_task.h/.c # Over-The-Air update functionality
git clone https://github.com/verncat/ESP32-Intercom.git
cd ESP32-IntercomCopy the example credentials file and edit with your settings:
cp main/credentials.example.h main/credentials.hEdit main/credentials.h:
#define WIFI_SSID "YourWiFiSSID"
#define WIFI_PASS "YourWiFiPassword"
#define MQTT_BROKER_URL "mqtt://your-mqtt-broker.local"
#define MQTT_USERNAME "your-mqtt-username"
#define MQTT_PASSWORD "your-mqtt-password"
// OTA Configuration
#define OTA_FIRMWARE_UPG_URL "http://your-server.local:8080/firmware.bin"
#define OTA_FIRMWARE_RECV_TIMEOUT 10000idf.py build
idf.py flash monitor/topic/intercom/open_state: Controls GPIO 2- Send
"true"or"1"to set GPIO HIGH - Send
"false"or"0"to set GPIO LOW
- Send
/topic/intercom/dial_value: ADC readings when threshold is exceeded- Publishes raw ADC value as string
The RGB LED provides visual feedback for different system states:
- Light Blue (Blinking): WiFi connecting
- Light Green (Solid): WiFi connected
- Orange (Blinking): WiFi disconnected
- Purple (Blinking): MQTT connecting
- Green (Solid): MQTT connected
- Yellow (Blinking): MQTT disconnected
- Magenta (Blinking): MQTT sending message
- Cyan (Blinking): MQTT receiving message
- Black/Off: System idle
- Red (Blinking): Error state
- White (Blinking): OTA update in progress
- Green (Blinking): OTA update successful
- Red (Fast Blinking): OTA update failed
The system tracks the following states:
enum IntercomState {
ENUM_INTERCOM_STATE_IDLE,
ENUM_INTERCOM_STATE_WIFI_CONNECTING,
ENUM_INTERCOM_STATE_WIFI_CONNECTED,
ENUM_INTERCOM_STATE_WIFI_DISCONNECTED,
ENUM_INTERCOM_STATE_MQTT_CONNECTING,
ENUM_INTERCOM_STATE_MQTT_CONNECTED,
ENUM_INTERCOM_STATE_MQTT_DISCONNECTED,
ENUM_INTERCOM_STATE_MQTT_SENDING,
ENUM_INTERCOM_STATE_MQTT_RECEIVING,
ENUM_INTERCOM_STATE_OTA_UPDATING,
ENUM_INTERCOM_STATE_OTA_SUCCESS,
ENUM_INTERCOM_STATE_OTA_FAILURE,
};- Threshold: 2000 (12-bit ADC value)
- Sampling Rate: 1 second
- Resolution: 12-bit (0-4095)
- Protocol: MQTT v5.0
- QoS: 1 (At least once delivery)
- Reconnection: Automatic with 3-second delay
Enable verbose logging for troubleshooting:
esp_log_level_set("mqtt_client", ESP_LOG_VERBOSE);
esp_log_level_set("wifi", ESP_LOG_VERBOSE);Monitor output:
idf.py monitorThe project uses a modular, task-based architecture:
- Main Task: Initializes all components and starts other tasks
- RGB Task: Continuously updates LED status based on system state
- WiFi Task: Handles WiFi connection and reconnection
- MQTT Task: Manages MQTT connection and message handling
- GPIO Monitor Task: Monitors ADC input and publishes values
- OTA Task: Handles over-the-air firmware updates
The system supports remote firmware updates via HTTP without requiring physical access to the device.
Set up an HTTP server to host firmware files:
# Example using Python HTTP server
cd /path/to/firmware/directory
python3 -m http.server 8080-
Build your firmware:
idf.py build
-
Copy the firmware binary:
cp build/smart-intercom.bin /path/to/firmware/directory/firmware.bin
Update your credentials.h with the firmware URL:
#define OTA_FIRMWARE_UPG_URL "http://192.168.1.100:8080/firmware.bin"