How mp-se/gravitymon works
Project type and purpose
• This is an embedded-firmware project (“GravityMon”) for ESP32/ESP8266-compatible hardware, providing a drop-in replacement firmware for the iSpindle beer-brewing hydrometer.
• It reads sensor data (gyro/accel, temperature, battery), hosts a web UI, exposes BLE services, and pushes gravity readings to an external server.
File structure
• Top-level
• platformio.ini → PlatformIO build config
• boards/ → custom board definitions (ESP32 variants)
• src/ → main firmware C++ code (drivers, services, web, BLE, push)
• lib/ → third-party drivers (MPU6050 I²C)
• html/ → prebuilt web assets (index.html, app.js.gz, app.css.gz)
• script/ → Python helpers (flash, versioning, build tooling)
• test/ → unit tests & Python scripts
• src_docs/ → Sphinx-based docs
• bin/ → generated firmware binaries and bootloaders
Extract insights from the README
• Core functionality: sensor acquisition, web interface, BLE, data push to brewflasher.com or custom endpoints
• Compatibility: multiple ESP32 family boards, no hardware changes
Main components & interactions
a. Hardware Platform
• ESP32 microcontroller
• Sensors: I²C bus → MPU6050 or ICM42670 gyro/accel, temperature sensor, battery monitor
• Power system (battery, calibration data in .env/default_calibration.xlsx)
b. Firmware Subsystems (running on ESP32)
1. Sensor Drivers (lib/mpu6050 + src/ICM42670P*, src/MPU6050*)
2. Sensor Processing & Filtering (src/gyro.*, src/lowpass.hpp, src/helper.cpp)
3. Configuration Manager (src/config_*.hpp)
4. Communication Services
• BLE GravityMon Service (src/ble_gravitymon.*)
• Wi-Fi Web Server (src/web_*.cpp/.hpp serving html assets)
• Push Client (src/pushtarget.*, src/push_*.cpp)
5. Main Application Logic
• Entry points: src/main_gravitymon.cpp, src/main.hpp
• Brewing mode handlers: src/web_brewing.*, src/config_brewing.*
6. Battery Management (src/battery.*)
7. Versioning & Bootloader Integration (scripts + bin/boot32*.bin)
c. External Systems
• Brewflasher.com (OTA/flasher service)
• GravityMon Cloud (optional HTTP/MQTT endpoints)
• User’s Web Browser or Mobile App (connects via BLE or HTTP)
• CI/CD & Documentation
• GitHub Actions workflows (.github/workflows/*.yaml)
• Sphinx (src_docs)
Architectural patterns & design principles
• Modular C++: separate driver, processing, service, and config layers
• Event/interrupt-driven sensor polling under FreeRTOS (implicitly via ESP-Arduino)
• Single-binary “fat” firmware: all subsystems compiled into one image
• Clear separation of I/O (hardware drivers), business logic, and presentation (web/BLE)
Essential elements
• Hardware: ESP32, sensors, battery
• Firmware subsystems: Drivers / Processing / Config / Comms / Main logic
• External: Brewflasher, GravityMon cloud, User clients
• CI/CD & Docs pipelines