[web-bluetooth] Error while writing characteristic to BLE device (#518)

pix1289 has just created a new issue for https://github.com/WebBluetoothCG/web-bluetooth:

== Error while writing characteristic to BLE device ==
I need to write a encrypted value to a characteristic of a BLE device using Web Bluetooth API. I can log the service and the characteristic. But I am unable to write the value.

We are referring a python script which can successfully write to the characteristic. The data written is encrypted and then converted to byte array and written to the characteristic.

We are trying to write the same value via javascript to the characteristic but we are getting NotSupportedError. 

Sample code: 

`
navigator.bluetooth.requestDevice ({ 
    filters: [{ name: deviceName }],
    optionalServices: [GATT_SERVICE],
}).then((device) => {
    return device.gatt.connect();
}).then((server) => {
    return server.getPrimaryService(GATT_SERVICE);
}).then((service) => {
    return service.getCharacteristic(GATT_CHARACTERISTIC);
}).then((characteristic) => {
    writeBuffer(data, 0);
    function writeBuffer(data, start) {
        writeOut(data, start);
    }
    function writeOut(data, start) {
            if (start >= data.length) return;
            characteristic
              .writeValue(
                new TextEncoder().encode(data.substring(start, start + 20))
              )
              .then(() => {
                writeOut(data, start + 20);
              });
          }
})
.catch((error) => {
          console.log(error);
        })
`

Since the length is more than 512 bytes, I am taking a substring and trying to write the value. 

What could be the reason this is not working?

Please view or discuss this issue at https://github.com/WebBluetoothCG/web-bluetooth/issues/518 using your GitHub account


-- 
Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config

Received on Friday, 18 September 2020 14:22:37 UTC