1

I am using the code in the example https://googlechrome.github.io/samples/web-bluetooth/notifications.html to subscribe to notifications from my bluetooth device.

 return myCharacteristic.startNotifications().then(_ => {
  log('> Notifications started');
  myCharacteristic.addEventListener('characteristicvaluechanged', handleNotifications);
});

When I do startNotification my bluetooth device recognizes the notification request and responds with the buffer transmission back to web, however it seems that because it responds IMMEDIATELY after startNotification() is called the web is not ready to accept the notification and it is missed completely.

I tried moving the characteristic event listener before startNotification like so:

myCharacteristic.addEventListener('characteristicvaluechanged', handleNotifications);
return myCharacteristic.startNotifications().then(_ => {
  log('> Notifications started');
});

but that didn't seem to help help.

If I put a setTimeout of even 1 millisecond on my bluetooth device before transmitting back the web event listener picks up the notifications no problem.

I would much rather make a change to my web bluetooth code than change my bluetooth device's code, any ideas of things to try?

russter
  • 133
  • 1
  • 8

0 Answers0