Search code examples
javascriptgoogle-chromebluetootharduinoweb-bluetooth

Web bluetooth API characteristic notification on Bluno board is not supported?


TL;DR;

My question is:

  1. Is the Web bluetooth API from https://developer.mozilla.org/en-US/docs/Web/API/Bluetooth not fully supporting some custom devices like Arduino boards at this moment? Because I got an DOMException: GATT Error: Not supported. exception when I try to use BluetoothRemoteGATTCharacteristic.startNotifications() to my Bluno Beetle board.

  2. If startNotifications() is fully implemented. Then, is there any extra settings on my Bluno board needed to be configured in order to make the notification working? From most online examples, there is no mention about extra settings on the devices before using this method. And I have checked the notify properties of target characteristic is true during runtime. It should not be the reason of having this exception as stated in https://webbluetoothcg.github.io/web-bluetooth/ :

    If neither of the Notify or Indicate bits are set in characteristic’s properties, reject promise with a NotSupportedError and abort these steps.
    

My case:

I am trying to build a little web demo on chrome that can output the text transmitted from my Bluno Beetle v1.0 board.

Program inside my board is very simple:

void setup() {
    Serial.begin(115200);  //initial the Serial
}

void loop() {
    Serial.write("hello world");
    Serial.println();
    delay(500);
}

I am using web bluetooth API from developer.mozilla.org

// UUID using by Bluno Beetle
var RXTX_SERVICE = 0xdfb0;
var RXTX_CHARACTERISTIC = 0xdfb2;

function handleCharacteristicValueChanged(event) {
    var value = event.target.value;
}

navigator.bluetooth.requestDevice({ acceptAllDevices: true, optionalServices: [RXTX_SERVICE] })
.then(device => { console.log(device); return device.gatt.connect(); })
.then(server => { return server.getPrimaryService(RXTX_SERVICE); })
.then(service => { return service.getCharacteristic(RXTX_CHARACTERISTIC); })
.then(ch => { console.log(ch); 
    ch.addEventListener('characteristicvaluechanged', handleCharacteristicValueChanged);
    console.log('Notifications have been started.');
    return ch;
})
.then(ch => { return ch.startNotifications() })
.catch(error => { console.log(error); });

Everything goes quite well, however, I got this exception when execute the line: ch.startNotifications()

DOMException: GATT Error: Not supported.

I tried using an iOS/Android APP to do the same task and both APPs are working with the notification of changes in that characteristic. So I assume my Bluno board is working normally in some configuration. But I cannot find web bluetooth API is useful for me to overcome this.

Any help would be appreciated! Thanks.


Solution

  • Web Bluetooth supports fully GATT Notifications.

    According to https://evothings.com/writing-your-first-mobile-application-for-the-bluno-micro-controller-by-dfrobot/, it looks like the RXTX characteristic is 0xdfb1 no 0xdfb2.