Skip to content

πŸ›œ Lab Expert is a lab experiment visualization app that helps students and researchers understand complex experimental setups through interactive simulations. It bridges theory and practice by providing clear, engaging visuals for lab procedures, making it a valuable tool for education and research.

Notifications You must be signed in to change notification settings

shavihara/LabExpert_Sensor_Communications

Repository files navigation

πŸ”¬ LabExpert β€” ESP32 Sensor Firmware

Modular, OTA-upgradable firmware suite for the LabExpert IoT sensor platform

ESP32 Arduino PlatformIO MQTT BLE | WiFi MIT License


πŸ“– Overview

This repository contains the complete embedded firmware ecosystem for the LabExpert platform β€” a modular IoT-based laboratory experiment system. Each sensor module is powered by an ESP32 and communicates with a central backend over WiFi + MQTT. Firmware is deployed wirelessly via a dual-partition OTA (Over-The-Air) update mechanism.

Key Highlights

  • πŸ”„ Dual-Partition OTA β€” Bootloader on ota_0, experiment firmware on ota_1 with automatic failsafe rollback
  • πŸ“‘ MQTT Telemetry β€” Real-time sensor data streaming with binary-packed payloads
  • πŸ“Ά BLE Provisioning β€” Zero-config WiFi setup via Bluetooth Low Energy (NimBLE)
  • πŸ” UDP Auto-Discovery β€” Backend automatically discovers sensor modules on the local network
  • 🧩 Modular Architecture β€” Shared libraries, per-sensor firmware generators, and a common hardware abstraction
  • πŸ’Ύ EEPROM-Based Sensor ID β€” Each sensor module carries a unique identity via an AT24C02 I2C EEPROM

πŸ“ Repository Structure

LabExpert_Sensor_ESP32_CODES/
β”‚
β”œβ”€β”€ ESP_32_OTA/                        # πŸ”§ OTA Bootloader (always on ota_0)
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ main.cpp                   #    Core bootloader logic
β”‚   β”‚   β”œβ”€β”€ wifi_credentials.cpp/h     #    BLE-based WiFi credential manager
β”‚   β”œβ”€β”€ partitions/
β”‚   β”‚   └── custom_partitions.csv      #    Dual OTA partition table
β”‚   └── platformio.ini
β”‚
β”œβ”€β”€ THR_Firmware_bin_Generator/        # 🌑️  Temperature (DS18B20) firmware
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ main.cpp                   #    Entry point & init
β”‚   β”‚   β”œβ”€β”€ sensor_communication.cpp   #    DS18B20 OneWire driver
β”‚   β”‚   β”œβ”€β”€ experiment_manager.cpp     #    Sampling loop & data batching
β”‚   β”‚   β”œβ”€β”€ mqtt_handler.cpp           #    MQTT pub/sub & commands
β”‚   β”‚   └── config_handler.cpp         #    HTTP API & experiment config
β”‚   β”œβ”€β”€ include/                       #    Header files
β”‚   β”œβ”€β”€ partitions/                    #    Partition table
β”‚   └── platformio.ini
β”‚
β”œβ”€β”€ TOF_Firmware_bin_Generator/        # πŸ“ Time-of-Flight (VL53L1X) firmware
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ main_sensor.cpp            #    Entry point (dual-core init)
β”‚   β”‚   β”œβ”€β”€ sensor_communication.cpp   #    I2C VL53L1X driver (10–50 Hz)
β”‚   β”‚   β”œβ”€β”€ experiment_manager.cpp     #    Timer ISR + Core 0 sensor task
β”‚   β”‚   β”œβ”€β”€ motor_controller.cpp       #    DC motor control (PWM + encoder)
β”‚   β”‚   β”œβ”€β”€ mqtt_handler.cpp           #    MQTT with binary data packets
β”‚   β”‚   └── config_handler.cpp         #    HTTP API, OTA upload handler
β”‚   β”œβ”€β”€ include/
β”‚   β”œβ”€β”€ partitions/
β”‚   β”œβ”€β”€ Implementation_Guide.md        #    Detailed I2C migration docs
β”‚   └── platformio.ini
β”‚
β”œβ”€β”€ OSI_Firmware_bin_Generator/        # 〰️  Oscillation Sensor firmware
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ main_sensor.cpp
β”‚   β”‚   β”œβ”€β”€ sensor_communication.cpp
β”‚   β”‚   β”œβ”€β”€ experiment_manager.cpp
β”‚   β”‚   β”œβ”€β”€ mqtt_handler.cpp
β”‚   β”‚   └── config_handler.cpp
β”‚   β”œβ”€β”€ EEPROM_driver.cpp              #    AT24C02 test/debug utility
β”‚   β”œβ”€β”€ partitions/
β”‚   └── platformio.ini
β”‚
β”œβ”€β”€ UltraSonic_Firmware_bin_Generator/ # πŸ“ Ultrasonic (HC-SR04) firmware
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ main_sensor.cpp
β”‚   β”‚   β”œβ”€β”€ sensor_communication.cpp
β”‚   β”‚   β”œβ”€β”€ experiment_manager.cpp
β”‚   β”‚   β”œβ”€β”€ mqtt_handler.cpp
β”‚   β”‚   └── config_handler.cpp
β”‚   β”œβ”€β”€ partitions/
β”‚   └── platformio.ini
β”‚
β”œβ”€β”€ BH1750/                            # πŸ’‘ Light Intensity calibration tool
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   └── main.cpp                   #    Calibration wizard (Arduino Uno)
β”‚   └── platformio.ini
β”‚
β”œβ”€β”€ shared/                            # πŸ“¦ Shared libraries (all firmwares)
β”‚   β”œβ”€β”€ LedController.h / .cpp         #    Multi-mode LED driver
β”‚   β”œβ”€β”€ nvs_wifi_credentials.h         #    NVS WiFi credential reader
β”‚   └── nvs_mqtt_credentials.h         #    NVS MQTT credential manager
β”‚
β”œβ”€β”€ bluetoothConfigeration/            # πŸ“² Standalone BLE provisioning tool
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   └── main.cpp                   #    NimBLE UART service (Nordic)
β”‚   └── platformio.ini
β”‚
β”œβ”€β”€ R_W_E_EEPROM_arduino_uno/          # πŸ”§ EEPROM utility (Arduino Uno)
β”‚   └── read_write_erase_for_arduino_uno/
β”‚       └── read_write_erase_for_arduino_uno.ino
β”‚
β”œβ”€β”€ Binn/                              # πŸ“¦ Binary firmware generators
β”‚   β”œβ”€β”€ binFileGen/                    #    ESP32 binary builder
β”‚   └── binFileGen - NodeMCU/          #    NodeMCU binary builder
β”‚
β”œβ”€β”€ docs/                              # πŸ“š Documentation & diagrams
β”‚   └── esp32-ota/
β”‚       β”œβ”€β”€ ESP32_OTA_Documentation.md #    Full OTA system documentation
β”‚       β”œβ”€β”€ api_reference.md           #    REST API reference
β”‚       β”œβ”€β”€ architecture.drawio        #    System architecture diagram
β”‚       β”œβ”€β”€ flowchart.png              #    Boot flow diagram
β”‚       β”œβ”€β”€ sequence_backend_push.png  #    Backend OTA sequence
β”‚       β”œβ”€β”€ sequence_web_upload.png    #    Web upload sequence
β”‚       └── state_diagram.png          #    State machine diagram
β”‚
β”œβ”€β”€ pin_usage.md                       # πŸ“Œ Complete GPIO pin mapping
β”œβ”€β”€ .gitignore
└── README.md                          # ← You are here

βš™οΈ System Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                        LabExpert Backend                        β”‚
β”‚              (Python Β· MQTT Broker Β· REST API Β· DB)             β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
               β”‚  MQTT (pub/sub)              β”‚  UDP Discovery
               β”‚  Port 1883                   β”‚  Port 8888/8889
               β–Ό                              β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                     ESP32 Sensor Module                         β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚  β”‚  Partition: ota_0 (1.5 MB)          ota_1 (1.5 MB)        β”‚  β”‚
β”‚  β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚  β”‚
β”‚  β”‚  β”‚   ESP_32_OTA        β”‚  β”‚  Sensor Firmware          β”‚   β”‚  β”‚
β”‚  β”‚  β”‚   (Bootloader)      β”‚  β”‚  (THR/TOF/OSI/ULT)       β”‚   β”‚  β”‚
β”‚  β”‚  β”‚                     β”‚  β”‚                           β”‚   β”‚  β”‚
β”‚  β”‚  β”‚  β€’ BLE Provisioning β”‚  β”‚  β€’ Sensor Reading         β”‚   β”‚  β”‚
β”‚  β”‚  β”‚  β€’ WiFi Manager     β”‚  β”‚  β€’ MQTT Publishing        β”‚   β”‚  β”‚
β”‚  β”‚  β”‚  β€’ UDP Discovery    β”‚  β”‚  β€’ Experiment Manager     β”‚   β”‚  β”‚
β”‚  β”‚  β”‚  β€’ OTA Web Server   β”‚  β”‚  β€’ HTTP Config API        β”‚   β”‚  β”‚
β”‚  β”‚  β”‚  β€’ EEPROM Detection β”‚  β”‚  β€’ Dual-Core Processing   β”‚   β”‚  β”‚
β”‚  β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚  β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
β”‚                                                                 β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”       β”‚
β”‚  β”‚ AT24C02  β”‚  β”‚  Sensor  β”‚  β”‚  Status  β”‚  β”‚  Motor   β”‚       β”‚
β”‚  β”‚ EEPROM   β”‚  β”‚  Module  β”‚  β”‚  LEDs    β”‚  β”‚ (TOF)    β”‚       β”‚
β”‚  β”‚ (I2C)    β”‚  β”‚  (I2C/   β”‚  β”‚  Γ—5      β”‚  β”‚  (PWM)   β”‚       β”‚
β”‚  β”‚          β”‚  β”‚   1-Wire β”‚  β”‚          β”‚  β”‚          β”‚       β”‚
β”‚  β”‚          β”‚  β”‚   /GPIO) β”‚  β”‚          β”‚  β”‚          β”‚       β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜       β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Boot Flow

  1. Power On β†’ ESP32 boots from ota_0 (OTA Bootloader)
  2. EEPROM Check β†’ Reads sensor type ID from AT24C02 (0x50)
  3. WiFi Connect β†’ Loads credentials from NVS (saved via BLE provisioning)
  4. UDP Discovery β†’ Responds to backend broadcast, receives MQTT broker info
  5. OTA Push β†’ Backend pushes matching firmware binary to ota_1
  6. Reboot β†’ ESP32 boots into experiment firmware on ota_1
  7. Failsafe β†’ If EEPROM unreadable or firmware crashes, auto-rollback to ota_0

πŸ§ͺ Supported Experiments

ID Experiment Sensor Firmware Communication Frequency
THR Temperature DS18B20 THR_Firmware_bin_Generator OneWire (Pin 23) Configurable
TOF Distance / Motion VL53L1X (TOF400F) TOF_Firmware_bin_Generator I2C (Pin 21/22) 10–50 Hz
OSI Oscillation Digital Sensor OSI_Firmware_bin_Generator GPIO (Pin 33) Configurable
ULT Distance HC-SR04 UltraSonic_Firmware_bin_Generator GPIO Trig/Echo (Pin 21/22) Configurable
BH Light Intensity BH1750 BH1750 (calibration only) I2C (Pin 21/22) 2 Hz (cal mode)

πŸ”Œ Hardware Pin Map (ESP32)

Pin Function Used By
12 BLE Status LED (Active Low) All
13 Sensor Connected LED (Active Low) All
14 WiFi Status LED (Active Low) All
16 OTA Status LED (Active Low) All
18 EEPROM SDA (I2C) All
19 EEPROM SCL (I2C) All
21 Sensor SDA / Trig TOF, ULT, BH
22 Sensor SCL / Echo TOF, ULT, BH
23 OneWire / LDR Encoder THR, TOF
25 EEPROM Write Protect OTA
26 Motor Left PWM / I2S WS TOF
27 Sensor Active LED (Active Low) All
32 OTA Restart Trigger All Firmware
33 Motor Right PWM / OSI Sensor TOF, OSI
34 BLE Trigger / Factory Reset OTA
35 Limit Switch (OR Gate) TOF

πŸ“Œ Full pin documentation with LED logic states available in pin_usage.md

LED Status Indicators

LED (Pin) State Meaning
WiFi (14) ON Disconnected
WiFi (14) Blink (Slow) Connected
WiFi (14) OFF Bluetooth mode active
BLE (12) ON BLE advertising
BLE (12) Blink BLE connected
Sensor (13) OFF Sensor connected
Sensor (13) ON Sensor disconnected
Active (27) Blink (Fast) Experiment running
OTA (16) Blink (Fast) OTA restart triggered

πŸ› οΈ Prerequisites

Tool Version Purpose
PlatformIO Latest Build system & dependency management
VS Code Latest IDE (recommended with PlatformIO extension)
ESP32 Dev Board ESP32-WROOM-32 Target microcontroller
Arduino Uno ATmega328P BH1750 calibration & EEPROM utility
USB Cable Micro-USB / USB-C Initial flash & serial monitor

πŸš€ Getting Started

1. Clone the Repository

git clone <repository-url>
cd LabExpert_Sensor_ESP32_CODES

2. Flash the OTA Bootloader (First Time Only)

The OTA bootloader must be flashed via USB once. After that, all firmware updates happen wirelessly.

cd ESP_32_OTA
pio run -t upload
pio device monitor        # Verify boot output

3. Build a Sensor Firmware Binary

Each sensor firmware generates a .bin file for OTA deployment:

cd THR_Firmware_bin_Generator    # Or TOF / OSI / UltraSonic
pio run                          # Compile firmware

The compiled binary is located at:

.pio/build/esp32dev/firmware.bin

4. Deploy via OTA

The backend automatically pushes the correct firmware via the OTA HTTP API:

# Manual OTA push (for testing)
curl -X POST "http://<esp32-ip>/update" \
  -F "update=@.pio/build/esp32dev/firmware.bin"

Or use the backend's programmatic OTA endpoint:

POST /ota/begin   β†’  { "size": <bytes> }
POST /ota/write   β†’  { "offset": 0, "size": 1024, "data": "<hex>" }
POST /ota/end     β†’  triggers reboot

πŸ“¦ Shared Libraries

All sensor firmwares include shared code from the shared/ directory via the -I../shared build flag.

LedController

Multi-mode LED driver supporting active-low hardware with non-blocking blink patterns.

#include "LedController.h"

LedController led(14, true);  // Pin 14, active-low

led.begin();
led.set(LedController::BLINK_SLOW);  // 1s on/off
led.set(LedController::BLINK_FAST);  // 200ms on/off
led.set(LedController::BLINK_PULSE); // 150ms on, 2850ms off
led.update();                         // Call in loop()

nvs_wifi_credentials.h

Header-only NVS reader for WiFi credentials saved by the OTA bootloader's BLE provisioning.

#include "nvs_wifi_credentials.h"

char ssid[33], password[65];
if (loadWiFiCredentialsFromNVS(ssid, sizeof(ssid), password, sizeof(password))) {
    WiFi.begin(ssid, password);
}

nvs_mqtt_credentials.h

NVS-based MQTT broker credential manager with change detection to minimize flash writes.

#include "nvs_mqtt_credentials.h"

// Save (OTA bootloader)
saveMQTTCredentialsToNVS("192.168.1.100", 1883, "aa:bb:cc:dd:ee:ff");

// Load (sensor firmware)
char broker[40]; uint16_t port; char mac[18];
loadMQTTCredentialsFromNVS(broker, sizeof(broker), &port, mac, sizeof(mac));

πŸ”— Firmware Module Architecture

Each sensor firmware (THR, TOF, OSI, ULT) follows a consistent modular pattern:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                  main.cpp                     β”‚
β”‚         (Init, WiFi, LED control, loop)       β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  sensor_ β”‚ experimentβ”‚   mqtt_   β”‚  config_   β”‚
β”‚  communi β”‚ _manager  β”‚  handler  β”‚  handler   β”‚
β”‚  cation  β”‚           β”‚           β”‚            β”‚
β”‚          β”‚           β”‚           β”‚            β”‚
β”‚ β€’ Init   β”‚ β€’ Timer   β”‚ β€’ Setup   β”‚ β€’ Status   β”‚
β”‚ β€’ Read   β”‚   ISR     β”‚ β€’ Pub/Sub β”‚ β€’ Config   β”‚
β”‚ β€’ EEPROM β”‚ β€’ Core 0  β”‚ β€’ Callbackβ”‚ β€’ Start    β”‚
β”‚ β€’ Calib  β”‚   task    β”‚ β€’ Binary  β”‚ β€’ Stop     β”‚
β”‚          β”‚ β€’ Batch   β”‚   packets β”‚ β€’ OTA      β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
        β–²                    β–²
        β”‚                    β”‚
   shared/              shared/
   LedController        nvs_*_credentials
Module Responsibility
main.cpp / main_sensor.cpp Hardware init, WiFi connection, LED management, main loop
sensor_communication.cpp Sensor driver, EEPROM ID detection, device ID from MAC
experiment_manager.cpp Timer ISR, sampling task (Core 0), data batching & buffering
mqtt_handler.cpp MQTT connection, topic subscription, binary data publishing
config_handler.cpp AsyncWebServer HTTP API (/status, /config, /start, /stop, /update)

🌐 HTTP API Endpoints (Sensor Firmware)

Method Endpoint Description
GET /status Current sensor status, experiment state, config
GET /config Read current experiment configuration
POST /config Set frequency, duration, mode
POST /start Start experiment data collection
POST /stop Stop running experiment
POST /update Upload firmware binary (multipart)
GET /id Get sensor type ID

OTA Bootloader Endpoints

Method Endpoint Description
GET / OTA management web page
GET /info Sensor type & ID (JSON)
GET /ping Health check (pong)
POST /update Upload firmware (multipart form)
POST /ota/begin Start chunked OTA ({ "size": N })
POST /ota/write Write chunk ({ "offset", "size", "data" })
POST /ota/end Finalize OTA & reboot
POST /sensor/repair Rewrite EEPROM sensor ID
GET /id Get current sensor type

πŸ”„ OTA Update Flow

sequenceDiagram
    participant Backend
    participant ESP32 (ota_0)
    participant ESP32 (ota_1)

    Note over ESP32 (ota_0): Bootloader running
    Backend->>ESP32 (ota_0): UDP Discovery broadcast
    ESP32 (ota_0)-->>Backend: Device ID, IP, sensor type
    Backend->>ESP32 (ota_0): POST /ota/begin {size}
    Backend->>ESP32 (ota_0): POST /ota/write {chunks...}
    Backend->>ESP32 (ota_0): POST /ota/end
    Note over ESP32 (ota_1): Firmware written to ota_1
    ESP32 (ota_0)->>ESP32 (ota_1): Reboot β†’ ota_1
    Note over ESP32 (ota_1): Sensor firmware running
    ESP32 (ota_1)-->>Backend: MQTT sensor data
Loading

🧰 Utility Tools

BH1750 Calibration Wizard (BH1750/)

Interactive serial tool for calibrating a BH1750 light sensor against a reference meter (UT383). Runs on Arduino Uno.

Command Action
c Collect calibration data point
s Show collected data
f Calculate calibration factors (linear regression)
r Reset data
m Show current calibrated measurement
d Debug / I2C scan
cd BH1750
pio run -t upload
pio device monitor

EEPROM Read/Write/Erase (R_W_E_EEPROM_arduino_uno/)

Serial tool for programming AT24C02 EEPROM sensor IDs. Runs on Arduino Uno.

Option Action
1 Write new Sensor ID
2 Read current Sensor ID
3 Erase EEPROM
4 Full hex dump (0x00–0xFF)

EEPROM Driver (OSI_Firmware_bin_Generator/EEPROM_driver.cpp)

Standalone AT24C02 test utility for ESP32 with I2C scanning, page write, boundary tests, and full hex dump.

Bluetooth Configuration (bluetoothConfigeration/)

Standalone BLE provisioning tool using NimBLE Nordic UART Service (NUS). Saves WiFi credentials to NVS Preferences on confirmation.


πŸ—‚οΈ Custom Partition Table

# Name,    Type,  SubType, Offset,    Size
nvs,       data,  nvs,     0x9000,    0x5000   (20 KB)
otadata,   data,  ota,     0xe000,    0x2000   (8 KB)
ota_0,     app,   ota_0,   0x10000,   0x180000 (1.5 MB) ← Bootloader
ota_1,     app,   ota_1,   0x190000,  0x180000 (1.5 MB) ← Sensor Firmware
spiffs,    data,  spiffs,  0x310000,  0x0F0000 (960 KB)

πŸ“š Dependencies

ESP32 Firmware (Common)

Library Version Purpose
ArduinoJson ^6.21 / ^7.4 JSON serialization
ESPAsyncWebServer Latest Async HTTP server
AsyncTCP ^1.1.1 Async TCP for ESP32
WebSockets ^2.4.1 WebSocket support
PubSubClient ^2.8 MQTT client

Sensor-Specific

Library Firmware Purpose
DallasTemperature THR DS18B20 driver
OneWire THR OneWire protocol
VL53L1X TOF Time-of-Flight sensor
NimBLE-Arduino OTA BLE provisioning
BH1750 BH1750 Light sensor (Uno)

πŸ“ Documentation

Document Description
pin_usage.md Complete GPIO pin mapping for all experiments
docs/esp32-ota/ESP32_OTA_Documentation.md Full OTA system documentation
docs/esp32-ota/api_reference.md REST API reference
TOF_Firmware_bin_Generator/Implementation_Guide.md TOF I2C implementation guide

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/new-sensor
  3. Follow the modular architecture pattern (see Firmware Module Architecture)
  4. Test with serial monitor: pio device monitor
  5. Submit a pull request

Adding a New Sensor

  1. Duplicate an existing firmware generator folder (e.g., UltraSonic_Firmware_bin_Generator)
  2. Modify sensor_communication.cpp with your sensor driver
  3. Update experiment_manager.cpp for sampling logic
  4. Set the EEPROM sensor ID (3-char code, e.g., "MIC")
  5. Update pin_usage.md with your pin assignments

πŸ“„ License

This project is licensed under the MIT License.

MIT License

Copyright (c) 2025 LabExpert

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Built with ❀️ for physics education using ESP32 + PlatformIO

About

πŸ›œ Lab Expert is a lab experiment visualization app that helps students and researchers understand complex experimental setups through interactive simulations. It bridges theory and practice by providing clear, engaging visuals for lab procedures, making it a valuable tool for education and research.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •