Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StartNotification doesn't return me callback success or callback error #921

Open
AngeNew opened this issue Jun 20, 2022 · 4 comments
Open

Comments

@AngeNew
Copy link

AngeNew commented Jun 20, 2022

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
@peitschie
Copy link
Collaborator

The getData log there is a normal part of the startNotification flow:

BLECommandContext *context = [self getData:command prop:CBCharacteristicPropertyNotify]; // TODO name this better

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.

@AngeNew
Copy link
Author

AngeNew commented Jun 21, 2022

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??

@peitschie
Copy link
Collaborator

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 #913 (comment) in case this is a similar display issue.

Alternatively, you might be experiencing #805 (comment)

Unfortunately, I don't maintain the ionic wrappers, so I'm not certain what's causing the problem you see there.

@AngeNew
Copy link
Author

AngeNew commented Jun 24, 2022

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;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants