react-native-ble-manager: BleManagerDidUpdateValueForCharacteristic is not being triggered
Describe the bug I’m trying to listen for the changes happening on a characteristic. To achieve that I added a listener on BleManagerDidUpdateValueForCharacteristic event. But this handler is not being called when the characteristic value is changed.
Code changes
await BleManager.connect(peripheral.id);
await sleep(900);
await BleManager.retrieveServices(peripheral.id);
BleManager.startNotification(
peripheral.id,
"00001530-1212-efde-1523-785feabcd123",
"00001531-1212-efde-1523-785feabcd123"
)
.then(async res => {
console.log('started Notification');
bleManagerEmitter.addListener(
"BleManagerDidUpdateValueForCharacteristic",
handleUpdateValueForCharacteristic,
);
})
.catch((error) => {
// Failure code
console.log(error);
});
BleManager.write(
peripheral.id,
"00001530-1212-efde-1523-785feabcd123",
"00001531-1212-efde-1523-785feabcd123",
buffer.toJSON().data
)
.then(async(data) => {
// Success code
console.log("Write: " + data);
BleManager.readDescriptor(
peripheral.id,
"00001530-1212-efde-1523-785feabcd123",
"00001531-1212-efde-1523-785feabcd123",
"2902"
)
.then((data) => {
// Success code
console.log("Read after write 1: " + data);
})
.catch((error) => {
// Failure code
console.log(error);
});
})
.catch((error) => {
// Failure code
console.log(error);
});
const handleUpdateValueForCharacteristic = (
data: BleManagerDidUpdateValueForCharacteristicEvent,
) => {
console.debug(
`[handleUpdateValueForCharacteristic] received data from '${data.peripheral}' with characteristic='${data.characteristic}' and value='${data.value}'`,
);
};
Expected behavior BleManagerDidUpdateValueForCharacteristic should be triggered whenever the Characteristic value is changed.
Screenshots
Smartphone (please complete the following information):
- Device: Android 12
- react-native-ble-manager version: 10.1.2
- react-native version: 0.71.2
Please help me in fixing this issue.
About this issue
- Original URL
- State: open
- Created a year ago
- Comments: 17 (2 by maintainers)
@toanleviet95 I have tried but it still does not work, the maximum set MTU from the device I get is 150 bytes, do not think this would be an issue when getting data back from device… the problem is as soon as it starts notification mobile phone gets disconnected using bluetooth.
The phone has 5.2 bluetooth version
@marcosinigaglia is there a way we can debug and see what’s the error? callback is not getting triggered
@marcosinigaglia what could be the issue? onCharacteristicChanged is not getting fired but write descriptor gives success
I get the same error and not receiving the updated values from the device. I am using Galaxy S21 with Android version 13 and API 33 in my case what I get is
After all the above steps it should call "onCharacteristicChanged: " (BLE Manager)
@marcosinigaglia can you please tell me what could be the issue?
UPDATE
@marcosinigaglia Can you please change in the code or let me know how can I make a change so moving forward Android API level >=33 will work