DEV Community

Cover image for Advertising Custom Data over Bluetooth Low Energy on iOS & Android: Github Graduation
Julian Steenbakker
Julian Steenbakker

Posted on

Advertising Custom Data over Bluetooth Low Energy on iOS & Android: Github Graduation

My Final Project

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.

Picture showing different LED devices communicating with smartphone

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.

flutter_ble_peripheral

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.

An Apple a day keeps BLE away?

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!

How I built it

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.

  • Flutter
  • Github Actions
  • flutter_blue
  • flutter_ble_peripheral

Link to Code

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!

GitHub logo juliansteenbakker / flutter_ble_peripheral

A Flutter package for advertising BLE data in peripheral mode

pub package Join the chat Dev: Workflow Master: Workflow

FlutterBlePeripheral

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.

Not stable

Since this plugin is currently being developed, limited functionality will be available. Check the release page for the most recent release.

Functionality Android iOS Description
Advertise UUID 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.
Read characteristic Enable the possibility to read a value.
Write characteristic Enable the possibility to write a value.
Notify characteristic Enable the possibility to subscribe and notify a value.



GitHub logo pauldemarco / flutter_blue

Bluetooth plugin for Flutter

pub package Chat


FlutterBlue

Introduction

FlutterBlue is a bluetooth plugin for Flutter, a new mobile SDK to help developers build modern apps for iOS and Android.

Alpha version

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.

Usage

Obtain an instance

FlutterBlue flutterBlue = FlutterBlue.instance;

Scan for devices

Top comments (1)

Collapse
 
elmubarak profile image
Mubarak Ibrahim

Amazing, can you please kindly share or explain how you managed to send custom manufacturer data over iOS