From 3e4147b91712f5f2cbe0845ce80e6c36c7756f7f Mon Sep 17 00:00:00 2001 From: liamcottle Date: Fri, 26 Sep 2025 17:53:49 +1200 Subject: [PATCH] add example for fetching repeater neighbours --- examples/get_repeater_neighbours.js | 41 +++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 examples/get_repeater_neighbours.js diff --git a/examples/get_repeater_neighbours.js b/examples/get_repeater_neighbours.js new file mode 100644 index 0000000..4e87859 --- /dev/null +++ b/examples/get_repeater_neighbours.js @@ -0,0 +1,41 @@ +import TCPConnection from "../src/connection/tcp_connection.js"; +import NodeJSSerialConnection from "../src/connection/nodejs_serial_connection.js"; + +// create connection +// const connection = new TCPConnection("10.1.0.75", 5000); +const connection = new NodeJSSerialConnection("/dev/cu.usbmodem14401"); + +// wait until connected +connection.on("connected", async () => { + + // we are now connected + console.log("Connected"); + + // find contact + // const contact = await connection.findContactByName("Liam's Solar Repeater"); + // const contact = await connection.findContactByPublicKeyPrefix([0x93, 0x5c, 0x6b, 0x69]); + // const contact = await connection.findContactByPublicKeyPrefix(Buffer.from("935c6b69", "hex")); + const contact = await connection.findContactByPublicKeyPrefix(Buffer.from("935c6b694200644710a374c250c76f7aed9ec2ff3e60261447d4eda7c246ce5d", "hex")); + if(!contact){ + console.log("Contact not found"); + await connection.close(); + return; + } + + // login to repeater (with empty guest password) + console.log("Logging in..."); + const res = await connection.login(contact.publicKey, ""); + console.log("res", res); + + // get repeater neighbours + console.log("Fetching neighbours..."); + const neighbours = await connection.getNeighbours(contact.publicKey); + console.log(neighbours); + + // disconnect + await connection.close(); + +}); + +// connect to meshcore device +await connection.connect();