I'm working on a project using the capacitor-community/bluetooth-le plugin to communicate with a Bluetooth device. I've encountered an issue where I need to pause listening to incoming Bluetooth notifications while executing a sub-routine triggered by a previous notification.
In my connect() function, I start listening to Bluetooth notifications using BleClient.startNotifications(). However, I've noticed that in certain scenarios, I need to temporarily block the plugin from listening to notifications while I perform a specific task in the openGate() function.
Here's a simplified version of the relevant code:
async connect() {
// ...
await BleClient.startNotifications(
this.connectedDeviceId,
READ_SERVICE,
READ_CHARACTERISTIC,
(value) => {
if (!shouldListenForNotifications) return;
let keypadNotification: number = dataViewToNumbers(value)[0];
this.openGate(keypadNotification);
}
);
}
async openGate(keypadNotification: number) {
if (keypadNotification === 1) {
shouldListenForNotifications = false;
setTimeout(async () => {
// Perform sub-routine
shouldListenForNotifications = true;
}, 0);
}
// ... (similar logic for other cases)
}
Is there a recommended approach to temporarily pause the Bluetooth notifications while executing the sub-routine? I want to ensure that I don't miss any notifications during the pause and that the communication remains reliable.
Any guidance, best practices, or suggestions would be greatly appreciated. Thank you in advance for your help!