don / cordova-plugin-ble-central

Bluetooth Low Energy (BLE) Central plugin for Apache Cordova (aka PhoneGap)
Apache License 2.0
951 stars 606 forks source link

startNotification response empty [{},2] @android8.0.0 #805

Closed butlet closed 3 years ago

butlet commented 4 years ago

hi, i am building an android app using ionic5 framework in which cordova-plugin-ble-central plugin is used. The BLE peripheral has a characteristic which pushes notifications to phone.i can scan,connect,and readrssi,also can write to ble,but when i read 0x1800 0x2a00 it did not response data,it's empty. i enable the notification and register the callback by calling startNotification(),when the ble sends message, the phone just received [{},1],or [{},2],[{},3].... why no data,just has received times

start_notification(){ this.ble.startNotification(this.connected_device.id, SERVICE_ID_READ,CHARACTERISTICS_ID_READ).subscribe( msg => { this.setStatus("notification succ:" + JSON.stringify(msg)); }, err => { this.setStatus("notification err:" + JSON.stringify(err)); } ) }

saayalac commented 4 years ago

I am facing the same problem. I had to go to an older version to make it work. Had the problem with android 6, 9 and 10

markamccorkle commented 3 years ago

Have you tried reading the first index in the response to an array buffer? This was changed a little while back and nobody updated the docs.

const data = new Uint8Array(buffer[0]);

Bozonych commented 3 years ago

Have you tried reading the first index in the response to an array buffer? This was changed a little while back and nobody updated the docs.

const data = new Uint8Array(buffer[0]);

yep, i will changed my code: from: const data16 = new Uint16Array(buffer); to: const data16 = new Uint16Array(buffer[0]); and all works fine ^-^