nymea-networkmanager icon indicating copy to clipboard operation
nymea-networkmanager copied to clipboard

Communicate via BT Browser API

Open deltasystems-pl opened this issue 3 years ago • 1 comments

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?

deltasystems-pl avatar Dec 03 '20 22:12 deltasystems-pl