Skip to content

Commit

Permalink
update bluetooth flow since we can't get pin until after pairing init…
Browse files Browse the repository at this point in the history
…iated from android side
  • Loading branch information
liamcottle committed Dec 19, 2024
1 parent c0f37e3 commit 028571e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 23 deletions.
3 changes: 2 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
46 changes: 24 additions & 22 deletions js/rnode.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`;
// }

}

Expand Down

0 comments on commit 028571e

Please sign in to comment.