How ducvinh2910/lab_iot works
Project Type and Purpose
• This is an IoT firmware project specifically built for embedded microcontroller development using PlatformIO.
• The project is designed to run on devices such as the M5Stack Atom or YOLO Uno (as suggested by the board files) and provides functionalities such as a web server and MQTT connectivity.
• It leverages libraries like ESPAsyncWebServer, SPIFFS for filesystem operations, and Adafruit_MQTT_Library to communicate with external MQTT brokers.
File Structure for Architectural Clues
• Top-Level Files and Directories:
• The presence of directories like src, include, lib, and boards indicates separation between source code, header files, libraries, and board configuration files.
• The src folder is organized into a modular structure with further subdirectories:
▪ src/app contains application-level code, e.g., reset.cpp and web_Server_Task.cpp.
▪ src/tasks contains individual tasks, such as background_Task.cpp/h.
▪ src/utils holds utility code, e.g., version.h.
• The data directory includes web content files (HTML and CSS) which are likely to be served by the embedded web server using SPIFFS.
• Configuration files like platformio.ini, project_config.h, and boards JSON definitions help manage the build environment and target hardware.
Insights from the README File
• The README clearly states this is an IoT Starter Kit and outlines the flashing and filesystem upload process.
• Included libraries confirm that the key functionalities include asynchronous web services and MQTT connectivity.
• The README instructions indicate how to enter bootloader mode, flash firmware, and build/upload SPIFFS images, all pointing towards an embedded, full-stack (firmware + web interface) system design.
a. Main Components:
• Hardware Platform:
▪ Microcontroller Board (e.g., M5Stack Atom, YOLO Uno) – as defined in the boards folder.
• Firmware Core:
▪ Bootloader (mode handling, not explicitly present in code but implied by instructions).
▪ Main Application (src/main.cpp) – the entry point that initializes the firmware.
• Application Modules:
▪ App Module (src/app): Responsible for hardware reset management and handling web server tasks (web_Server_Task.cpp).
▪ Tasks Module (src/tasks): Runs background processes (background_Task.cpp/h).
▪ Utility Module (src/utils): Holds utility functions such as retrieving version information (version.h).
• External Interfaces:
▪ Web Server Component (leveraging ESPAsyncWebServer) – to serve static content stored in SPIFFS (data folder with index.html and style.css).
▪ MQTT Communication (using Adafruit_MQTT_Library) – for IoT connectivity with external brokers.
• Filesystem Storage:
▪ SPIFFS for storing the web interface, updated through PlatformIO’s Tools.
b. Relationships and Interactions:
• The Firmware (main.cpp) initializes the hardware and sets up the different application modules.
• The Web Server Task (under src/app) interacts with the SPIFFS storage to serve content from the data directory.
• The Background Task (under src/tasks) runs alongside to manage periodic or asynchronous tasks.
• External connectivity is handled via MQTT and web client connections, where data flows from the device to external servers or services.
c. Important Architectural Patterns/Design Principles:
• Modular design: Code is clearly separated into distinct modules (app, tasks, utils) for clarity and maintainability.
• Asynchronous processing: Use of ESPAsyncWebServer implies that the design relies on event-driven asynchronous handling of requests.
• Separation of concerns: The codebase is organized to separate data (SPIFFS), network interfaces (MQTT/WebServer), and core application logic.
d. Relevant Technologies and Frameworks:
• PlatformIO for project management and build/deployment.
• ESPAsyncWebServer for the web server handling.
• SPIFFS for internal filesystem management.
• Adafruit_MQTT_Library for MQTT communication.
• The board definitions and configuration files tie the code to specific hardware.
Elements
• Hardware (with boards like M5Stack-Atom and YOLO Uno illustrated).
• Web Server block and File System (SPIFFS) block.
• MQTT Communication block connecting to external systems.
• Initialization flow from main firmware to individual modules.
• Data flow from the web server to SPIFFS and back.
• Communication routes from the firmware to external MQTT brokers.