setNotifyValue method
Sets notifications or indications for the characteristic.
- If a characteristic supports both notifications and indications, we use notifications. This is a limitation of CoreBluetooth on iOS.
forceIndications
Android Only. force indications to be used instead of notifications.
Implementation
@override
Future<bool> setNotifyValue(bool notify,
{bool forceIndications = false, int timeout = 15}) async {
if (!device.isConnected) {
throw Exception('Cannot set notify value on a disconnected device');
}
if (notify) {
_timer = Timer.periodic(const Duration(seconds: 5), (timer) {
if (!device.isConnected) {
_timer?.cancel();
_timer = null;
return;
}
// TODO: dynamic report data
_notificationController.add(jsonEncode({
"#": 27,
"date": "20-02-14",
"time": "16:05:04",
"timestamp": 1644854704,
"report": true,
"cycles": 2445,
"doses": 35,
"event": 2
}).codeUnits);
});
} else {
_timer?.cancel();
_timer = null;
}
return true;
}