'Error writing long string with Web Bluetooth Api and Electron
I have a somewhat simple electron app that is just trying to write a small string to a device.
I'm getting the error in the picture shown below:

GATT Error: Not supported.
The "off" command works perfectly and my device responds. The "on" command gives the error. I'm running a hex string through a small function in each instance that returns the hex string as an array buffer. I've included the function here just for reference. The only difference between the two calls is the length of the bytes. Is there any nuance that I'm missing trying to write a longer byte string through web bluetooth api?
function turnOn() {
console.log('on')
theVals = hexStringToArrayBuffer('FED35252C00E010B010101010000000000017200AFFC')
return myCharacteristic.writeValue(theVals)
}
function turnOff() {
console.log('off')
theVals = hexStringToArrayBuffer('FED3424cD003DF00004EFD')
return myCharacteristic.writeValue(theVals)
}
function hexStringToArrayBuffer(hexString) {
// remove the leading 0x
hexString = hexString.replace(/^0x/, '');
// ensure even number of characters
if (hexString.length % 2 != 0) {
console.log('WARNING: expecting an even number of characters in the hexString');
}
// check for some non-hex characters
var bad = hexString.match(/[G-Z\s]/i);
if (bad) {
console.log('WARNING: found non-hex characters', bad);
}
// split the string into pairs of octets
var pairs = hexString.match(/[\dA-F]{2}/gi);
// convert the octets to integers
var integers = pairs.map(function(s) {
return parseInt(s, 16);
});
var array = new Uint8Array(integers);
console.log(array);
return array.buffer;
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
