Reputation: 413
I'm trying to send a sample hex string to a BLE device via web bluetooth.
This string is sending perfectly fine on OSX, but when I attempt to send it on windows I'm getting the following error:
Uncaught (in promise) DOMException: GATT operation failed for unknown reason.
Here is the code I'm using to send the string and convert it:
event.target.writeValue(str2ab(":100000000C9434000C943E000C943E000C943E0082*"));
Here is my str2ab function:
function str2ab(str) {
var buf = new ArrayBuffer(str.length*2); // 2 bytes for each char
var bufView = new Uint16Array(buf);
for (var i=0, strLen=str.length; i<strLen; i++) {
bufView[i] = str.charCodeAt(i);
}
return buf;
}
Upvotes: 2
Views: 1018
Reputation: 413
So it looks like for windows you have a 20 byte limit.
To correct the issue I'm using a write buffer and recursively going over it until all the bites have been written. Here is the code.
function writeBuffer(string) {
writeOut(string, 0);
}
function writeOut(string, start) {
if(start >= string.length) return;
myCharacteristic.writeValue(str2ab(string.substring(start, (start+20)))).then(foo => {
writeOut(string, (start+20));
});
}
Upvotes: 1