Skip to content

add FromRadioSync BLE characteristic#9675

Draft
jamesarich wants to merge 5 commits intomeshtastic:developfrom
jamesarich:feat/from_radio_sync
Draft

add FromRadioSync BLE characteristic#9675
jamesarich wants to merge 5 commits intomeshtastic:developfrom
jamesarich:feat/from_radio_sync

Conversation

@jamesarich
Copy link
Copy Markdown

This pull request introduces a new Bluetooth characteristic, FROMRADIOSYNC, to enable data transfer via BLE indications. This provides an alternative to the existing notification-based mechanism, allowing clients to choose between notifications and indications for receiving data. The changes ensure that data is sent through the appropriate characteristic based on client subscriptions, and update both NimBLE and nRF52 Bluetooth implementations to support the new characteristic.

Bluetooth Characteristic Additions and Updates:

  • Added the FROMRADIOSYNC_UUID definition and corresponding 16-byte array for use as a BLE characteristic UUID in both header and source files. [1] [2]
  • Declared and initialized the fromRadioSyncCharacteristic (NimBLE) and fromRadioSync (nRF52) BLE characteristic objects in their respective codebases. [1] [2]

BLE Service Setup and Permissions:

  • Registered the FROMRADIOSYNC characteristic with INDICATE and READ properties in both NimBLE and nRF52 BLE service setup routines, including appropriate permissions and maximum length. [1] [2] [3]

Data Sending Logic:

  • Updated the onNowHasData method in both NimBLE and nRF52 implementations to prioritize sending data via the FROMRADIOSYNC characteristic if indications are enabled, draining the queue and avoiding duplicate sends to the legacy notification characteristic. [1] [2]

CCCD (Client Characteristic Configuration Descriptor) Handling:

  • Modified CCCD handling to support enabling/disabling indications for the new FROMRADIOSYNC characteristic, alongside existing characteristics.

@github-actions
Copy link
Copy Markdown
Contributor

@jamesarich, Welcome to Meshtastic!

Thanks for opening your first pull request. We really appreciate it.

We discuss work as a team in discord, please join us in the #firmware channel.
There's a big backlog of patches at the moment. If you have time,
please help us with some code review and testing of other PRs!

Welcome to the team 😄

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new BLE characteristic (FROMRADIOSYNC) intended to let clients receive FromRadio payloads via indications (instead of the legacy notification-driven “fromNum + read FromRadio” flow), with support in both NimBLE (ESP32) and Bluefruit (nRF52).

Changes:

  • Introduces FROMRADIOSYNC UUID definitions (string + nRF52 byte-array form).
  • Registers a new FROMRADIOSYNC characteristic in NimBLE and nRF52 GATT services with INDICATE (+ READ) properties.
  • Updates BLE send logic to prefer sending FromRadio via indications when the new characteristic is subscribed.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
src/platform/nrf52/NRF52Bluetooth.cpp Adds fromRadioSync characteristic and indication-based drain/send behavior; updates CCCD handling.
src/nimble/NimbleBluetooth.cpp Adds fromRadioSyncCharacteristic, registers it in the GATT service, and adds indication-based send path.
src/BluetoothCommon.h Adds FROMRADIOSYNC_UUID and declares FROMRADIOSYNC_UUID_16.
src/BluetoothCommon.cpp Defines FROMRADIOSYNC_UUID_16 byte array for nRF52.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

Comment on lines +318 to +326
// Check if FromRadioSync is subscribed (indications enabled)
// If so, we push the data directly via indication and consume it from the queue
if (fromRadioSyncCharacteristic->getSubscribedCount() > 0) {
uint8_t fromRadioBytes[meshtastic_FromRadio_size];
// Loop until queue is empty or we fail to send
while (true) {
// Peek at the request to see if we have data, but we need to dequeue to send.
// getFromRadio dequeues.
size_t numBytes = getFromRadio(fromRadioBytes);
Copy link

Copilot AI Feb 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

onNowHasData() now calls getFromRadio() to send indications. However PhoneAPI::getFromRadio() can synchronously invoke onNowHasData() during certain state transitions, which makes this re-entrant and can recursively call back into this method. That can cause deep recursion and unpredictable state progression. Consider moving indication sending out of onNowHasData() (e.g., queue work for the BLE thread/run loop) or add a reentrancy guard and only emit a single indication per trigger.

Copilot uses AI. Check for mistakes.
@jamesarich
Copy link
Copy Markdown
Author

jamesarich commented Feb 17, 2026

Overall this is working with the Android counterpart meshtastic/Meshtastic-Android#4584

Some things to note during testing:

  • nimble

    • needed to erase flash in order to add a new characteristic to the GATT database
    • updating w/o erasing prior caused crash:
      Crash site: populate_db_from_nvs (NimBLE/NVS restore) triggered during NimbleBluetooth::setup().
      Likely cause: Corrupted/invalid BLE NVS state after the GATT database change (adding FromRadioSync)
  • nrf52

    • needed to forget/rebond on phone in order for characteristic to populate:
      [DB:15:70:C8:F3:F3] Found fromRadioSync: null, null
      [DB:15:70:C8:F3:F3] Found fromRadioSync: 888a50c3-982d-45db-9963-c7923769165d, 42

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants