Skip to content

MrRaidrop/ESP-MoNet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

57 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🌐 ESP32 Modular IoT Framework

πŸ‡¨πŸ‡³ δΈ­ζ–‡η‰ˆζœ¬ README.zh-CN.md | πŸ‡ΊπŸ‡Έ English Version README.md

This repository a service‑oriented framework for embedded systems, built on ESP‑IDFβ€―5.4 and tested on ESP32‑S3. Every function (light sensor, camera, UART, HTTP upload, BLE notify…) runs as an independent service module that auto‑registers through a service registry and communicates over a message bus. Adding a new sensor is one HAL + one service file; adding a new cloud sink is one subscriber. The same bus already fans‑out data to Wi‑Fiβ€―HTTP, BLEβ€―GATT and UART; hooks for MQTT, SD‑card, LoRa are ready.

How to Add a Sensor

Module CI


Releases

Version Date Highlights
v0.5 2025‑05‑03 Zero‑copy camera, binary cache, adaptive FPS, new docs
v0.6 2025‑05‑07 Introduced service_registry:
β€’ All services now registered via service_registry_register()
β€’ Can be controlled under group subscription
v0.7 β€” Sink / Uploader Refactor 2025‑05‑10 β€’ Added sink-callback architecture in service_registry
β€’ Replaced monolithic data_uploader_service with http_uploader_service
β€’ msg_t gains .release() hook – JPEG owner returns camera_fb_t safely
β€’ UART & HTTP now consume JSON-first
β€’ Only JPEG needs custom code (you can always add your own)
β€’ Will write a document showing how to do it
v0.8 β€” Kconfig Migration 2025-05-20 β€’ All project settings exposed via menuconfig
β€’ sdkconfig.defaults shipped for one-click build
β€’ Router table (publisher ➜ sink) selectable in UI
β€’ utils/config.h shrunk to a thin wrapper

Milestone Roadmap

Version ETA Key Changes Delivery Criteria
v0.9Β β€”Β BLE Service & OTA Refinement 2025‑06 β€’ Refactor BLE GATT layer: separate profile and service logic
β€’ Introduce ble_register_characteristic() API
β€’ Demo: add a custom Notify in 5 lines
β€’ Add How to Add BLE Characteristic doc
* BLE unit tests cover new API
* Existing Light Notify functionality remains compatible * OTA rollback
v1.0Β β€”Β Quality Release 2025‑06 β€’ β‰₯β€―80β€―% unit test coverage (cache, encoder, msg_bus, registry, BLE API)
β€’ GitHub Actions: build + ctest + clang-format all pass
β€’ Public firmware binary + 2‑min demo video
β€’ Complete bilingual docs and architecture diagrams
* CI passes all checks
* CHANGELOG & release notes finalized
* README features embedded demo video link

Features

  • Auto-reconnecting Wi-Fi connection manager
  • Periodic sensor readings via ADC (Analog-to-Digital Converter) or Digital Pin
  • Secure HTTPS POST to cloud with JSON payloads
  • Data uploader: 5-second loop by default (adaptive via RSSI)
  • UART echo for sensor debugging
  • BLE GATT Server: notifies mobile device with sensor data (e.g. light / JPEG hash)
  • Component-based structure under components/
  • Over-the-Air (OTA) firmware update (starts 30s after boot by default)
  • Camera (OV2640) JPEG capture + HTTP upload
  • Message Bus EVENT_SENSOR_JPEG for binary frame pipeline
  • Zero-copy JPEG transmission (camera_fb_t* passthrough, no memcpy)
  • Offline binary JPEG ring buffer with auto-retry
  • Future-ready: designed for MQTT and custom sensors
  • Decoupled module, can remove any pub or sub or sink
  • Camera Module Deep Dive
  • Bilingual Docs + Mermaid Diagrams

Project Structure

project-root
β”œβ”€β”€ components/
β”‚   β”œβ”€β”€ monet_hal/                 # Hardware abstraction layer (ADC, UART, Wi-Fi)
β”‚   β”‚   β”œβ”€β”€ include/monet_hal/*.h
β”‚   β”‚   └── src/*.c
β”‚   β”œβ”€β”€ monet_core/                # Core messaging infrastructure (e.g., msg_bus)
β”‚   β”‚   β”œβ”€β”€ include/monet_core/*.h
β”‚   β”‚   └── src/*.c
β”‚   β”œβ”€β”€ net/                 # Networking (HTTPS POST, future MQTT)
β”‚   β”‚   β”œβ”€β”€ include/net/*.h
β”‚   β”‚   └── src/*.c
β”‚   β”œβ”€β”€ OTA/                 # OTA update support via HTTPS
β”‚   β”‚   β”œβ”€β”€ include/OTA/*.h
β”‚   β”‚   └── src/*.c
β”‚   β”œβ”€β”€ service/             # Business logic (FreeRTOS tasks, BLE, Uploader)
β”‚   β”‚   β”œβ”€β”€ include/service/*.h
β”‚   β”‚   └── src/*.c
β”‚   └── utils/               # Common tools and infrastructure
β”‚       β”œβ”€β”€ include/utils/*.h
β”‚       └── src/*.c          # json_utils, cache, log, format helpers
β”‚
β”œβ”€β”€ main/                    # Application entry point
β”‚   β”œβ”€β”€ main.c
β”‚   └── CMakeLists.txt
β”‚
β”œβ”€β”€ .github/workflows/       # GitHub Actions CI
β”‚   └── ci.yml
β”œβ”€β”€ server/                  # OTA test server (optional)
└── README.md


Current Architecture

System Architecture

Click the link below to view the interactive system diagram:
πŸ‘‰ System Architecture Diagram - GitHub Pages


Getting Started

This guide will help you build, configure, and run the ESP-MoNet project on your ESP32-S3 board.

Prerequisites

  • ESP-IDF v5.0 or higher installed and configured
  • How to get ESP-IDF
  • Your ESP32-S3 DevKit board (e.g. Freenova ESP32-S3 with PSRAM, if camera not used, any esp32s3 board will be good)
  • A USB cable and access to serial terminal (e.g. screen, minicom, or idf.py monitor)

Quick Setup

  1. Clone the repository

    git clone https://github.com/MrRaidrop/ESP-MoNet.git
    cd ESP-MoNet
  2. Set the target chip

    idf.py set-target esp32s3
  3. Use provided configuration

    cp sdkconfig.default sdkconfig
  4. Configure and verify settings (optional)

    idf.py menuconfig

    Key settings (already set in sdkconfig.default, but double-check if needed):

    • Wi-Fi: enabled by default (CONFIG_WIFI_SERVICE_ENABLE)
    • BLE: enabled (CONFIG_BLE_SERVICE_ENABLE)
      BLE needs Bluetooth 4.2, not 5.0 (required on ESP32-S3)
    • Camera: enabled (CONFIG_CAMERA_SERVICE_ENABLE)
      Requires PSRAM support on ESP32-S3 and camera module (OV2640)
    • ADC / Light Sensor: enabled (CONFIG_LIGHT_SENSOR_ENABLE)
    • msg_bus / cache / JSON / uploader modules are enabled

Build & Flash

idf.py build flash monitor

Tip: Use idf.py menuconfig anytime to enable/disable features in the Modules section.

Optional: Verify Functionality

  • BLE: Connect via nRF Connect, observe sensor notify (e.g. light_value, jpeg_frame_hash)
  • UART: Run screen /dev/ttyUSB0 921600 or use serial terminal to see logs
  • Wi-Fi: ESP32 will upload JPEG + sensor data to your configured HTTPS server

What’s pre-configured in sdkconfig.default

Module Setting
Wi-Fi Enabled, STA mode
BLE Enabled, 4.2 only (not 5.0!)
Camera Enabled, PSRAM required
Light Sensor Enabled
Logging Info level, tag filtering enabled
Services All core modules enabled (msg_bus, cache)

Cameara module can be removed if you don't want to use it

Ready to go? Plug in your board, flash it, and watch the data flow.


OTA Update Test

Workflow: Firmware boots and connects to Wi-Fi

ota_test_task starts counting to 30

After 30s, it performs OTA via HTTPS:

https://<your_server_ip>:8443/firmware.bin 

To test OTA, build a new firmware version, host it on your server, and let the device auto-update.

For complete OTA server setup instructions, refer to:

/server/README_SERVER.md

JSON Upload Format

All sensor data is uploaded in a unified JSON format, automatically generated by the centralized encoder in json_encoder.c.

Each msg_t from the message bus is converted using json_encoder_encode() and sent via HTTP POST or BLE Notify, depending on connection status.

Example Outputs Light Sensor

{
  "type": "light",
  "value": 472,
  "ts": 1713302934
}

DHT22 Temperature & Humidity

{
  "type": "temp",
  "temperature": 24.65,
  "humidity": 63.10,
  "ts": 1713302971
}

Unknown topic fallback

{
  "type": "unknown",
  "topic": 99,
  "ts": 1713303001
}

Add Your Own Format

To define the format for your new sensor:

Extend the msg_t data union in msg_bus.h

Add a case in json_encoder_encode() to format the desired JSON fields for your topic.

The upload system requires no other changes β€” just define the message and format once.


Project Roadmap

Feature Overview

Feature Status Notes
Light sensor ADC driver βœ… Done Reads every 1s, publishes via msg_bus
JSON packaging utility βœ… Done Structured type + value + timestamp format
HTTPS POST to cloud βœ… Done Modular http_post_hal() + retry support
BLE GATT notification βœ… Done Subscribe msg_bus, notify phone via notify_raw()
UART forwarding (light sensor) βœ… Done UART sends formatted values via msg_bus subscription
Upload retry (cache) βœ… Done RAM ring buffer with manual flush_with_sender()
Modular task architecture βœ… Done Each service runs as isolated FreeRTOS task
OTA update (Wi-Fi) βœ… Done HTTPS OTA using esp_https_ota()
GitHub repo + documentation βœ… Done Clean README, architecture diagram, GitHub Actions
Camera JPEG capture βœ… Done OV2640 integration + camera_hal abstraction
Zero-copy JPEG pipeline βœ… Done camera_fb_t* passed directly via msg_bus
Offline binary JPEG cache βœ… Done flash-resident ring buffer with auto flush
Dynamic FPS based on RSSI βœ… Done Adapts to Wi-Fi quality automatically
MQTT secure upload πŸ”œ Planned Add TLS MQTT broker support
OTA update (BLE) πŸ”œ Planned Plan to implement BLE-based OTA update
DMA + Ring Buffer integration βœ… Done For ultrasonic / high-rate sensor support
Flutter mobile app (sensor UI) πŸ”œ Planned BLE dashboard for real-time sensor data
Flutter mobile app (BLE OTA) πŸ”œ Planned Integrated BLE OTA functionality

Known Limitations & Improvement Plan

Category Issue Description Improvement Direction Status
Architecture No centralized service lifecycle manager Add service_registry + app_init() startup logic βœ… Done
Config System Configs hardcoded in .c files Use Kconfig + NVS runtime override πŸ”œ Planned
Logging LOGI/W macros used, but no module-level control Introduce LOG_MODULE_REGISTER + per-module level βœ… Done
Unit Testing Only BLE utils tested in CI Add test cases for json_utils, cache, uploader ⏳ In Progress
HTTPS Security TLS certs not validated Add CA config toggle + cert verification NOT Planned
OTA Mechanism No image validation or rollback Add SHA256 + dual partition fallback πŸ”œ Planned
BLE Extension Only 1 notify char, no write command support Extend GATT profile to support control commands ⏳ In Progress

Want to contribute or suggest improvements? Feel free to open an issue or fork this repo!


Example Use Cases

  • Wi-Fi JPEG camera node with fail-safe cache
  • BLE-notifying environmental monitor
  • Hybrid image + sensor uploader
  • Custom IoT prototype platform, easily extendable to sensors, or servo output
  • Edge computing node with dynamic FPS control
  • Developer-friendly OTA testbed

How to Add a New Sensor

This guide walks you through integrating a new sensor (e.g., DHT22 for temperature/humidity) into the system.
Because this is a modular architecture, you can do this in 3 simple steps β€” without modifying any other services (UART, BLE, HTTP, etc.).

Click the link below to view the guide. πŸ‘‰ docs/how_to_add_sensor


Camera Module Deep Dive

Click the link below to view the guide. πŸ‘‰ docs/camera_module.md

Zero‑Copy, Adaptive & Offline‑Resilient

(Drop‑in for any OV2640‑based ESP32‑S3 board β€” tested on Freenove DevKit)

License

MIT License β€” Use freely, modify, and integrate.


πŸ› οΈ Last Updated: May 20, 2025
Made with ❀️ by Greyson Yu

About

A modular esp32 sensor framework

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published