Skip to content

Conversation

@sensei-hacker
Copy link
Member

@sensei-hacker sensei-hacker commented Jan 28, 2026

User description

Summary

Fixes BLE connection byte counter always showing 0, which also caused MSP request timeouts over BLE.

See #2538

Root Cause

In 8.0.0, Connection.addOnReceiveListener() called both _onReceiveListeners.push() AND addOnReceiveCallback(), which registered the byte counter callback in BLE's separate listener array. In 9.0.0 this was changed to only push to _onReceiveListeners (to avoid duplication in Serial/TCP/UDP which share the same array). BLE was the only connection type with a separate array, so it silently lost the byte counter callback.

Changes

  • Removed BLE's separate _onCharateristicValueChangedListeners array
  • Changed addOnReceiveCallback() and removeOnReceiveCallback() to use the base class _onReceiveListeners array, matching the pattern Serial already uses
  • Notification handler now dispatches to _onReceiveListeners directly

Testing

  • Could not test with BLE hardware (none available in this environment)
  • Code review performed with inav-code-review agent — no critical issues
  • Logic verified against Serial connection implementation which uses the same pattern
  • Requesting testing from someone with BLE hardware (e.g. SpeedyBee or Nordic NRF adapter)

Note on Debug Logging

This PR intentionally includes temporary [BLE FIX] console.log statements (4 total, marked with TODO comments) to help verify the fix when tested with real BLE hardware. These should be removed in a follow-up once the fix is confirmed working.


PR Type

Bug fix


Description

  • Fixes BLE byte counter regression showing zero bytes received

  • Aligns BLE connection with Serial pattern using shared listener array

  • Removes BLE-specific characteristic listener array causing callback loss

  • Adds temporary debug logging to verify fix with BLE hardware


Diagram Walkthrough

flowchart LR
  A["BLE Notification Handler"] -->|"dispatch to"| B["_onReceiveListeners array"]
  B -->|"calls"| C["Byte Counter Callback"]
  C -->|"increments"| D["_bytesReceived counter"]
  B -->|"calls"| E["MSP Parser Callback"]
  E -->|"processes"| F["MSP Responses"]
Loading

File Walkthrough

Relevant files
Bug fix
connectionBle.js
Align BLE listener pattern with Serial implementation       

js/connection/connectionBle.js

  • Removed _onCharateristicValueChangedListeners array from constructor
  • Changed addOnReceiveCallback() to push to _onReceiveListeners instead
    of BLE-specific array
  • Updated removeOnReceiveCallback() to filter _onReceiveListeners
    instead of BLE-specific array
  • Modified notification handler to dispatch to _onReceiveListeners
    directly with debug logging
  • Added four temporary [BLE FIX] console.log statements marked with TODO
    for removal after testing
+18/-8   

In 8.0.0, addOnReceiveListener() called addOnReceiveCallback() which
registered callbacks in both _onReceiveListeners and the BLE-specific
_onCharateristicValueChangedListeners array. In 9.0.0 this was removed
to "avoid duplicate push", but Serial's addOnReceiveCallback() pushes
to _onReceiveListeners while BLE's pushes to its own separate array.

This meant the byte counter listener (added via addOnReceiveListener)
only went into _onReceiveListeners, but BLE's notification handler only
called _onCharateristicValueChangedListeners - so the counter never
incremented and MSP responses were never seen by the parser.

Fix: align BLE with Serial by using _onReceiveListeners throughout,
removing the now-unnecessary _onCharateristicValueChangedListeners array.
Includes debug logging to aid diagnosis if further issues arise.
@qodo-code-review
Copy link
Contributor

qodo-code-review bot commented Jan 28, 2026

ⓘ Your approaching your monthly quota for Qodo. Upgrade your plan

PR Compliance Guide 🔍

All compliance sections have been disabled in the configurations.

@sensei-hacker sensei-hacker changed the title Fix BLE byte counter regression introduced in 9.0.0 Fix BLE byte counter regression introduced in 9.0.0 - testing needed Jan 28, 2026
@sensei-hacker sensei-hacker changed the title Fix BLE byte counter regression introduced in 9.0.0 - testing needed Fix BLE byte counter regression introduced in 9.0.0 Jan 30, 2026
User confirmed BLE connection is working correctly after the byte
counter fix, but reported slower performance compared to 8.0.1.

Analysis showed 4 console.log() statements in the data path:
- 2 logs on every BLE notification received (hot path)
- 2 logs during listener add/remove (cold path)

The hot path logs were causing performance degradation as they
execute on every 20-byte BLE packet received. Removed all 4
debug logs as they were marked TODO for removal after testing.

The core fix (using _onReceiveListeners array) remains intact.
@sensei-hacker sensei-hacker merged commit 1a85fc5 into iNavFlight:maintenance-9.x Jan 30, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant