How air-sense/airsense_esp32-idf_rtos works
Project Type and Purpose
• This is an embedded IoT firmware project built on Espressif’s ESP‑IDF framework for the ESP32.
• It gathers environmental and time data (from BME280/BMP280, PMS7003, DS3231), timestamps it, stores it on an SD card, and publishes it (e.g., via MQTT).
File‐Structure Analysis
• Top‐Level:
• CMakeLists.txt, Makefile, sdkconfig – build and config for ESP‑IDF
• component/ – all reusable modules (drivers, managers, helpers)
• main/ – application entry point (main.c)
• component/:
• Sensor drivers: BME280, BMP280, PMS7003 (each has .c/.h, CMakeLists.txt, component.mk, Kconfig)
• DS3231 + Time: Real Time Clock driver + wrapper for timestamp handling
• FileManager: SD‑card abstraction
• DataManager: aggregation and orchestration of sensor data
• DeviceManager: high‑level device control (init/sequencing)
• SNTP_Sync: external time synchronization over Wi‑Fi
• i2cdev, esp_idf_lib_helpers: low‑level I²C helper libraries
• main/:
• main.c: creates FreeRTOS tasks or timers, initializes components via DeviceManager
Extracted Architectural Insights from README
• Uses ESP‑IDF v5.1.2 with FreeRTOS
• Key features: sensor read, SD storage, MQTT publish
• Modular “component” layout follows ESP‑IDF component paradigm
• Kconfig.projbuild files allow per‑component configuration via menuconfig
a. Main Components
• Hardware layer: ESP32 SoC, I²C bus, UART (for PMS7003), SD‑card interface, Wi‑Fi radio
• ESP‑IDF framework (FreeRTOS scheduler, Wi‑Fi, peripheral drivers)
• Helper libraries: i2cdev, esp_idf_lib_helpers
• Sensor drivers: BME280, BMP280, PMS7003, DS3231
• Time services: DS3231Time + SNTP_Sync
• Managers: DeviceManager, DataManager, FileManager
• Application layer: main.c (task orchestration)
• External services: MQTT broker (cloud), NTP server (internet)
b. Relationships & Data Flows
1. At boot: main.c → DeviceManager initializes sensors + network → RTOS tasks start
2. Sensor tasks: use i2cdev/driver → read BME280/BMP280/PMS7003 periodically
3. Time sync: DS3231Time task reads RTC; SNTP_Sync updates RTC via Wi‑Fi
4. DataManager aggregates sensor+timestamp → passes payload to:
– FileManager (writes to SD‑card)
– MQTT publish function (via ESP‑IDF MQTT client API)
c. Architectural Patterns & Principles
– Layered: Hardware → Driver libraries → Component drivers → Manager services → Application
– Component‑based (ESP‑IDF recommended layout)
– Separation of concerns: I/O, storage, networking, orchestration each in its own component
– FreeRTOS tasks encapsulate periodic or event‑driven behavior
d. Key Technologies
– ESP‑IDF (FreeRTOS, Wi‑Fi, peripheral APIs)
– I²C via i2cdev
– SD‑card via FATFS (FileManager)
– MQTT client (inside DeviceManager or DataManager)
– SNTP (built‑in LWIP SNTP in ESP‑IDF)
– Kconfig for runtime configuration
Essential Details not to Miss
• The dual time‐source (DS3231 RTC vs. SNTP) and how they synchronize
• The use of Kconfig for dynamic pin/parameter reconfiguration
• FreeRTOS tasks as fundamental runtime units
• The component.mk/CMakeLists.txt build separation
• The flow from on‑device storage to cloud publishing