From 028571e6ace78de148d6d9a5f1807f4e9a177f3e Mon Sep 17 00:00:00 2001 From: liamcottle Date: Thu, 19 Dec 2024 23:23:14 +1300 Subject: [PATCH] update bluetooth flow since we can't get pin until after pairing initiated from android side --- index.html | 3 ++- js/rnode.js | 46 ++++++++++++++++++++++++---------------------- 2 files changed, 26 insertions(+), 23 deletions(-) diff --git a/index.html b/index.html index 2b38d8b..57ef7cc 100644 --- a/index.html +++ b/index.html @@ -1750,11 +1750,12 @@ console.log("start bluetooth pairing"); const pin = await rnode.startBluetoothPairing(); console.log("start bluetooth pairing: done"); - alert(`Bluetooth Pairing Pin: ${pin}`); } catch(error) { alert(error); } + alert("RNode should now be in Bluetooth Pairing mode. A pin will be shown on the screen when you pair with it from Android bluetooth settings."); + // done await rnode.close(); diff --git a/js/rnode.js b/js/rnode.js index 9ce3d7a..9fe0233 100644 --- a/js/rnode.js +++ b/js/rnode.js @@ -544,28 +544,30 @@ class RNode { 0x02, // enable pairing ]); - // attempt to get bluetooth pairing pin - try { - - // read response from device - const [ command, ...pinBytes ] = await this.readFromSerialPort(5000); - if(command !== this.CMD_BT_PIN){ - throw `unexpected command response: ${command}`; - } - - // convert 4 bytes to 32bit integer - const pin = pinBytes[0] << 24 | pinBytes[1] << 16 | pinBytes[2] << 8 | pinBytes[3]; - - // todo: remove logs - console.log(pinBytes); - console.log(pin); - - // todo: convert to string - return pin; - - } catch(error) { - throw `failed to get bluetooth pin: ${error}`; - } + // todo: listen for packets, pin will be available once user has initiated pairing from Android device + + // // attempt to get bluetooth pairing pin + // try { + // + // // read response from device + // const [ command, ...pinBytes ] = await this.readFromSerialPort(5000); + // if(command !== this.CMD_BT_PIN){ + // throw `unexpected command response: ${command}`; + // } + // + // // convert 4 bytes to 32bit integer + // const pin = pinBytes[0] << 24 | pinBytes[1] << 16 | pinBytes[2] << 8 | pinBytes[3]; + // + // // todo: remove logs + // console.log(pinBytes); + // console.log(pin); + // + // // todo: convert to string + // return pin; + // + // } catch(error) { + // throw `failed to get bluetooth pin: ${error}`; + // } }