BrilliantBle
A Flutter package to connect to BLE devices by brilliant Labs
It Uses FlutterBluePlus as a dependency to connect to BLE devices.
Provide an abstraction layer over the FlutterBluePlus package to make it easier to connect to BLE devices and to read write files and data to devices.
Features
- Connect to BLE devices (Brilliant Labs devices only for now)
a. Monocle (Supported)
b. Frame (TODO) - Read and write data to BLE devices
- Read and write files to BLE devices
Getting started
Install the package by adding the following to your pubspec.yaml
file:
dependencies:
brilliant_ble: ^0.0.1
or with flutter pub
flutter pub add brilliant_ble
Then run flutter pub get
to install the package.
For Android
flutter_blue_plus is compatible only from version 21 of Android SDK so you should change this in your android/app/build.gradle
file
android/app/build.gradle:
android {
defaultConfig {
minSdkVersion: 21
Add the following permissions to your AndroidManifest.xml
file
android/app/src/main/AndroidManifest.xml:
<!-- Tell Google Play Store that your app uses Bluetooth LE
Set android:required="true" if bluetooth is necessary -->
<uses-feature android:name="android.hardware.bluetooth_le" android:required="false" />
<!-- New Bluetooth permissions in Android 12
https://developer.android.com/about/versions/12/features/bluetooth-permissions -->
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" android:usesPermissionFlags="neverForLocation" />
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
<!-- legacy for Android 11 or lower -->
<uses-permission android:name="android.permission.BLUETOOTH" android:maxSdkVersion="30" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" android:maxSdkVersion="30" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" android:maxSdkVersion="30"/>
<!-- legacy for Android 9 or lower -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" android:maxSdkVersion="28" />
For iOS
Add the following permissions to your Info.plist
file
<dict>
<key>NSBluetoothAlwaysUsageDescription</key>
<string>This app always needs Bluetooth to function</string>
<key>NSBluetoothPeripheralUsageDescription</key>
<string>This app needs Bluetooth Peripheral to function</string>
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>This app always needs location and when in use to function</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>This app always needs location to function</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>This app needs location when in use to function</string>
<key>UIBackgroundModes</key>
<array>
<string>bluetooth-central</string>
</array>
Usage
ble = await BrilliantBle.create();
ble.onConnected = () {
print("connected");
};
ble.onDisconnected = () {
print("Disconnected");
};
ble.onData = (data) {
// Data Recieved from the device
print(String.fromCharCodes(data));
};
await ble.setup();
Then after connecting to the device you can send and receive data using the following methods
await ble.sendData("print('hello world')\n\r");
TODO
x
Add support for Monocle REPL (Done)