meshcore.js/examples/get_repeater_neighbours.js
2025-09-26 17:53:49 +12:00

41 lines
1.4 KiB
JavaScript

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();