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

Notification callback is not being raise in any device and the instructions sent to the characteristics are not being written #677

Open
luissanchez0305 opened this issue Aug 13, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@luissanchez0305
Copy link

Describe the bug
The plugin is being used to connect a Bluetooth device to the mobile. It works up to setting the notification on the mobile device to check changes in the characteristics. I know this because the Bluetooth device starts blinking differently.

But when I try to write into a characteristic it's not raising the callback set on the notification. Secondly, the device should have a 3rd set of blinking when an instruction is written in a characteristic, which never happens.

For what is worth, I have set all the necessary code in a Android Java app and it works correctly, so the Bluetooth device is working correctly

To Reproduce
Steps to reproduce the behavior:

  1. Go to connect device and choose the device
    Instructions use up to here
    ´´´
    // plugin initialize
    await BleClient.initialize()

// to connect the device
await BleClient.connect(id, (deviceId) => this.onDisconnect(deviceId));

// to search in all the services and characteristics of the device and choose the right one
await BleClient.getServices(id);

// to make sure there is no other notification set on the mobile device
await BleClient.stopNotifications(deviceId, serviceId, characteristic);

// set the notification, this instruction change the blinking on the BT device, so it's working
await BleClient.startNotifications(
deviceId,
serviceId,
characteristicId,
(value) => {
console.log('current heart rate', value);

            console.log('raw', value);
            console.log('text', dataViewToText(value));
            console.log('hex', dataViewToHexString(value));
            console.log('numbers', dataViewToNumbers(value));
        }
    );

// send the instructions to the device
const message = 'P : 2 , 3 , 5 , 6';
const arrayString = message.split(' ');
const buffer = new ArrayBuffer(arrayString.length);
const view = new DataView(buffer, 0);
for (let i = 0; i < arrayString.length; i++) {
let v;
if ( typeof arrayString[i] === 'string' && arrayString[i].charAt(1) === 'x' ) {
const hexString = arrayString[i];
const hex = hexString.replace(/^0x/, '');
v = hex.match(/[\dA-F]{2}/gi);
}
else if ( typeof arrayString[i] === 'number' ) {
v = arrayString[i];
}
else {
v = new TextEncoder().encode(arrayString[i]);
console.log('hex', arrayString[i], v);
}
view.setUint8(i,v);
}

    await BleClient.disconnect(id);
    await BleClient.connect(id, (deviceId) => console.log('Disconnected from', deviceId));
    await BleClient.write(id, serviceUuid, characteristicUuid, view);

// 1st ERROR: the notification callback doesn't run

// 2nd ERROR: the notification callback doesn't run on another instruction and the 2nd blinking change never happens. Which give the idea that the written have never taken place
´´´

Expected behavior

  1. Callback notification raise
  2. BT device changes the set of blinking lights to acknowledge the instructions are being set correctly

Screenshots
image
image
image

Plugin version:

  • "@capacitor-community/bluetooth-le": "^6.0.1"
@luissanchez0305 luissanchez0305 added the bug Something isn't working label Aug 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant