During my internship at Bever Innovations, a Dutch company that manufactures smart LED-light solutions for gas stations and other companies, I developed a Flutter application that communicates via Bluetooth Low Energy (BLE) with the different LED devices. The idea was to communicate without making a connection, in order to save time and increase the usage speed when there are many products in one area.
In order to get this to work, I needed to turn the device where the application was running on into a Bluetooth Low Energy Peripheral, which means it can advertise custom manufacturer data without specifying a receiver. Because there wasn't any package available on pub.dev that would allow me to do that, I decided to create my own and share it by making it open source.
By enabling a mobile device to broadcast custom manufacturer data, we were able to communicate without much delay with the different products, regardless of how many products were in the area. You can find the repository at the bottom of this post.
One of the advantages of Flutter is that you can run your application on multiple platforms with the same codebase. However, there are some drawbacks on using BLE on iOS. Using Android, it's no problem to advertise custom manufacturer data at all, but on iOS Apple restricts the possibility to broadcast custom data. In order to get around this problem, I’ve developed a way to broadcast custom data using the UUID field of the Core Bluetooth API. Using this way, we can still broadcast non directed data over the air via BLE on an iOS device!
I've used Flutter as cross-platform framework because it compiles to native code and allows for really great performance. GitHub Actions allowed me to automate tests, which was great. Thanks for the free GitHub Pro included in the student pack @GitHub! For receiving BLE data I’ve used flutter_blue.
- Github Actions
Keep in mind that flutter_ble_peripheral is still under development and your mileage may vary. Feel free to contribute and make it even greater!
A Flutter package for advertising BLE data in peripheral mode
This Flutter plugin allows a device to be used in Peripheral mode, and advertise data over BLE to central devices.
Help develop this plugin!
If you want to contribute to this plugin, feel free to make issues and pull-requests.
Since this plugin is currently being developed, limited functionality will be available. Check the release page for the most recent release.
|Set and advertise a custom uuid.
|Advertise custom service
|Advertise a custom service.
|Advertise custom characteristic
|Advertise a custom characteristic with any of the following specifications.
|Enable the possibility to read a value.
|Enable the possibility to write a value.
|Enable the possibility to subscribe and notify a value.
FlutterBlue is a bluetooth plugin for Flutter, a new mobile SDK to help developers build modern apps for iOS and Android.
This library is actively developed alongside production apps, and the API will evolve as we continue our way to version 1.0.
Please be fully prepared to deal with breaking changes.
Having trouble adapting to the latest API? I'd love to hear your use-case, please contact me.
Cross-Platform Bluetooth LE
FlutterBlue aims to offer the most from both platforms (iOS and Android).
Using the FlutterBlue instance, you can scan for and connect to nearby devices (BluetoothDevice) Once connected to a device, the BluetoothDevice object can discover services (BluetoothService), characteristics (BluetoothCharacteristic), and descriptors (BluetoothDescriptor) The BluetoothDevice object is then used to directly interact with characteristics and descriptors.
Obtain an instance
FlutterBlue flutterBlue = FlutterBlue.instance;