nymea-networkmanager
nymea-networkmanager copied to clipboard
Communicate via BT Browser API
After sending a cmd to RPi i got this warning in network manager and no response
W | NetworkManagerBluetoothServer: Got invalid json object "{c:0}\n"
My JS code:
button.addEventListener('pointerup', function(event) {
navigator.bluetooth.requestDevice({
acceptAllDevices: true,
optionalServices: [
'ef6d6610-b8af-49e0-9eca-ab343513641c',
'00001801-0000-1000-8000-00805f9b34fb',
'e081fec0-f757-4449-b9c9-bfa83133f7fc',
'00001800-0000-1000-8000-00805f9b34fb',
'0000180a-0000-1000-8000-00805f9b34fb'
]
})
.then(device => device.gatt.connect())
.then(server => {
// Getting Battery Service…
return server.getPrimaryService('e081fec0-f757-4449-b9c9-bfa83133f7fc');
})
.then(service => {
// Getting Battery Level Characteristic…
return service.getCharacteristic('e081fec1-f757-4449-b9c9-bfa83133f7fc');
})
.then(characteristic => {
let encoder = new TextEncoder('utf-8');
return characteristic.writeValue(encoder.encode({'c': 0}+'\n'));
})
.then(value => {
console.log( new TextDecoder("utf-8").decode(value));
})
.catch(error => { console.error(error); });
});
Do I something wrong? Have someone try to use Browser BT API to set WLAN on RPi?
Looks like the received byte array does not contain valid json data.
Try to send
encoder.encode({"c": 0}+'\n')
or
encoder.encode('{"c": 0}'+'\n')
not sure about the syntax...
but the receiving string should actually look like this: {"c": 0}\n