Bluetooth LE plugin for Xamarin released

The first release candidate of our BLE plugin is now available.

Posted by Sven-Michael Stübe on May 13, 2016

Adrian (@secelead) and I pushed the first release candidate of our bluetooth low energy plugin for xamarin and MvvmCross to NuGet, today. The code is available on github. It is based on Monkey robotics, but heavily refactored.

It currently supports Android and iOS and the following features are implemented.

Bluetooth State

You can check if the device supports bluetooth LE, check whether it is turned on or off and subscribe to any changes on this state.

varstate=ble.State;ble.StateChanged+=(s,e)=>{Debug.WriteLine($"The bluetooth state changed to {e.NewState}");};

You can provide any Func<IDevice, bool> you want. You can access the simple properties of a device (like its name) or use the advertisement records to filter devices on a more complex base.

adapter.StartScanningForDevicesAsync(dev=>dev.Name.Contains("Sven"));

a single device

In some use cases you might be only interested in a particular device (e.g. last connected device). In these cases starting the discovery, handling events, etc. is annoying. We implemented this for you ;)

characteristic.StartUpdates() starts listening for notifications and updates the Value of characteristic when the notification has been received successfully. You can stop listening with characteristic.StopUpdates().

Reading Rssi

Initially, you get the Rssi value when you discover the device. If you want to update it, you can use UpdateRssiAsync. Due some limitations, this works only while being connected to the device.

Sample app

We provide a sample Xamarin.Forms app, that is a basic bluetooth LE scanner. With this app, it’s possible to

check the bluetooth LE status

discover devices

connect/disconnect

discover the services

discover the characteristics

see characteristic details

read/write and register for notifications of a characteristic

Have a look at the code and use it as starting point to learn about the plugin and play around with it.

Our goals for v 1.0

Adrian started this project last year as MvvmCross plugin. He fixed alot of bugs and made it stable. It has been in v 0.9.x for quite a while and we wanted to bring it to v 1.0. In recent weeks, we refactored it with the goals

provide a “vanilla” Xamarin plugin

provide a sample app

streamline the API (make it asnyc and use cancelable)

get rid of old code

What next?

We are aiming for a soon stable release. We invite everybody to give some feedback and suggestions. Feel free, to create an issue on github or contact us directly on twitter or slack.
The open issues can be found on github.