Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Communicate via BT Browser API #41

Open
deltasystems-pl opened this issue Dec 3, 2020 · 1 comment
Open

Communicate via BT Browser API #41

deltasystems-pl opened this issue Dec 3, 2020 · 1 comment

Comments

@deltasystems-pl
Copy link

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?

@t-mon
Copy link
Member

t-mon commented Dec 3, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants