flowchart LR S1["1 Hello"] --> S2["2 Advertising"] --> S3["3 Notify"] --> S4["4 Commands"] --> S5["5 Pairing"] --> S6["6 Event-driven"]
Building Notify, commands and pairing with NimBLE, then restructuring as event-driven
flowchart LR S1["1 Hello"] --> S2["2 Advertising"] --> S3["3 Notify"] --> S4["4 Commands"] --> S5["5 Pairing"] --> S6["6 Event-driven"]
| Layer | Role | NimBLE |
|---|---|---|
| GAP | Discover, connect | ble_gap_*, BLE_GAP_EVENT_* |
| GATT | Services, characteristics | ble_gatt_svc_def |
| ATT | Read/write attributes (handles) | BLE_ATT_ERR_* |
| SM | Pairing, keys | ble_hs_cfg.sm_* |
| LL / PHY | Advertising, connections, encryption | Controller (binary) |
flowchart TB S["Service c0a60001-…"] --> C1["Counter<br/>Read / Notify"] S --> C2["Command<br/>Write / Notify"] C1 --> D1["CCCD 0x2902"] C2 --> D2["CCCD 0x2902"]
sync_cbble_gatts_notify_custom() are freed by NimBLECONFIG_BT_ENABLED=y etc. in sdkconfig.defaultssdkconfig already exists, defaults have no effect
sdkconfig and regenerate it*_ENC = encryption required, *_AUTHEN = key with MITM protection requiredNOTIFY_INDICATE_*, unpaired peers can subscribeflowchart LR
GAP["GAP"] -->|enqueue| Q[("Queue")]
GATT["GATT Write"] -->|enqueue| Q
TMR["esp_timer 1s"] -->|enqueue| Q
Q -->|dequeue| L["main loop"]
L --> T["table[state][event]"]
T --> H["Handler → next state"]
| State | CONNECTED | DISCONNECTED | CMD_PING | CMD_STATUS | TIMER_1S |
|---|---|---|---|---|---|
| IDLE | → CONNECTED | — | — | — | +1 |
| CONNECTED | — | → IDLE | PONG | status | +1, Notify |
NULL = ignore