An ESP32-based BitChat relay node that discovers nearby peers over BLE, connects to them, listens for BitChat packets, and re-broadcasts messages to extend the mesh.
It currently:
- Scans for peers advertising the BitChat GATT service.
- Accepts inbound connections while advertising its own BitChat service.
- Maintains up to 8 concurrent BLE client connections.
- Subscribes to notifications and parses packets via
BitchatPacketSerializer. - Handles ANNOUNCE and KEY_EXCHANGE packets (echo/response + self-announce).
- Queues outgoing packets and broadcasts them to all connected peers.
- Uses a global BLE mutex to avoid simultaneous scan/advertise conflicts.
- Runs work on FreeRTOS tasks to keep the loop lean.
- ✅ Relay over BLE (scan ↔ connect ↔ notify ↔ re-broadcast)
- ✅ Packet types supported:
ANNOUNCE,KEY_EXCHANGE - ✅ Connection cap: 8 clients (configurable)
- ✅ Duplicate-safe broadcast (partial) – queue-based; message-ID de-dup TBD
- ⏳ TTL enforcement (TBD)
- ⏳ Signature verification / E2E crypto (TBD)
- ⏳ Wi-Fi / LoRa backhaul (TBD)
- Service:
F47B5E2D-4A9E-4C5A-9B3F-8E1D2C3A4B5C - Characteristic:
A1B2C3D4-E5F6-4A5B-8C9D-0E1F2A3B4C5D(notify / write)
- Advertise a BitChat service and accept inbound connections.
- Scan for other advertisers; when found, connect as a client and subscribe to notifications.
- On notification, deserialize payload →
BitchatPacket. - Handle packet types:
KEY_EXCHANGE: reply with mock combined public key; then send selfANNOUNCE.ANNOUNCE: log/ack (hook for future routing/neighbor table).
- Enqueue response/announce packets; broadcast to all connected peers.
xScanForPeersTask: active scan (5s), enqueue connect targets.xAdvertiseBLEServerTask: advertise in 10s on / 5s off duty cycle.packetProcessingTask: drainsg_packetQueueand writes to all clients.- Global BLE mutex (
g_globalBluetoothMutex) ensures only one of scan/advertise runs at a time to keep the controller happy.
[Phone] ~ ~> [Node A] <==BLE==> [bitchat-relay (ESP32)] <==BLE==> [Node B] ~ ~> [Node C]
BitchatPacket.hpp— packet struct + types (ANNOUNCE,KEY_EXCHANGE, …)BitchatPacketSerializer—serialize()/deserialize()Generate25519key.hpp— currently used for the echo demo (mock key)main.cpp— scanning, advertising, client mgmt, notification callback, queue