How darho-academy/esp8266-underground-helmet works
Purpose and Runtime
Underground Helmet is ESP8266 firmware that monitors gas, temperature/humidity, and distance; drives LEDs and a buzzer; and exposes live device status on a local Wi-Fi web dashboard and JSON API. It runs on the ESP8266 RTOS SDK/FreeRTOS stack, producing a flashable image (build/underground_helmet.bin) with a SPIFFS web-assets image (build/spiffs.bin).
Entrypoint and Composition
Application startup is rooted at main/main.c, compiled as the main component (main/component.mk). It coordinates independently built application components rather than a monolithic program:
• components/app_system/app_system.c
• components/app_wifi/app_wifi.c
• components/app_sensors/app_sensors.c
• components/app_outputs/app_outputs.c
• components/app_webserver/app_webserver.c
Public headers under each component’s include/ directory form the main inter-component boundary.
Sensing and Device-State Path
components/app_sensors/app_sensors.c is the hardware acquisition boundary for the MQ gas sensor, DHT temperature/humidity sensor, and ultrasonic distance sensor. Readings are consumed as device state by the rest of the firmware rather than directly coupled to HTTP handling.
• components/app_sensors/include/app_sensors.h
• components/app_system/app_system.c
• components/app_logs/app_logs.c
The ESP8266 driver/runtime layer supplies GPIO, ADC, timers, I2C, and FreeRTOS scheduling beneath this boundary.
Safety Actuation and System Coordination
components/app_outputs/app_outputs.c owns physical responses: five status LEDs and the buzzer alarm. app_system is the likely policy/orchestration layer that translates measurements and lifecycle events into status/alarm decisions and output updates.
• components/app_outputs/include/app_outputs.h
• components/app_system/include/app_system.h
• components/app_logs/include/app_logs.h
This separates safety-facing GPIO control from sensor acquisition and network-facing interfaces.
Network, Local API, and UI
components/app_wifi/app_wifi.c establishes connection to an existing router or hotspot, bridging firmware state to the TCP/IP stack. components/app_webserver/app_webserver.c serves the local dashboard and JSON status interface; its embedded minimal JSON support keeps HTTP/API serialization inside the web boundary.
• components/app_wifi/include/app_wifi.h
• components/app_webserver/app_webserver.c
• components/app_webserver/json_min.c
Browser assets are deployed separately through SPIFFS:
• spiffs/index.html
• spiffs/app.js
• spiffs/style.css
The external interaction surface is therefore local Wi-Fi HTTP, with browser clients reading status and potentially invoking protected operations.
Configuration, Authentication, Persistence, and Updates
Configuration interfaces are centralized in components/app_config/include/app_config.h; persistent backing is likely ESP-IDF NVS/SPI flash, as the build includes nvs_flash, SPIFFS, and partition artifacts. Authentication is an explicit boundary around administrative or API actions, with local SHA-256 implementation:
• components/app_auth/app_auth.c
• components/app_auth/sha256_min.c
• components/app_ota/app_ota.c
OTA is a distinct update path, built with ESP OTA and HTTPS OTA support. The flash layout is defined by partitions.csv; bootloader and OTA metadata artifacts (build/bootloader/bootloader.bin, build/ota_data_initial.bin) indicate firmware lifecycle management is part of the deployed system.
Main entry points: app_webserver.c Dashboard & JSON API · main.c Application startup · app_system.c System coordinator · app_sensors.c Sensor acquisition
Components 18
Firmware Components
- Application startup · Composes and starts application components.
main/main.c - System coordinator · Turns lifecycle and measurements into device decisions.
components/app_system/app_system.c - Sensor acquisition · Reads MQ gas, DHT, and ultrasonic sensors.
components/app_sensors/app_sensors.c - Safety outputs · Controls five LEDs and buzzer alarm.
components/app_outputs/app_outputs.c - Application logging
components/app_logs/app_logs.c - Configuration interface · Central configuration boundary.
components/app_config/include/app_config.h - Authentication · Protects administrative or API actions.
components/app_auth/app_auth.c - OTA updater · Installs updates through OTA support.
components/app_ota/app_ota.c
Local Network Surface
- Wi-Fi connection · Connects to an existing router or hotspot.
components/app_wifi/app_wifi.c - Dashboard & JSON API · Serves local status and protected operations.
components/app_webserver/app_webserver.c - JSON serialization
components/app_webserver/json_min.c - Browser clients
Storage & Deployment
- SPIFFS web assets · Dashboard HTML, JavaScript, and CSS.
spiffs/index.html - Flash persistence · Stores configuration and device state.
- Flash layout · Defines firmware, OTA, and SPIFFS storage layout.
partitions.csv - Flashable firmware
build/underground_helmet.bin - SPIFFS image
build/spiffs.bin
Other components
- ESP8266 RTOS & drivers · Provides FreeRTOS, GPIO, ADC, timers, I2C, and TCP/IP.
Connections 24
- Application startup → System coordinator: starts
- Application startup → Sensor acquisition: starts
- Application startup → Safety outputs: starts
- Application startup → Wi-Fi connection: starts
- Application startup → Dashboard & JSON API: starts
- Sensor acquisition → System coordinator: measurements
- System coordinator → Safety outputs: status and alarm decisions
- Sensor acquisition → Application logging: readings
- System coordinator → Application logging: lifecycle events
- ESP8266 RTOS & drivers → Sensor acquisition: drivers and scheduling
- ESP8266 RTOS & drivers → Safety outputs: GPIO
- ESP8266 RTOS & drivers → Wi-Fi connection: TCP/IP stack
- Wi-Fi connection → Dashboard & JSON API: local TCP/IP
- Dashboard & JSON API → System coordinator: reads device state
- Dashboard & JSON API → JSON serialization: serializes status
- Browser clients → Dashboard & JSON API: local Wi-Fi HTTP
- Dashboard & JSON API → SPIFFS web assets: serves
- Dashboard & JSON API → Authentication: protects operations
- Configuration interface → Flash persistence: persists
- OTA updater → Flash persistence: writes update state
- Flash layout → Flashable firmware: places
- Flash layout → SPIFFS image: places
- SPIFFS web assets → SPIFFS image: packaged into
- Flashable firmware → OTA updater: update payload