BLE Protocol¶
The FlockFinder iOS app communicates with the ESP32-S3 device using Bluetooth Low Energy (BLE) GATT protocol. This document describes the communication protocol in detail.
Firmware Compatibility
This app is designed to work with flock-you, a fork with BLE GATT server support.
Service & Characteristics¶
Service UUID¶
The FlockFinder device advertises this custom service UUID. The iOS app scans for devices advertising this service.
Characteristics¶
| Characteristic | UUID | Properties | Description |
|---|---|---|---|
| Detection | beb5483e-36e1-4688-b7f5-ea07361b26a8 |
Notify | Surveillance camera detection alerts |
| Command | beb5483e-36e1-4688-b7f5-ea07361b26a9 |
Write | Send commands to device |
| Stream | beb5483e-36e1-4688-b7f5-ea07361b26aa |
Notify | Live scan data stream |
Device Discovery¶
The app scans for BLE devices matching these criteria:
- Service UUID - Devices advertising the FlockFinder service
- Name Patterns - Devices with names containing:
FlockFinderFlockFeatherESP32S3
Detection Data Format¶
When the ESP32 detects a surveillance camera, it sends a JSON payload via the Detection characteristic:
JSON Schema¶
{
"type": "Flock Safety",
"mac": "AA:BB:CC:DD:EE:FF",
"ssid": "FLOCK-CAM-001",
"rssi": -55,
"confidence": 0.95,
"ts": 123456789
}
Field Descriptions¶
| Field | Type | Required | Description |
|---|---|---|---|
type |
string | ✅ | Detection type (see Detection Types) |
mac |
string | ❌ | MAC address of detected device |
ssid |
string | ❌ | WiFi SSID if applicable |
rssi |
integer | ✅ | Signal strength in dBm |
confidence |
float | ✅ | Detection confidence (0.0 - 1.0) |
ts |
integer | ❌ | Unix timestamp from device |
Example Detections¶
Connection Flow¶
sequenceDiagram
participant App as iOS App
participant CM as CBCentralManager
participant Device as ESP32 Device
App->>CM: scanForPeripherals(withServices:)
CM->>App: didDiscover(peripheral:)
App->>CM: connect(peripheral:)
CM->>Device: BLE Connect
Device-->>CM: Connected
CM->>App: didConnect(peripheral:)
App->>Device: discoverServices()
Device-->>App: Services Discovered
App->>Device: discoverCharacteristics()
Device-->>App: Characteristics Discovered
App->>Device: setNotifyValue(true, for: detection)
loop Detection Events
Device-->>App: BLE Notification (JSON)
App->>App: Parse & Store Detection
end
Connection States¶
enum ConnectionState: String {
case disconnected = "Disconnected"
case scanning = "Scanning..."
case connecting = "Connecting..."
case connected = "Connected"
case discovering = "Discovering Services..."
case bluetoothOff = "Bluetooth Off"
case unauthorized = "Bluetooth Unauthorized"
}
Command Protocol¶
The app can send commands to the ESP32 via the Command characteristic:
| Command | Description |
|---|---|
PING |
Connection keep-alive |
STATUS |
Request device status |
RESET |
Reset detection counters |
Commands are sent as UTF-8 encoded strings:
func sendCommand(_ command: String) {
guard let data = command.data(using: .utf8),
let characteristic = commandCharacteristic else { return }
connectedDevice?.writeValue(data, for: characteristic, type: .withResponse)
}
Live Stream¶
The Stream characteristic provides real-time scan data for debugging:
- WiFi networks being scanned
- BLE devices in range
- Detection algorithm state
Enable the Debug Stream View in the app to see this data.
Signal Strength¶
RSSI values indicate proximity to detected devices:
| RSSI Range | Distance | Indication |
|---|---|---|
| -30 to -50 | Very close | < 2 meters |
| -50 to -70 | Close | 2-10 meters |
| -70 to -85 | Medium | 10-30 meters |
| -85 to -100 | Far | > 30 meters |
RSSI Accuracy
RSSI is affected by obstacles, interference, and antenna orientation. Use as a rough proximity indicator only.
Error Handling¶
The app handles common BLE errors:
| Error | Handling |
|---|---|
| Bluetooth Off | Show alert, guide to Settings |
| Connection Lost | Automatic reconnection attempts |
| Service Not Found | Display error, suggest firmware update |
| Parse Error | Log error, continue listening |
Firmware Compatibility¶
Ensure your ESP32 device is running compatible firmware:
The device should advertise as "FlockFinder-S3" when properly configured.