|
|
Plumet ESP8266 Firmware is the embedded software component of the Plumet system. This firmware runs on the wearable belt device equipped with a NodeMCU ESP8266 and MPU6050 IMU sensor.
- Sensor Monitoring: The MPU6050 accelerometer is polled at 100Hz to detect sudden acceleration changes
- Fall Detection Algorithm: Analyzes G-force patterns to identify free fall followed by impact
- Event Publishing: When a fall is detected, connects to WiFi and publishes an MQTT message
- Real-time Alerts: The backend forwards the alert to the mobile app via MQTT, showing a push notification
ESP8266 (Firmware) Backend (NestJS) Mobile App
| | |
|-- Fall detected | |
|-- Connect to WiFi | |
|-- Publish to MQTT | |
| | |
|------------------------------------->| Forward alert via MQTT |
| | |
| |------------------------------------->|
| | Push notification shown
| | |
|-- Disconnect immediately | |
| | |
|-- Return to sleep mode | |
- Event-driven MQTT: The device only connects to MQTT when a fall is detected, then disconnects. This saves battery and reduces network traffic.
- WiFi Provisioning via Captive Portal: Users can configure WiFi credentials through a browser-based interface without modifying code.
- EEPROM Storage: WiFi credentials are persisted in non-volatile memory, surviving power cycles.
- Real-time Fall Detection - 100Hz accelerometer sampling with adaptive algorithm
- WiFi Provisioning - Captive portal for easy network configuration
- MQTT over WebSocket - Secure event-driven communication
- LED Status Indicators - Visual feedback for device state
- Event-Driven Architecture - Battery-efficient, sleeps until fall detected
- Telemetry Data - G-force, timestamp, baseline calibration values
- Hardware Requirements
- Software Prerequisites
- Wiring Diagram
- Quick Start
- Flash Firmware
- WiFi Configuration
- LED Status Patterns
- Fall Detection Algorithm
- MQTT Protocol
- Troubleshooting
| Component | Specification | Qty | Notes |
|---|---|---|---|
| NodeMCU ESP8266 | ESP-12E, 4MB Flash | 1 | Development board with USB |
| MPU6050 | 3-axis IMU (accel + gyro) | 1 | I2C interface |
| Belt/Strap | Adjustable, 2-5cm width | 1 | For wearing the device |
| USB Cable | Micro-USB, data-capable | 1 | For flashing |
| Jumper Wires | Female-to-female | 4 | For I2C connection |
| Power Source | 5V USB or 3.7V LiPo | 1 | Battery for portable use |
- 3.7V LiPo Battery - For portable operation
- TP4056 Charger Module - For battery charging
- Switch - On/off power control
- Enclosure - 3D printed case
pip install platformio
pio --version- Windows: Install CH340 USB driver
- macOS: Usually pre-installed, or install here
- Linux: Usually pre-installed (
sudo modprobe usbserialif needed)
flowchart TD
subgraph NodeMCU["NodeMCU ESP8266"]
D1["D1 (GPIO5)<br/>I2C SCL"]
D2["D2 (GPIO4)<br/>I2C SDA"]
VCC["3V3"]
GND["GND"]
end
subgraph MPU6050["MPU6050 Sensor"]
SCL["SCL"]
SDA["SDA"]
VCC2["VCC"]
GND2["GND"]
INT["INT (Optional)"]
end
D1 -->|"Jumper Wire"| SCL
D2 -->|"Jumper Wire"| SDA
VCC -->|"Jumper Wire"| VCC2
GND -->|"Jumper Wire"| GND2
style D1 fill:#EDD60A
style D2 fill:#EDD60A
style VCC fill:#ef4444
style GND fill:#374151
style SCL fill:#3b82f6
style SDA fill:#3b82f6
style VCC2 fill:#ef4444
style GND2 fill:#374151
| NodeMCU | MPU6050 | Wire Color |
|---|---|---|
| D1 (GPIO5) | SCL | Yellow |
| D2 (GPIO4) | SDA | Green |
| 3V3 | VCC | Red |
| GND | GND | Black |
| Pin | Description |
|---|---|
| Built-in LED (D4/GPIO2) | Status indicator (active LOW) |
- Power Off: Disconnect USB before wiring
- Connect I2C:
- SCL (D1) to MPU6050 SCL
- SDA (D2) to MPU6050 SDA
- Connect Power:
- 3V3 to MPU6050 VCC
- GND to MPU6050 GND
- Verify: Check connections against diagram above
- Power On: Connect USB cable
Warning:
- VCC of MPU6050 is 3.3V only - Do NOT connect to 5V (Vin)
- Ensure correct polarity (VCC to VCC, GND to GND)
git clone https://github.com/plumet/plumet-esp8266.git
cd plumet-esp8266# Build for ESP8266
pio runOutput will be in .pio/build/esp8266/firmware.bin
# Upload to connected device
pio run --target upload
# Monitor serial output (optional)
pio device monitor
# Upload and monitor in one command
pio run --target upload && pio device monitor-
Download firmware:
- Go to Releases
- Download
plumet-esp8266-vX.X.X.bin
-
Install esptool:
pip install esptool
-
Find your serial port:
# Linux ls /dev/ttyUSB* # macOS ls /dev/tty.usbserial* # Windows # Look in Device Manager for COM port
-
Flash firmware:
esptool.py --chip esp8266 \ --port /dev/ttyUSB0 \ --baud 460800 \ write_flash \ -fm dio \ -fs 4MB \ 0x00000 firmware.bin
Replace
/dev/ttyUSB0with your serial port.
- Download NodeMCU Flasher
- Extract and run
nodemcu-flasher.exe - Select firmware
.binfile - Select COM port
- Click "Flash" button
After flashing, open serial monitor:
pio device monitor -b 115200You should see:
[INFO] Attempting to connect to WiFi...
Or if no WiFi configured:
[INFO] AP mode active. Connect to configure WiFi
The device features a captive portal for WiFi provisioning:
- First Boot - Device creates AP:
Plumet_<CHIPID> - Connect - Join the AP with your phone/laptop (no password needed)
- Configure - Browser opens automatically (captive portal)
- Enter Credentials - SSID and password
- Connect - Device saves credentials and restarts
- Ready - Device connects to WiFi and starts monitoring
There are three ways to reset WiFi credentials and force AP mode:
Edit src/config/config.h and temporarily set the persistence flag to false:
#define PERSIST_WIFI_CREDENTIALS false- Flash the firmware with
PERSIST_WIFI_CREDENTIALS = false - Device will clear credentials on boot and enter AP mode
- Reconfigure WiFi via captive portal
- Change flag back to
trueand reflash for normal operation
If WiFi connection fails (after 60 second timeout), the device will:
- Automatically clear credentials from EEPROM
- Restart and enter AP mode
- Allow you to reconfigure WiFi via captive portal
Temporarily add to setup() in src/main.ino:
WiFiManager.clearCredentials();
ESP.restart();Flash the firmware, then remove these lines and reflash after reconfiguration.
| Pattern | Meaning | Description |
|---|---|---|
| Fast Blink (100ms) | AP Mode | Waiting for WiFi configuration |
| Slow Blink (500ms) | Ready | WiFi connected, monitoring active |
| Medium Blink (250ms) | Connecting | Attempting WiFi connection |
| Solid Off | Device Ready | Device is connected and ready |
| 10 Rapid Blinks | Fall Alert | Fall detected, publishing event |
┌─────────────────────────────────────────────────────────────┐
│ FALL DETECTION FLOW │
├─────────────────────────────────────────────────────────────┤
│ │
│ 1. SAMPLE @ 100Hz │
│ ├── Read MPU6050 (accel + gyro) │
│ ├── Convert raw to G-force (16384 LSB/g) │
│ └── Calculate magnitude |a| = √(ax² + ay² + az²) │
│ │
│ 2. UPDATE HISTORY (Circular Buffer - 50 samples) │
│ └── Push magnitude, pop oldest if full │
│ │
│ 3. DETECT FALL │
│ ├── Check: current G > IMPACT_THRESHOLD (3.0G) │
│ └── Verify: >50% samples < FALL_THRESHOLD (2.5G) │
│ │
│ 4. TRIGGER ALERT │
│ ├── LED: 3 rapid blinks │
│ ├── MQTT: Publish JSON payload │
│ └── Return to monitoring │
│ │
└─────────────────────────────────────────────────────────────┘
-
Calibration Phase (5 seconds):
- Collects baseline acceleration values
- Averages samples to determine resting orientation
-
Monitoring Phase (continuous):
- Reads accelerometer at 100Hz
- Maintains circular buffer of last 50 samples
- Calculates magnitude of acceleration vector
-
Detection Logic:
- Impact Detection: Current G-force > 3.0G
- Fall Confirmation: >50% of recent samples < 2.5G
- Combined indicates free fall followed by impact
Method: MQTT over WebSocket
Port: 443 (WSS)
QoS: 1 (At least once)
{
"macAddress": "AA:BB:CC:DD:EE:FF",
"timestamp": 1234567890,
"gForce": 3.2,
"baselineX": 0.1,
"baselineY": -0.2,
"baselineZ": 9.8
}| Field | Type | Description |
|---|---|---|
macAddress |
string | Device MAC address (uppercase, colon-separated) |
timestamp |
number | Uptime in milliseconds since boot |
gForce |
float | Peak G-force at impact (1.0 = normal gravity) |
baselineX/Y/Z |
float | Calibration baseline values (G-force) |
Edit src/config/config.h to customize behavior:
#define PERSIST_WIFI_CREDENTIALS falseNote: Currently set to false for development. WiFi credentials are not persisted between reboots.
#define MQTT_BROKER "broker-plumet.pcamposu.com"
#define MQTT_PORT 443
#define PLUMET_MQTT_TIMEOUT 15000
#define FALL_THRESHOLD 2.5
#define IMPACT_THRESHOLD 3.0
#define SAMPLE_RATE 100
#define CALIBRATION_SAMPLES 100
#define WIFI_CONNECTION_TIMEOUT 60000
#define SENSOR_READ_DELAY 10-D DEBUG=1Symptoms: LED keeps blinking fast, can't find device on network
Solutions:
- Check credentials - Press reset button twice quickly to clear EEPROM
- Verify SSID - Ensure SSID is visible and 2.4GHz (not 5GHz)
- Check password - Re-enter credentials via captive portal
- Restart router - Sometimes router has connection issues
Symptoms: Device doesn't detect falls when tested
Solutions:
- Calibrate sensor - Place belt on flat surface during calibration
- Check MPU6050 - Verify I2C connections (SCL: D1, SDA: D2)
- Adjust thresholds - Lower
IMPACT_THRESHOLDin config.h - Serial monitor - Check for
[Sensor] Fall detected!messages - Test firmly - Drop device from ~30cm onto soft surface
Symptoms: Fall detected but no MQTT message received
Solutions:
- Verify broker - Check MQTT_BROKER and MQTT_PORT in config.h
- Check WiFi - Ensure device has IP address
- Test manually - Use MQTT explorer to connect to broker
- View logs - Serial monitor shows MQTT connection attempts
- Check firewall - Ensure outbound connections on port 443 are allowed
Symptoms: Upload fails, timeout errors
Solutions:
- Hold FLASH button - Press and hold GPIO0 button while powering on
- Check driver - Install CH340 driver (Windows)
- Try different cable - Use a data-capable USB cable
- Lower baud rate - Change
upload_speedto 57600 in platformio.ini - Reset board - Press reset button before uploading
Symptoms: Random characters, unreadable text
Solutions:
- Check baud rate - Must be 115200
- Try different terminal - Use PlatformIO monitor instead of Arduino Serial Monitor
- Check USB cable - Some cables only work for power, not data
pio test
pio test -v
pio test -e esp8266pio run --target upload DEBUG=1pio run --target size
# Expected output:
# Sketch uses 245KB (23% of storage)
# Global variables use 32KB (39% of dynamic memory)- Fork the repository
- Create feature branch (
git checkout -b feature/amazing-feature) - Commit changes (
git commit -m 'Add amazing feature') - Push to branch (
git push origin feature/amazing-feature) - Open Pull Request
git clone https://github.com/your-username/plumet-esp8266.git
cd plumet-esp8266
git remote add upstream https://github.com/plumet/plumet-esp8266.git
git fetch upstream
git merge upstream/mainThis project is licensed under the GNU General Public License v3.0 - see the COPYING file for details.

