Skip to content

feat(ble): Add support for LogRadio characteristic, enhance logs#3691

Merged
jamesarich merged 4 commits into
meshtastic:mainfrom
jamesarich:feat/log-radio
Nov 13, 2025
Merged

feat(ble): Add support for LogRadio characteristic, enhance logs#3691
jamesarich merged 4 commits into
meshtastic:mainfrom
jamesarich:feat/log-radio

Conversation

@jamesarich

@jamesarich jamesarich commented Nov 13, 2025

Copy link
Copy Markdown
Collaborator

Adds LogRecord BLE characteristic, improve BLE logging and error handling.

Addresses part of #1110 - I've not seen this working yet for TCP or Serial connections, only BLE (via the characteristic). Introduces new LogRecord consumption. When enabled via Security -> Debug log API Enabled (and supported by device/fw) this allows the app to consume device logs sent on the LOG_RADIO BLE characteristic. These logs are displayed in Android logcat debug loging and the in-app Debug Panel.

Note that this can be noisy, and inflate your app packet database greatly - so it is not recommended to keep enabled when not debugging.

Introduces a new BleError sealed class to provide more granular and structured error handling for Bluetooth Low Energy (BLE) operations, and refactors the NordicBleInterface to use this new error model. Additionally, it improves diagnostic logging, enhances characteristic discovery, and updates the Detekt baseline to reflect these changes.

Key changes:

BLE Characteristic Discovery and Logging

  • Added support for the logRadioCharacteristic and improved discovery logic to log all relevant BLE characteristics (toRadio, fromNum, fromRadio, logRadio) with device addresses for better traceability. [1] [2]
  • Enhanced log messages throughout NordicBleInterface to include device addresses, making debugging and diagnostics easier. [1] [2] [3]
Screenshot_20251113_130611

BLE Error Handling

  • Introduced a new BleError sealed class in BleError.kt to model specific BLE failures, enabling more precise error handling and intelligent reconnection strategies. This class includes factory logic to map exceptions to error types and indicates whether a reconnect should be attempted.
  • Refactored NordicBleInterface to use BleError in all relevant disconnect and error scenarios, replacing boolean flags with detailed error objects and improving error propagation. [1] [2] [3]

Code Cleanup and Refactoring

  • Simplified packet queue handling by renaming and clarifying flow methods, and improved coroutine usage and error handling in packet dispatching.

This commit introduces support for the new `LogRadio` BLE characteristic, which provides a dedicated channel for device logs. It also refactors logging for incoming packets to be more structured and less verbose.

- A new `BTM_LOGRADIO_CHARACTER` UUID has been added.
- `NordicBleInterface` now discovers and subscribes to the `LogRadio` characteristic, dispatching received data.
- Logging for incoming `FromRadio` packets in `MeshService` is now more structured, logging a one-line summary of the parsed protobuf.
- `onReceiveFromRadio` in `MeshService` now attempts to parse incoming data as a `LogRecord` if parsing as a `FromRadio` message fails.
- Redundant verbose byte-array logging in `RadioInterfaceService` has been removed.
- The `WANT_CONFIG_DELAY` has been increased to 100ms.

Signed-off-by: James Rich <2199651+jamesarich@users.noreply.github.com>
This commit introduces a structured `BleError` sealed class to provide more granular and specific feedback on BLE failures, modeled after the iOS implementation. This allows for more intelligent reconnection strategies based on the type of error encountered.

Key changes include:
- Added `BleError.kt` to define specific BLE failure types, each with a `shouldReconnect` flag.
- Integrated `BleError` handling into `NordicBleInterface` and `RadioInterfaceService` to report connection errors and trigger disconnections with appropriate context.
- Refactored `NordicBleInterface` for cleaner logic, improved error catching, and more concise logging.
- Enhanced logging across `MeshService` by adding contextual tags (e.g., `[myInfo]`, `[nodeInfo]`) and removing redundant log messages to improve debuggability.
- Increased the `WANT_CONFIG_DELAY` to 250ms to provide more time for the connection to stabilize before requesting second configuration.

Signed-off-by: James Rich <2199651+jamesarich@users.noreply.github.com>
@github-actions github-actions Bot added the enhancement New feature or request label Nov 13, 2025
@codecov

codecov Bot commented Nov 13, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 172 lines in your changes missing coverage. Please review.
✅ Project coverage is 0.51%. Comparing base (ac5412b) to head (f52cd87).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
...sville/mesh/repository/radio/NordicBleInterface.kt 0.00% 62 Missing ⚠️
...in/java/com/geeksville/mesh/service/MeshService.kt 0.00% 54 Missing ⚠️
...a/com/geeksville/mesh/repository/radio/BleError.kt 0.00% 44 Missing ⚠️
...lle/mesh/repository/radio/RadioInterfaceService.kt 0.00% 4 Missing ⚠️
...otlin/org/meshtastic/core/model/util/Extensions.kt 0.00% 4 Missing ⚠️
.../java/com/geeksville/mesh/service/PacketHandler.kt 0.00% 2 Missing ⚠️
...m/geeksville/mesh/service/MeshServiceBroadcasts.kt 0.00% 1 Missing ⚠️
...astic/feature/settings/debugging/DebugViewModel.kt 0.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##            main   #3691      +/-   ##
========================================
- Coverage   0.51%   0.51%   -0.01%     
========================================
  Files        376     377       +1     
  Lines      21214   21298      +84     
  Branches    2556    2580      +24     
========================================
  Hits         109     109              
- Misses     21085   21169      +84     
  Partials      20      20              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Adds support for displaying the full `LogRecord` message from the device in the debug log. This also removes unnecessary line breaks from the output and enables soft wrapping for better readability of long log messages.

Signed-off-by: James Rich <2199651+jamesarich@users.noreply.github.com>
@jamesarich jamesarich marked this pull request as ready for review November 13, 2025 19:07
@jamesarich jamesarich requested a review from Copilot November 13, 2025 19:07
@jamesarich jamesarich changed the title feat(ble): Add support for new LogRadio characteristic feat(ble): Add support for LogRadio characteristic, enhance logs Nov 13, 2025

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds support for a new LogRadio BLE characteristic to receive log records directly from Meshtastic devices via Bluetooth. It also introduces structured error handling through a new BleError sealed class and improves diagnostic logging throughout the BLE stack.

Key changes:

  • Added LogRadio BLE characteristic discovery and subscription for receiving device logs
  • Introduced BleError sealed class for granular BLE error handling with intelligent reconnection strategies
  • Enhanced logging with device addresses for better traceability in BLE operations
  • Improved packet parsing with fallback to LogRecord parsing when FromRadio fails

Reviewed Changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
BleError.kt New sealed class modeling BLE errors with reconnection strategies
NordicBleInterface.kt Added LogRadio characteristic support, improved error handling with BleError, enhanced logging with device addresses
RadioInterfaceService.kt Added connectionError flow, new onDisconnect overload accepting BleError, exposed radioIf as read-only
MeshService.kt Refactored packet parsing with LogRecord fallback, increased WANT_CONFIG_DELAY, enhanced logging consistency, reordered initialization in onHasSettings
PacketHandler.kt Improved error logging format with exception-first parameter
MeshServiceBroadcasts.kt Added PII string handling for node change broadcasts
DebugViewModel.kt Added LogRecord message annotation with string replacement
Debug.kt Removed softWrap=false to allow text wrapping in debug view
GooglePlatformAnalytics.kt Commented out Datadog and Crashlytics initialization (debug-only)
detekt-baseline.xml Updated baseline for new code complexity and removed obsolete entries

Comment thread app/src/main/java/com/geeksville/mesh/service/MeshService.kt
Comment thread app/src/main/java/com/geeksville/mesh/service/MeshService.kt
Comment thread app/src/main/java/com/geeksville/mesh/repository/radio/RadioInterfaceService.kt Outdated
Signed-off-by: James Rich <2199651+jamesarich@users.noreply.github.com>
@jamesarich jamesarich added this pull request to the merge queue Nov 13, 2025
Merged via the queue into meshtastic:main with commit 6590ea0 Nov 13, 2025
8 checks passed
@jamesarich jamesarich deleted the feat/log-radio branch November 13, 2025 20:02
mdecourcy pushed a commit to mdecourcy/Meshtastic-Android that referenced this pull request Nov 14, 2025
…htastic#3691)

Signed-off-by: James Rich <2199651+jamesarich@users.noreply.github.com>
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.

2 participants