Home Arrow Icon Knowledge base Arrow Icon Global Arrow Icon How does MvvmCross.Plugin.BLE handle device discovery compared to Plugin.BLE


How does MvvmCross.Plugin.BLE handle device discovery compared to Plugin.BLE


MvvmCross.Plugin.BLE and Plugin.BLE are both used for Bluetooth Low Energy (BLE) device discovery, but they handle this process differently based on their architecture and implementation.

MvvmCross.Plugin.BLE

MvvmCross.Plugin.BLE is designed to work within the MvvmCross framework, providing a structured approach to BLE device discovery. It registers `IBluetoothLE` and `IAdapter` as lazy-initialized singletons, allowing developers to resolve these services in their view models or other components. This plugin supports Android, iOS, macOS, and Windows platforms.

To discover devices using MvvmCross.Plugin.BLE, you typically use the `CrossBluetoothLE.Current.Adapter` to access the adapter. However, specific methods for scanning or discovering devices are not explicitly detailed in the plugin's documentation. Instead, it relies on the underlying `CrossBluetoothLE` implementation, which is commonly used in Xamarin-based projects.

The plugin allows you to check the Bluetooth state and listen for state changes, which is useful for managing device discovery based on the current Bluetooth status. For actual scanning, you would typically use methods similar to those in the vanilla `CrossBluetoothLE` implementation, such as accessing the adapter and using its methods to start scanning.

Plugin.BLE (CrossBluetoothLE)

Plugin.BLE, often referred to as CrossBluetoothLE, is a more generic plugin for accessing BLE functionality across multiple platforms, including Android and iOS. It provides a straightforward way to discover BLE devices by using the `CrossBluetoothLE.Current.Adapter` to start scanning.

To discover devices with CrossBluetoothLE, you would typically use the adapter's methods to initiate a scan. The plugin supports discovering all advertised devices, devices with specific advertised services, or devices that match a custom filter. Once devices are discovered, you can connect to them, explore their services and characteristics, and perform read/write operations or subscribe to notifications.

In terms of device discovery, CrossBluetoothLE offers more direct control over the scanning process compared to MvvmCross.Plugin.BLE. It allows developers to specify filters for discovering devices with specific services or characteristics, making it more versatile for applications that need to interact with a variety of BLE devices.

Comparison

- Architecture: MvvmCross.Plugin.BLE is specifically designed for use within the MvvmCross framework, providing services that can be injected into view models. Plugin.BLE (CrossBluetoothLE) is more generic and can be used in any Xamarin-based project.

- Device Discovery: Both plugins rely on the underlying BLE implementation for device discovery. However, CrossBluetoothLE provides more direct access to scanning methods and filters, making it easier to customize the discovery process. MvvmCross.Plugin.BLE's documentation does not explicitly detail scanning methods, suggesting it might rely on the developer to use the underlying CrossBluetoothLE functionality.

- Platform Support: Both plugins support Android and iOS, but MvvmCross.Plugin.BLE also mentions support for macOS and Windows, which might be beneficial for cross-platform applications targeting these platforms.

In summary, while both plugins enable BLE device discovery, MvvmCross.Plugin.BLE is more integrated with the MvvmCross framework and might require additional setup or reliance on underlying CrossBluetoothLE functionality for scanning. Plugin.BLE (CrossBluetoothLE) offers a more straightforward approach to device discovery with direct access to scanning methods and filters.

Citations:
[1] https://www.nuget.org/packages/MvvmCross.Plugin.BLE/
[2] https://github.com/don/cordova-plugin-ble-central
[3] https://github.com/xabre/xamarin-bluetooth-le/issues/524
[4] https://github.com/mrozema/xamarin-bluetooth-le
[5] https://developer.android.com/develop/connectivity/bluetooth/ble/find-ble-devices
[6] https://punchthrough.com/ble-connectivity-architecture/
[7] https://smstuebe.de/2016/05/13/blev1.0/
[8] https://github.com/dotnet-bluetooth-le/dotnet-bluetooth-le
[9] https://stackoverflow.com/questions/38327176/xamarin-forms-plugins-ble-mvvmcross-plugins-ble