cordova-plugin-ble-central
cordova-plugin-ble-central copied to clipboard
StartNotification doesn't return me callback success or callback error
Hi, I use startNotification to handle measure of IMU sensor, at startNotification sensor should me a constant signal of measures, I don't understand because startNotification tell me getData, but after doesn't return me callback success or callback error. How can I trouble?? this is my code:
startMeasureNotification() {
let buffer = new ArrayBuffer(3)
let dataViewObject = new DataView(buffer)
dataViewObject.setUint8(0, 0x01);
dataViewObject.setUint8(1, 0x01);
dataViewObject.setUint8(2, 0x21);
this.ble.startNotification(this.id1, "15172000-4947-11e9-8646-d663bd873d93", "15172003-4947-11e9-8646-d663bd873d93").subscribe((result) => {
console.log(result);
this.ble.write(this.id1, "15172000-4947-11e9-8646-d663bd873d93", "15172001-4947-11e9-8646-d663bd873d93", dataViewObject.buffer).then((result) => {
console.log(result);
});
}, (error) => {
console.log(error);
})
this.ble.startNotification(this.id2, "15172000-4947-11e9-8646-d663bd873d93", "15172003-4947-11e9-8646-d663bd873d93").subscribe((result) => {
console.log(result);
this.ble.write(this.id2, "15172000-4947-11e9-8646-d663bd873d93", "15172001-4947-11e9-8646-d663bd873d93", dataViewObject.buffer).then((result) => {
console.log(result);
});
}, (error) => {
console.log(error);
});
}
output in ios :To Native Cordova -> BLE
startNotification BLE1395621188 ["options": [B2795872-4070-B2F0-3064-1475EDA2C967, 15172000-4947-11e9-8646-d663bd873d93, 15172003-4947-11e9-8646-d663bd873d93]]
2022-06-20 12:38:25.011776+0200 App[930:122363] registering for notification
2022-06-20 12:38:25.011840+0200 App[930:122363] getData
2022-06-20 12:38:25.011933+0200 App[930:122363] Looking for 15172003-4947-11E9-8646-D663BD873D93 with properties 16
The getData log there is a normal part of the startNotification flow:
https://github.com/don/cordova-plugin-ble-central/blob/0732380e27772a08df2c6ce6447b4cab901ad4d2/src/ios/BLECentralPlugin.m#L300
Does the Peripheral automatically start sending notifications as soon as you turn them on? Or do you need to write a payload to start them?
I ask because the ble.write you've nested in the subscribe there will only get called after a notification arrives.
I need to write payload to start them, sensors manual suggest to do before startNotification and after startMeasure, I do the ble.write inside subscribe do start of measure, Do I can try this.ble.write before startNotification?? this.ble.write(this.id1, "15172000-4947-11e9-8646-d663bd873d93", "15172001-4947-11e9-8646-d663bd873d93", dataViewObject.buffer).then((result) => { console.log(result); this.ble.startNotification(this.id1, "15172000-4947-11e9-8646-d663bd873d93", "15172003-4947-11e9-8646-d663bd873d93").subscribe((result) => {
console.log(result);
});
}, (error) => {
console.log(error);
})
output: To Native Cordova -> BLE write BLE660513637 ["options": [50BDE010-2FAF-BD5D-31FD-AD391438DEB3, 15172000-4947-11e9-8646-d663bd873d93, 15172001-4947-11e9-8646-d663bd873d93, { CDVType = ArrayBuffer; data = AQEh; }]] 2022-06-21 09:07:47.026710+0200 App[2549:186654] getData 2022-06-21 09:07:47.026989+0200 App[2549:186654] Looking for 15172001-4947-11E9-8646-D663BD873D93 with properties 8 To Native Cordova -> BLE startNotification BLE660513638 ["options": [50BDE010-2FAF-BD5D-31FD-AD391438DEB3, 15172000-4947-11e9-8646-d663bd873d93, 15172003-4947-11e9-8646-d663bd873d93]] ⚡️ [log] - null 2022-06-21 09:07:47.066179+0200 App[2549:186654] registering for notification 2022-06-21 09:07:47.066366+0200 App[2549:186654] getData 2022-06-21 09:07:47.066560+0200 App[2549:186654] Looking for 15172003-4947-11E9-8646-D663BD873D93 with properties 16
I haven't data, I wait your answer, thanks for your response. in sensor in Ios, I have one flag isNotifying that is false and I read that if isNotifying is false, notification will always disable, is this my problem??
Apologies @AngeNew , this fell off my radar.
Yes, I'd do the write and then subscribe. What's the console output of result there?
I'd suggest taking a look at https://github.com/don/cordova-plugin-ble-central/issues/913#issuecomment-1103876933 in case this is a similar display issue.
Alternatively, you might be experiencing https://github.com/don/cordova-plugin-ble-central/issues/805#issuecomment-713639126
Unfortunately, I don't maintain the ionic wrappers, so I'm not certain what's causing the problem you see there.
I trouble problem in this way, I use async await in right way, and I must convert my payload mode in hex to start correctly payload, thanks for your support
async startMeasure() { let buffer = new ArrayBuffer(3); let dataViewObject = new DataView(buffer); /** 01 indicate measures / dataViewObject.setUint8(0, 0x01); /* 01 indicate start measures */ dataViewObject.setUint8(1, 0x01); dataViewObject.setUint8(2, 0x15);
this.ble.startNotification(this.id1, "15172000-4947-11e9-8646-d663bd873d93", "15172003-4947-11e9-8646-d663bd873d93").subscribe(
(data) => {
console.log(this.saveSingleMeasure(data));
this.measures1.push(this.saveSingleMeasure(data));
},
() => console.log("error")
);
await this.ble.write(this.id1, "15172000-4947-11e9-8646-d663bd873d93", "15172001-4947-11e9-8646-d663bd873d93", dataViewObject.buffer).then((result) => {
console.log(result);
}, (error) => {
console.log(error);
});
this.ble.startNotification(this.id2, "15172000-4947-11e9-8646-d663bd873d93", "15172003-4947-11e9-8646-d663bd873d93").subscribe(
(data) => {
console.log(this.saveSingleMeasure(data));
this.measures2.push(this.saveSingleMeasure(data));
},
() => console.log("error")
);
await this.ble.write(this.id2, "15172000-4947-11e9-8646-d663bd873d93", "15172001-4947-11e9-8646-d663bd873d93", dataViewObject.buffer).then((result) => {
console.log(result);
}, (error) => {
console.log(error);
});
}
I trouble also problem that send me empty notifications with this function where I use Float32 right format for my data /** save single measure in Float32 */ saveSingleMeasure(buffer) { var data = new Float32Array(buffer[0]); return data; }