Skip to content

Conversation

@the-eric-kwok
Copy link
Contributor

@the-eric-kwok the-eric-kwok commented Dec 17, 2025

This PR resolves issue #195 .


Note

Adds cross-platform readRssi surface with native support on Android and iOS/macOS.

  • Introduces readRssi(deviceId) to platform interface and generated Pigeon channels (UniversalBlePlatformChannel) across Android/Darwin/Windows glue
  • Android: implements readRssi via BluetoothGatt.readRemoteRssi() with result tracking and error handling; cleans up pending futures on disconnect
  • iOS/macOS: implements readRssi using CBPeripheral.readRSSI() and didReadRSSI delegate; integrates with existing futures cleanup
  • Windows/Linux/Web: stubbed as not implemented with consistent UniversalBleException
  • Dart API: exposes UniversalBle.readRssi(deviceId) and BleDevice.readRssi(); updates platform interface, pigeon channel, and mock/test implementations
  • Example app: adds "Get RSSI" action in peripheral_detail_page.dart
  • Docs: updates README and Low-Level API with "Reading RSSI" section and API support table; minor README formatting fix

Written by Cursor Bugbot for commit cd051db. This will update automatically on new commits. Configure here.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @the-eric-kwok, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request implements the readRssi feature across supported platforms, specifically Android and Darwin (iOS/macOS), to allow users to query the signal strength of connected BLE devices. This enhancement directly addresses issue #195, providing a crucial capability for monitoring device proximity and connection quality. The changes include core platform implementations, API exposure, and comprehensive documentation.

Highlights

  • New readRssi Method: Introduced a new readRssi method to retrieve the signal strength (RSSI) of a connected Bluetooth Low Energy device.
  • Platform Support: The readRssi functionality is fully supported on Android, iOS, and macOS. It is explicitly marked as not supported on Windows, Linux, and Web platforms.
  • Documentation Updates: The main README.md and README.low_level.md files have been updated to include documentation for the new readRssi method, its usage, and platform limitations.
  • Example App Integration: The example application has been updated with a 'Get RSSI' button to demonstrate the new functionality in action.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request successfully implements the readRssi functionality for Android and Darwin platforms, while correctly providing 'not implemented' stubs for Windows, Linux, and Web. The changes are comprehensive, including updates to the public API, documentation, example application, and tests. The implementation across different platforms is consistent and well-structured. I have one suggestion for improvement in the Android implementation to enhance code clarity and efficiency.

@DGuang21
Copy link

relation:

#195

Copy link
Contributor

@fotiDim fotiDim left a comment

Choose a reason for hiding this comment

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

Thanks for the PR. Added some first comments. This won't probably make it for the 1.0 release which is due soon if it doesn't support all possible platforms.

| enable/disable Bluetooth | ✔️ ||| ✔️ | ✔️ ||
| onAvailabilityChange | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ |
| requestMtu | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ ||
| readRssi | ✔️ | ✔️ | ✔️ ||||
Copy link
Contributor

Choose a reason for hiding this comment

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

@the-eric-kwok the platforms that are marked as ❌ do they not support reading RSSI at all or are they just not implemented? If they can support it please mark them as 🚧

Copy link
Contributor Author

@the-eric-kwok the-eric-kwok Dec 18, 2025

Choose a reason for hiding this comment

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

@fotiDim As far as I know, they are not supportable. On these platform you can only read RSSI in device discovery phase. Not after they are connected.

See:

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Linux can be done in a separate PR. Merging...

Copy link
Contributor

Copilot AI left a comment

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 implements the readRssi functionality for Android and Darwin (iOS/macOS) platforms to read the signal strength (RSSI) of connected BLE devices, resolving issue #195.

  • Adds platform-specific implementations for Android (Kotlin) and Darwin (Swift) to read RSSI values
  • Implements proper error handling and future-based callbacks for asynchronous RSSI reading
  • Adds stub implementations for unsupported platforms (Windows, Linux, Web) that return "not implemented" errors

Reviewed changes

Copilot reviewed 21 out of 23 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
pigeon/universal_ble.dart Adds readRssi method definition to platform channel interface
lib/src/universal_ble_pigeon/universal_ble.g.dart Generated Dart platform channel code for readRssi method
lib/src/universal_ble_pigeon/universal_ble_pigeon_channel.dart Implements readRssi in pigeon channel with error handling wrapper
lib/src/universal_ble_platform_interface.dart Adds abstract readRssi method to platform interface
lib/src/universal_ble.dart Adds public API method with comprehensive documentation for reading RSSI
lib/src/models/ble_device.dart Adds convenience readRssi method to BleDevice class
lib/src/universal_ble_web/universal_ble_web.dart Implements readRssi stub that throws "not implemented" exception for Web
lib/src/universal_ble_linux/universal_ble_linux.dart Implements readRssi stub that throws "not implemented" exception for Linux
android/src/main/kotlin/com/navideck/universal_ble/UniversalBlePlugin.kt Implements readRssi using BluetoothGatt.readRemoteRssi() with proper callback handling and cleanup
android/src/main/kotlin/com/navideck/universal_ble/UniversalBleHelper.kt Adds RssiResultFuture data class for managing async RSSI read operations
android/src/main/kotlin/com/navideck/universal_ble/UniversalBle.g.kt Generated Kotlin platform channel setup code for readRssi
darwin/Classes/UniversalBlePlugin.swift Implements readRssi using CBPeripheral.readRSSI() with proper future handling and cleanup
darwin/Classes/UniversalBleHelper.swift Adds RssiReadFuture class for managing async RSSI read operations
darwin/Classes/UniversalBle.g.swift Generated Swift platform channel setup code for readRssi
windows/src/universal_ble_plugin.h Adds readRssi method declaration to Windows plugin
windows/src/universal_ble_plugin.cpp Implements readRssi stub that returns "not implemented" error for Windows
windows/src/generated/universal_ble.g.h Generated C++ platform channel interface for readRssi
windows/src/generated/universal_ble.g.cpp Generated C++ platform channel implementation for readRssi
test/ble_characteristic_test.dart Adds mock readRssi implementation returning -50 dBm
example/lib/data/mock_universal_ble.dart Adds mock readRssi implementation for example app
example/lib/peripheral_details/peripheral_detail_page.dart Adds "Get RSSI" button to example app UI
README.md Adds "Reading RSSI" section with usage example, platform limitations, and fixes code block formatting
README.low_level.md Adds "Read RSSI" section with usage example and platform limitations

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +283 to +301
override fun readRssi(deviceId: String, callback: (Result<Long>) -> Unit) {
try {
val gatt = deviceId.toBluetoothGatt()
if (gatt.readRemoteRssi()) {
rssiResultFutureList.add(RssiResultFuture(deviceId, callback))
} else {
callback(
Result.failure(
createFlutterError(
UniversalBleErrorCode.FAILED,
"Failed to read RSSI"
)
)
)
}
} catch (e: FlutterError) {
callback(Result.failure(e))
}
}
Copy link

Copilot AI Dec 23, 2025

Choose a reason for hiding this comment

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

Missing debug logging for readRssi operation. Other similar operations (requestMtu, readValue, writeValue, setNotifiable) include UniversalBleLogger.logDebug calls for consistency and debugging purposes. Consider adding a log statement like "READ_RSSI -> $deviceId" at the start of the function to match the logging pattern used in other operations.

Copilot uses AI. Check for mistakes.
Comment on lines +136 to +139
@override
Future<int> readRssi(String deviceId) async {
return -50; // Mock RSSI value
}
Copy link

Copilot AI Dec 23, 2025

Choose a reason for hiding this comment

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

The readRssi functionality lacks test coverage. While mock implementations have been added to _UniversalBleMock and MockUniversalBle, there are no actual test cases that invoke and verify the readRssi behavior. Consider adding a test case in the test suite that calls UniversalBle.readRssi or bleDevice.readRssi and verifies the expected mock return value of -50.

Copilot uses AI. Check for mistakes.
Comment on lines +303 to +324
override fun onReadRemoteRssi(gatt: BluetoothGatt?, rssi: Int, status: Int) {
val deviceId = gatt?.device?.address ?: return
rssiResultFutureList.removeAll {
if (it.deviceId == deviceId) {
if (status == BluetoothGatt.GATT_SUCCESS) {
it.result(Result.success(rssi.toLong()))
} else {
it.result(
Result.failure(
createFlutterError(
UniversalBleErrorCode.FAILED,
"Failed to read RSSI"
)
)
)
}
true
} else {
false
}
}
}
Copy link

Copilot AI Dec 23, 2025

Choose a reason for hiding this comment

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

Missing error logging in onReadRemoteRssi failure case. Other similar callbacks (onCharacteristicRead, onCharacteristicWrite) log errors using UniversalBleLogger.logError when operations fail. Consider adding error logging when status is not GATT_SUCCESS to maintain consistency with the codebase's error reporting pattern.

Copilot uses AI. Check for mistakes.
@fotiDim fotiDim merged commit bb07cbb into Navideck:main Jan 5, 2026
2 of 3 checks passed
fotiDim pushed a commit that referenced this pull request Jan 5, 2026
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.

3 participants