An ESP32 embedded development library and GPS tracking system built with Rust and ESP-IDF. This project provides reusable modules for BLE, WiFi, GPS, LED control, and more, along with client/server applications demonstrating a complete GPS tracking solution.
This project consists of:
- Library - Reusable ESP32 modules for embedded development
- Client Example - GPS tracker that advertises speed data via BLE
- Server Example - BLE scanner that receives GPS data and posts to HTTP endpoint
Add esp32-simple to your ESP32 project:
cargo add esp32-simpleOr manually add to Cargo.toml:
[dependencies]
esp32-simple = "0.1"Then import modules:
use esp32_simple::{
ble::{Advertiser, Scanner},
wifi::Connection,
gps::Sensor,
// ... other modules
};The library provides the following modules for ESP32 development:
ble- Bluetooth Low Energy advertising and scanningbutton- Physical button input handling with polling-based debounceclock- Hardware timer management and interrupt configurationcolor- RGB color representation and predefined color constantsgps- GPS sensor reading via UART and NMEA parsinghttp- HTTP client for sending requests over WiFiinfra- Core infrastructure traits:Poller,Switch, andStatelight- NeoPixel LED control via the RMT peripheralmessage- Inter-thread messaging with triggers, notifiers, and dispatchersthread- Thread spawning with automatic device restart on failuretime- Time utilities for sleeping and cooperative yieldingwifi- WiFi connection management and configuration
This crate includes two complete example applications demonstrating a GPS tracking system.
The client example tracks GPS location and advertises maximum speed via BLE.
Features:
- Reads GPS data from UART sensor
- Calculates and tracks maximum speed
- Advertises speed data via BLE
- Button toggles tracking on/off
- LED indicates system state with colors and blinking patterns
Usage:
cargo run --example clientThe server example scans for BLE devices, receives GPS data, and posts it to an HTTP endpoint.
Features:
- Scans for nearby BLE devices
- Receives speed data from client via BLE
- Connects to WiFi network
- Posts data to HTTP endpoint
- Button toggles scanning on/off
- LED indicates system state
Usage:
cargo run --example serverThe system implements a client/server GPS tracking architecture:
-
Client Device:
- GPS sensor continuously reads location data
- Calculates maximum speed since tracking started
- Advertises max speed as BLE manufacturer data
- Button press resets max speed and toggles tracking
-
Server Device:
- BLE scanner searches for client devices
- Extracts speed data from BLE advertisements
- Maintains WiFi connection
- Posts received data to configured HTTP endpoint
-
Communication:
- Client and server use BLE for wireless communication
- Server uses WiFi for internet connectivity
- Both use state machines to coordinate components
The following environment variables must be set at compile time:
APP_NAME- Application name (default: "ESPlayground")
WIFI_SSID- WiFi network SSIDWIFI_PASSWORD- WiFi network passwordHTTP_URL- HTTP endpoint URL for posting dataHTTP_PARAM- HTTP parameter name for the payload
Example:
export APP_NAME="MyESP32App"
export WIFI_SSID="MyNetwork"
export WIFI_PASSWORD="MyPassword"
export HTTP_URL="https://example.com/api/data"
export HTTP_PARAM="speed"
cargo run --example serverThe library is ESP32 board-agnostic and can be used with any ESP32 development board.
The examples are designed for the M5Stack Atom Lite with specific hardware:
Required components for examples:
- M5Stack Atom Lite (ESP32-PICO) - base board for both examples
- Atomic GPS Base V2 (AT6668) - for client example
# Build library
cargo build --release
# Build examples
cargo build --release --examples
# Build specific example
cargo build --release --example client
cargo build --release --example server# Format code
cargo fmt
# Run linter
cargo clippy
# Generate documentation
cargo doc --no-deps --openexperimental- Enables experimental features fromesp-idf-svc
cargo build --features experimental- GPS sensor thread continuously reads NMEA data from UART
- When valid GPS reading is received, speed is calculated
- Maximum speed is tracked and stored
- Speed data is encoded and set as BLE manufacturer data
- BLE advertiser broadcasts the current state and speed
- LED blinks to indicate active GPS tracking
- Button press toggles tracking and resets max speed
- BLE scanner periodically scans for nearby devices
- When client device is detected, manufacturer data is extracted
- Speed data is decoded from BLE payload
- HTTP client posts the data to configured endpoint
- LED indicates when active device is detected
- Button press toggles scanning on/off
Both applications use a state machine pattern coordinating:
- Button input (toggle on/off)
- BLE operations (advertising/scanning)
- LED control (visual feedback)
- Timer-based periodic tasks
- Inter-thread messaging via FreeRTOS notifications
This project is licensed under the MIT License. See LICENSE-MIT for details.