Skip to content

About

An ESP-based bitchat node to extend network size

Resources

Stars

13 stars

Watchers

2 watching

Forks

Latest commit

 

History

3 Commits

Folders and files

Repository files navigation

bitchat-relay

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.

Status: MVP relay (BLE-only)

  • ✅ 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)

How it works

GATT UUIDs

  • Service: F47B5E2D-4A9E-4C5A-9B3F-8E1D2C3A4B5C
  • Characteristic: A1B2C3D4-E5F6-4A5B-8C9D-0E1F2A3B4C5D (notify / write)

Core flow

  1. Advertise a BitChat service and accept inbound connections.
  2. Scan for other advertisers; when found, connect as a client and subscribe to notifications.
  3. On notification, deserialize payload → BitchatPacket.
  4. Handle packet types:
    • KEY_EXCHANGE: reply with mock combined public key; then send self ANNOUNCE.
    • ANNOUNCE: log/ack (hook for future routing/neighbor table).
  5. Enqueue response/announce packets; broadcast to all connected peers.

Concurrency model

  • xScanForPeersTask: active scan (5s), enqueue connect targets.
  • xAdvertiseBLEServerTask: advertise in 10s on / 5s off duty cycle.
  • packetProcessingTask: drains g_packetQueue and writes to all clients.
  • Global BLE mutex (g_globalBluetoothMutex) ensures only one of scan/advertise runs at a time to keep the controller happy.

Topology (concept)

[Phone] ~ ~> [Node A] <==BLE==> [bitchat-relay (ESP32)] <==BLE==> [Node B] ~ ~> [Node C]


Repo layout (key pieces)

  • 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

About

An ESP-based bitchat node to extend network size

Resources

Stars

13 stars

Watchers

2 watching

Forks

Releases

Packages

Contributors

Languages