Skip to content

Fix NimbleBluetooth: process fromPhoneQueue (phone->radio) before toPhoneQueue (radio->phone)#8404

Merged
thebentern merged 4 commits into
meshtastic:developfrom
compumike:compumike/fix-nimble-bluetooth-process-fromPhone-before-toPhone
Oct 20, 2025
Merged

Fix NimbleBluetooth: process fromPhoneQueue (phone->radio) before toPhoneQueue (radio->phone)#8404
thebentern merged 4 commits into
meshtastic:developfrom
compumike:compumike/fix-nimble-bluetooth-process-fromPhone-before-toPhone

Conversation

@compumike

Copy link
Copy Markdown
Contributor

Fix for the issue in #8385 (comment) where commit 099ab06 breaks the iOS client (especially if trying to connect within the first 10 seconds after boot, it seems).

As @garthvh pointed out, the clients expect to do a write-then-read when sending wantConfig. The read should block until the write is processed. So this switches the processing order and means that onRead (toPhoneQueue) will block until all onWrite (fromPhoneQueue) packets have been processed!

This fixes the iOS client, and simplifies the NimbleBluetooth code significantly! 👏

I've only tested on NimBLE 1. (I'm still fighting to get NIBMLE_TWO running locally...)

Would appreciate testing especially from:

  • android app
  • NIMBLE_TWO

🤝 Attestations

  • I have tested that my proposed changes behave as described.
  • I have tested that my proposed changes do not cause any obvious regressions on the following devices:
    • Heltec (Lora32) V3

@compumike

Copy link
Copy Markdown
Contributor Author

OK, I was able to test this PR successfully with NIMBLE_TWO with a Heltec V3. All good with iOS client 👍

Here is what I had to do to get NIMBLE_TWO working on the heltec-v3 platform: https://gist.github.com/compumike/75b87fd7e2f2399198c270be42c337b4 -- thanks @Links2004

Without the changes to NimbleBluetooth.cpp proposed in #7880 https://github.com/meshtastic/firmware/pull/7880/files#diff-228810058710e46189de098dbd92bba5cd367ad8b49b20d2efc2b202b258b766 I can't get it to compile: src/nimble/NimbleBluetooth.cpp:783:30: error: 'getClientByHandle' is not a member of 'NimBLEDevice'. So I don't know how y'all are managing to test it on NIMBLE_TWO without these changes!

@compumike

Copy link
Copy Markdown
Contributor Author

#8404 (This PR) works for me without NIMBLE_TWO, but fails to build with NIMBLE_TWO with src/nimble/NimbleBluetooth.cpp:783:30: error: 'getClientByHandle' is not a member of 'NimBLEDevice'.

#8405 (This PR + one extra commit) works for me with OR without NIMBLE_TWO. The one extra commit is 524d287 which are the changes from @Links2004 #7880 to NimbleBluetooth.cpp.


I think this PR (#8404) is safe and good to merge, and fixes the iOS client issue, and should be compatible with the Android one too. <-- if possible, I wouldn't wait on merging this one, because the current behavior is broken on iOS. 🙏

I'm less sure about #8405 because I don't have a C6L to test with. Maybe @Links2004 can take a peek too?

@compumike

compumike commented Oct 19, 2025

Copy link
Copy Markdown
Contributor Author

Update: This PR works as-is both with OR without NIMBLE_TWO on my heltec-v3 with the iOS app. (Never mind the above comments about #8405; that can be dealt with separately in #7880!)

I made a more minimal guide to using NIMBLE_TWO with heltec-v3: https://gist.github.com/compumike/64cd0384b66c540364254679e2c55fc7 . Compared to my earlier version, by skipping -DCONFIG_BT_NIMBLE_ROLE_CENTRAL_DISABLED, the rest of NimbleBluetooth.cpp seems to work fine for now!


I have tested this PR #8404 with:

  • heltec-v3
    • (default) without NIMBLE_TWO
      • ✅ iOS client BLE: works great
      • ✅ web client BLE: works great
    • -DNIMBLE_TWO per minimal gist
      • ✅ iOS client BLE: works great
      • ✅ web client BLE: works great
  • m5stack_unitc6l
    • ✅ builds cleanly (I do not have hardware to test with 🤷 )

@fifieldt fifieldt added the enhancement New feature or request label Oct 19, 2025
@HarukiToreda

Copy link
Copy Markdown
Contributor

tested on a Heltec V3 on powersave mode, node reconnects perfectly every time bluetooth wakes up from sleep with no issues.

@thebentern thebentern merged commit 871986d into meshtastic:develop Oct 20, 2025
5 of 64 checks passed
jeek pushed a commit to jeek/Meshtastic-Exploiteers-Hacker-Pager that referenced this pull request Jun 30, 2026
…e-bluetooth-process-fromPhone-before-toPhone

Fix NimbleBluetooth: process fromPhoneQueue (phone->radio) before toPhoneQueue (radio->phone)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants