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.
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.
Finding devices is the first step. You can discover
all advertised devices
devices with advertised services
devices that fullfil a custom filter expression
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.
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 ;)
Connect / Disconnect
For connecting the perviously discovered device, you have to use the adapter. We are currently discussing to move the connect and disconnect functions to
Getting the services of a device is easy.
Getting the characteristics of a service is as easy as getting a service of a device.
After you have found your characteristic, you can read, write or subscribe to notification.
characteristic.StartUpdates() starts listening for notifications and updates the
characteristic when the notification has been received successfully. You can stop listening with
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.
Give it a try
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
- 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
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.
The main todos are
- better build process
- more documentation
- get rid of fat single gatt callback (split it)
- unit tests
- request permission
- enable bluetooth
- basic info like IsBleAvailable, MaxSupportedVersion, …