Skip to content

Fix NimBLE_Stream_Server NUS compatibility: use standard two-characteristic layout#1140

Draft
Copilot wants to merge 3 commits intomasterfrom
copilot/fix-nimble-stream-server-compatibility
Draft

Fix NimBLE_Stream_Server NUS compatibility: use standard two-characteristic layout#1140
Copilot wants to merge 3 commits intomasterfrom
copilot/fix-nimble-stream-server-compatibility

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 31, 2026

The NimBLE_Stream_Server example used NUS UUIDs but a single characteristic for both notify (TX) and write (RX), which is non-standard and breaks compatibility with NUS terminal apps (nRF UART, Serial Bluetooth Terminal, etc.). Standard NUS requires separate TX (6E400003, notify) and RX (6E400002, write) characteristics.

No library code was changed. The existing NimBLEStreamServer::begin(pChr) already activates only the directions supported by the characteristic's properties — a NOTIFY-only characteristic enables the TX buffer; a WRITE-only characteristic enables the RX buffer — making the two-characteristic NUS pattern achievable entirely in the examples.

Example updates

NimBLE_Stream_Server

  • Creates the NUS service and both characteristics manually
  • Uses two NimBLEStreamServer instances backed by the appropriate characteristic:
    • bleStreamTx.begin(pTxChar) — NOTIFY-only char → TX-only stream (sends notifications)
    • bleStreamRx.begin(pRxChar) — WRITE-only char → RX-only stream (receives client writes)
  • bleStreamTx.ready() tracks the subscribed client; bleStreamRx.available()/read() handles incoming data
NimBLECharacteristic* pTxChar = pSvc->createCharacteristic(TX_CHAR_UUID, NIMBLE_PROPERTY::NOTIFY);
NimBLECharacteristic* pRxChar = pSvc->createCharacteristic(RX_CHAR_UUID,
                                                           NIMBLE_PROPERTY::WRITE | NIMBLE_PROPERTY::WRITE_NR);
bleStreamTx.begin(pTxChar);
bleStreamRx.begin(pRxChar);

NimBLE_Stream_Client

  • One NimBLEStreamClient for TX: writes to the server's RX characteristic (6E400002, WRITE_NR)
  • Subscribes directly to the server's TX characteristic (6E400003) via pTxChar->subscribe() for RX, with an onServerNotify callback
bleStream.begin(pRxChar, false);           // TX: write to server's RX char
pTxChar->subscribe(true, onServerNotify);  // RX: receive notifications from server's TX char

NimBLE_Stream_Echo (custom UUIDs, single characteristic) is unchanged.

Copilot AI changed the title [WIP] Fix NimBLE_Stream_Server compatibility with NUS terminal software Add NUS two-characteristic support to NimBLEStream for terminal app compatibility Mar 31, 2026
Copilot AI requested a review from h2zero March 31, 2026 23:58
Copy link
Copy Markdown
Owner

@h2zero h2zero left a comment

Choose a reason for hiding this comment

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

This should be doable with only a change to the examples, no need for extra code in the class.

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 29, 2026

This should be doable with only a change to the examples, no need for extra code in the class.

Done in commit 64c5111 — no library changes at all. The existing begin(pChr) already activates only the directions the characteristic supports (NOTIFY → TX buffer, WRITE → RX buffer), so using two NimBLEStreamServer instances is all that's needed on the server side. The client uses one NimBLEStreamClient for TX and a direct pTxChar->subscribe() callback for RX.

Copilot AI changed the title Add NUS two-characteristic support to NimBLEStream for terminal app compatibility Fix NimBLE_Stream_Server NUS compatibility: use standard two-characteristic layout Apr 29, 2026
Copilot AI requested a review from h2zero April 29, 2026 19:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The new example, NimBLE_Stream_Server, is incompatible with some NUS terminal software.

2 participants