Hi,
I want to read glucose measurements from a BLE-enabled glucose meter with Ionic2. For this purpose, I use the official BLE Plugin.
Scanning and connecting to a device works pretty good. The problem kicks in on reading a characteristic. I always get the following output: ## ERROR READ ##Read failed
This is my code:
// assuming there is only one device in range
BLE.scan([], 30).subscribe(
device => {
console.log("## DEVICE ##" + JSON.stringify(device));
BLE.connect(device.id).subscribe(
data => {
console.log("## CONNECT ##" + JSON.stringify(data));
// service und characteristic UUID: https://developer.bluetooth.org/gatt/services/Pages/ServiceViewer.aspx?u=org.bluetooth.service.glucose.xml
BLE.read(device.id, '1808', '2A18').then(function (data) {
console.log("## READ ##" + JSON.stringify(data));
}, function (error) {
console.log("## ERROR READ ##" + error);
});
},
error => console.log("## ERROR CONNECTING ##" + JSON.stringify(error))
);
},
error => console.log("## ERROR SCANNING ##" + JSON.stringify(error))
);
As the glucose service is pretty complex compared to the battery service, I tried to read this first. Unfortunately, my glucose meter device does not have a battery service.
Is there any bug in my code or why do I get this nothing saying error?
What I know from the source code of the BLE plugin:
The error message is set in readCharacteristic(CallbackContext callbackContext, UUID serviceUUID, UUID characteristicUUID)
in Periperhal.java. This is a consequence of a failing initialization of BluetoothGatt#readCharacteristic. But this only returns true or false, so no more information there.
Another thing I noticed while using this plugin:
I always have to scan for devices first. Only after doing so I can connect (again, looking at the source code of the plugin, it is obvious as peripherals are cached and only added while scanning). To my knowledge, a huge benefit of BLE is that a peripheral does not always have to advertise but you can connect to it. So in my eyes, it would be much better to get all bonded devices at initialization time of the plugin.
I hope you can help me with this error.
Thanks in advance.