mirror of
https://github.com/meshcore-dev/meshcore.js.git
synced 2026-04-20 22:13:49 +00:00
add example for fetching repeater neighbours
This commit is contained in:
parent
5e2df84d9b
commit
3e4147b917
1 changed files with 41 additions and 0 deletions
41
examples/get_repeater_neighbours.js
Normal file
41
examples/get_repeater_neighbours.js
Normal file
|
|
@ -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();
|
||||
Loading…
Add table
Add a link
Reference in a new issue