This Dart package provides functionality for interacting with OpenEarable devices. It enables you to communicate with OpenEarable devices, control LED colors, control audio, and access raw sensor data.
For your app to be able to use UniversalBLE in this package, you need to grant the following permissions:
You need to add the following permissions to your AndroidManifest.xml file:
<!-- flutter_reactive_ble permissions -->
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<!-- location permissions -->
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION"/>
If you use location services in your app, remove android:maxSdkVersion="30"
from the location permission tags
For iOS it is required you add the following entries to the Info.plist
file of your app. It is not allowed to access Core BLuetooth without this. See our example app on how to implement this. For more indepth details: Blog post on iOS bluetooth permissions
iOS 13 and higher
iOS 12 and lower
For macOS, add the Bluetooth capability to the macOS app from Xcode.
To get started with the OpenEarable Flutter package, follow these steps:
Installation: Add the package to your flutter project: \
flutter pub add open_earable_flutter
Alternatively, you can follow the instructions on pub.dev
Import the package:
import 'package:open_earable_flutter/open_earable_flutter.dart';
Initialize OpenEarable
final openEarable = OpenEarable();
Connect to Earable Device
openEarable.bleManager.startScan();
// Listen for discovered devices
openEarable.bleManager.scanStream.listen((device) {
// Handle discovered device
});
// Connect to a device
openEarable.bleManager.connectToDevice(device);
String? deviceName = openEarable.deviceName;
String? deviceIdentifier = openEarable.deviceIdentifier;
String? deviceFirmwareVersion = openEarable.deviceFirmwareVersion;
var config = OpenEarableSensorConfig(sensorId: 0, samplingRate: 30, latency: 0);
openEarable.sensorManager.writeSensorConfig(config);
Please refer to open-earable for a documentation on all possible sensor configurations
openEarable.sensorManager.subscribeToSensorData(0).listen((data) {
// Handle sensor data
});
Sensor data is returned as a dictionary:
{
"sensorId": 0,
"timestamp": 163538,
"sensorName": "ACC_GYRO_MAG",
"ACC": {
"units": {"X": "g", "Y": "g", "Z": "g"},
"X": 5.255882263183594,
"Y": -2.622856855392456,
"Z": 8.134146690368652
},
"GYRO": {
"units": {"X": "dps", "Y": "dps", "Z": "dps"},
"X": 0.007621999830007553,
"Y": -0.030487999320030212,
"Z": -0.015243999660015106
},
"MAG": {
"units": {"X": "uT", "Y": "uT", "Z": "uT"},
"X": -566.1000366210938,
"Y": -95.70000457763672,
"Z": -117.30000305175781
}
"EULER": {
"units": {"ROLL": "rad", "PITCH": "rad", "YAW": "rad"},
"ROLL": 0.8741,
"PITCH": -0.2417,
"YAW": 1.2913
}
}
Stream batteryLevelStream = openEarable.sensorManager.getBatteryLevelStream();
Stream buttonStateStream = openEarable.sensorManager.getButtonStateStream();
openEarable.rgbLed.writeLedColor(r: 0, g: 255, b: 0);
openEarable.audioPlayer.wavFile("audio.wav");
openEarable.audioPlayer.setState(AudioPlayerState.start);
int waveForm = 1;
double frequency = 500.0;
double loudness = 0.5;
openEarable.audioPlayer.frequency(waveForm, frequency, loudness);
openEarable.audioPlayer.setState(AudioPlayerState.start);
int jingleId = 1;
openEarable.audioPlayer.jingle(jingleId);
openEarable.audioPlayer.setState(AudioPlayerState.start);