feat(ble): Add support for LogRadio characteristic, enhance logs#3691
Merged
Conversation
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>
Codecov Report❌ Patch coverage is 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. |
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>
Contributor
There was a problem hiding this comment.
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
LogRadioBLE characteristic discovery and subscription for receiving device logs - Introduced
BleErrorsealed 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 |
b376ad9 to
9aa33ec
Compare
Signed-off-by: James Rich <2199651+jamesarich@users.noreply.github.com>
9aa33ec to
f52cd87
Compare
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
LogRecordconsumption. 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
BleErrorsealed class to provide more granular and structured error handling for Bluetooth Low Energy (BLE) operations, and refactors theNordicBleInterfaceto 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
logRadioCharacteristicand improved discovery logic to log all relevant BLE characteristics (toRadio,fromNum,fromRadio,logRadio) with device addresses for better traceability. [1] [2]NordicBleInterfaceto include device addresses, making debugging and diagnostics easier. [1] [2] [3]BLE Error Handling
BleErrorsealed class inBleError.ktto 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.NordicBleInterfaceto useBleErrorin all relevant disconnect and error scenarios, replacing boolean flags with detailed error objects and improving error propagation. [1] [2] [3]Code Cleanup and Refactoring