Skip to content

feat(rp2350w): add btstack BLE GATT transport #3861

Open

Description

@zackees

Context FastLED #3832 requires an RP2350W BLE audit. The selected Arduino-Pico 4.5.3 core ships BluetoothHCI, btstack, and CYW43 Bluetooth locking hooks. However, src/fl/net/ble.h defines FL_BLE_AVAILABLE only for ESP32 NimBLE, src/fl/net/ble.cpp.hpp returns stubs on RP2350W, and only the ESP32 BLE unity build supplies a transport. The core examples prove scanner/client-oriented BLE, while BluetoothHCI.cpp directly uses att_server_init, so a FastLED GATT server is implementable but not currently integrated. ## Proposal Add an RP2350W btstack-backed fl::net::ble GATT transport that implements the existing UUID and Remote callback contract. Add a platform dispatch/build fragment rather than changing the public API. Keep callback/main-loop handoff race-free with fl::atomic or an appropriate critical section, own all persistent FastLED state through fl::Singleton, and gate FL_BLE_AVAILABLE on the actual RP2350W Arduino-Pico headers and CYW43 support. ## Acceptance criteria - Add a focused RED compile/unit repro showing RP2350W currently selects the BLE stub, then make it green with the real RP transport. - Preserve ESP32 NimBLE behavior and unsupported-platform stubs. - Cover create/destroy, advertising, RX write to JSON-RPC request callback, TX notification, disconnect, and bounded queue-full behavior with tests. - No mutable static FastLED state outside fl::Singleton and no bare volatile cross-context state. - bash lint --cpp --strict plus target builds for rp2350w and esp32c6 pass. - Once COM17 is healthy/selectable, bash autoresearch rp2350w --ble --upload-port COM17 --timeout 120s records the actual GATT discovery/ping result. No one-off sketch or direct serial/flasher path. ## Open questions The core public BluetoothHCI examples emphasize scan/client use, so the first implementation must verify its direct btstack GATT-server lifecycle on the attached Pico 2 W and document the supported MTU/notification behavior. ## Related issues Parent #3832.

Activity

  1. zackees commented on Sep 7, 2026

    @zackees
    MemberAuthor

    The hardware clause on this issue is now unblocked.

    The bench fixture is confirmed a Raspberry Pi Pico 2 W — live evidence, not the historical record:

    2e8a:f00f  'Pico 2W'                                  # rpipico2w application CDC (2E8A:F00F)
    status     -> platform: "Raspberry Pi Pico 2 W (RP2350)"
    wifiStatus -> {"status":"IDLE","success":true}        # UNSUPPORTED on the non-W build
    

    Until now the variant was unestablished, so the W-only acceptance criteria here could not be attempted at all. They can be run now:

    • bash autoresearch rp2350w --rpc-smoke — PASS (71 RPC methods, dual-core concurrency 200/200)
    • bash autoresearch rp2350w --net-peer — deploys both boards; six full cycles of wifiConnect → join the C6 SoftAP → startNetServer → bidirectional HTTP → stopNet → ping

    Deploying the W build onto a board running non-W firmware needs --upload-port — fbuild refuses to guess which board to BOOTSEL and fails clean without flashing.

    One known blocker for long soaks: #4173 — the RP2350W hangs in wifiConnect on the 7th consecutive peer cycle and watchdog-resets. It self-recovers, so it limits repetition rather than stranding the fixture.

    Generated with Claude Code

    https://claude.ai/code/session_01KkufoNxfnNRU9psT3R9F51

  2. zackees commented on Sep 7, 2026

    @zackees
    MemberAuthor

    Device side works — the RP2350W btstack GATT server starts and advertises

    The precondition on this issue's last criterion ("Once COM17 is healthy/selectable, bash autoresearch rp2350w --ble ...") is now met: the fixture is confirmed a Pico 2 W (2E8A:F00F, status.platform "Raspberry Pi Pico 2 W (RP2350)") and its port is healthy and openable. Ran it:

    --- Step 1: Connect to device on /dev/ttyACM1 (serial) ---
    --- Step 2: Start BLE GATT server ---
      BLE started: name=FastLED-C6, service=12345678-1234-1234-1234-123456789abc
    --- Step 3: Connect to 'FastLED-C6' via BLE ---
      BLE autoresearch error: [org.freedesktop.DBus.Error.ServiceUnknown] The name is not activatable
    

    The deploy went to /dev/ttyACM1 and Step 1 connected there, so startBle was answered by the RP2350W, not the C6. It returned a live service UUID and advertising name — the btstack transport from #3863 comes up on real silicon.

    The failure is host-side, not the board

    bleak could not reach BlueZ:

    $ systemctl is-active bluetooth
    inactive
    $ ls /sys/class/bluetooth/
    hci0
    

    The adapter exists (hci0, a BCM20702 on USB) but bluetoothd is not running and bluetoothctl is not installed. On NixOS that is declarative — hardware.bluetooth.enable = true plus a rebuild — so it needs the bench owner, not an agent. Nothing about the RP2350W is implicated.

    Remaining for this issue is therefore only the host BLE central: GATT discovery, the RX write → JSON-RPC request path, and TX notification still need a working BlueZ to be observed end to end.

    Two cosmetic issues that cost time here

    1. ci/autoresearch/ble.py:69 prints "Start BLE GATT server on ESP32" regardless of target. It sends startBle over whatever serial client is connected, so on --ble --upload-port <rp2350w> the label names the wrong chip. I read it as "the test ignored my port and used the C6" before checking the deploy line.
    2. AUTORESEARCH_BLE_DEVICE_NAME is hardcoded "FastLED-C6" (examples/AutoResearch/AutoResearchBle.h:19), so an RP2350W advertises under a C6 name. Harmless functionally, but it makes a scan log actively misleading about which board answered.

    Both are worth a small follow-up; neither affects the transport.

    Generated with Claude Code

    https://claude.ai/code/session_01KkufoNxfnNRU9psT3R9F51

  3. zackees commented on Sep 8, 2026

    @zackees
    MemberAuthor

    Device-side btstack GATT transport verified on hardware. Host BlueZ is inactive here so the Bleak half of --ble cannot run, but startBle / bleStatus / stopBle travel over serial and exercise the RP2350W's GATT server independently of the host stack.

    RP2350W 2DCB876B587EA334 on /dev/ttyACM0, full lifecycle with cleanup in a finally:

    before   : {'ble_active': False, 'tx_char_exists': False, 'connected': False,
                'ring_head': 0, 'ring_tail': 0, 'tx_value_len': 0, 'connected_count': 0}
    
    startBle : {'success': True,
                'device_name':  'FastLED-RP2350',
                'service_uuid': '12345678-1234-1234-1234-123456789abc',
                'rx_uuid':      '12345678-1234-1234-1234-123456789ab0',
                'tx_uuid':      '12345678-1234-1234-1234-123456789ab1'}
    
    after    : {'ble_active': True,  'tx_char_exists': True,  ...}
    
    stopBle  : {'success': True}
    final    : {'ble_active': False, 'tx_char_exists': False, ...}
    ping     : {'message': 'pong', 'success': True, 'uptimeMs': 3647480,
                'lastResetCause': 'SOFTWARE', 'lastResetWasWatchdog': False}
    

    What this establishes:

    • The btstack GATT server initializes on the CYW43 and reports a complete service definition — device name plus service/RX/TX UUIDs.
    • tx_char_exists transitions False -> True -> False across start/stop, so the TX characteristic is really registered and really torn down; ble_active tracks it.
    • Teardown is clean. Every field returns to its pre-start value, and the board survives the cycle without a watchdog reset (lastResetWasWatchdog: False, uptime continuous across the sequence at 3647s — no reboot).

    What it does not establish: nothing connected. connected, connected_count, ring_head, ring_tail and tx_value_len all stay at zero throughout, so no notification actually traversed the link. The GATT server exists and advertises; whether a central can connect, subscribe and receive notifications is untested.

    That connect/subscribe/notify half needs host BlueZ. hci0 is present in /sys/class/bluetooth/ but systemctl is-active bluetooth reports inactive, bluetoothctl is not installed, and this account has no root or passwordless sudo to start the service — so it needs the NixOS declarative config change, not something I can arrange from here.

    Relevant to #3955 (BLE notification lifecycle): the ring buffer counters and tx_value_len are exposed in bleStatus and observably start at zero and stay there with no central attached, which is the correct idle state. Exercising the notification path itself is blocked behind the same host-BlueZ gap.

  4. zackees commented on Sep 11, 2026

    @zackees
    MemberAuthor

    Live device-side proof: the btstack GATT transport does come up on RP2350W

    I had recorded BLE as untestable on this bench because bash autoresearch rp2350w --ble dies host-side — org.freedesktop.DBus.Error.ServiceUnknown, BlueZ userspace absent so bleak has no org.bluez. That was wrong as a blanket statement: only the host-central role is blocked. The device half is reachable over serial RPC, and this issue's outstanding item is live proof of the transport.

    Driving startBle / bleStatus / stopBle directly through the fbuild-backed RpcClient (no BlueZ involved), on RP2350W 2DCB876B587EA334, master:

    before:   {"ble_active": false, "tx_char_exists": false, "connected": false, "connected_count": 0,
               "tx_value_len": 0, "ring_head": 0, "ring_tail": 0}
    
    startBle: {"success": true,
               "device_name":  "FastLED-RP2350",
               "service_uuid": "12345678-1234-1234-1234-123456789abc",
               "rx_uuid":      "12345678-1234-1234-1234-123456789ab0",
               "tx_uuid":      "12345678-1234-1234-1234-123456789ab1"}
    
    after:    {"ble_active": true,  "tx_char_exists": true,  "connected": false, "connected_count": 0,
               "tx_value_len": 0, "ring_head": 0, "ring_tail": 0}
    
    stopBle:  {"success": true}
    

    Reproduced twice, identical. Serial RPC smoke passes afterwards, so the stack starting and stopping does not disturb the control plane.

    What this proves

    • btstack initialises on RP2350W and createTransport returns a real transport rather than the stub — startBle returns the advertised identity instead of the stub's failure
    • a GATT service is created with the expected service and characteristic UUIDs
    • tx_char_exists transitions false → true, which is the substantive bit: the TX characteristic is actually registered on the GATT database, not merely a flag being set
    • teardown is clean and repeatable

    What this does not prove

    connected: false and connected_count: 0 throughout, because nothing ever connects. Untested, and untestable here: central discovery/connect, subscription to the TX characteristic, notification delivery, and the notification lifecycle in #3955. Those need a host acting as a BLE central.

    The blocker for that is bench provisioning, not firmware: the adapter is present (/sys/class/bluetooth/hci0) but systemctl is-active bluetooth reports inactive and bluetooth.service could not be found. Installing BlueZ and enabling the service would unblock the remaining criteria; it needs root, so I have not done it unattended. Recorded against #3714.

    So this issue's transport question is answered affirmatively on live hardware; what remains is the connected-peer half.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions