|
| 1 | +import TCPConnection from "../src/connection/tcp_connection.js"; |
| 2 | +import NodeJSSerialConnection from "../src/connection/nodejs_serial_connection.js"; |
| 3 | + |
| 4 | +// create connection |
| 5 | +// const connection = new TCPConnection("10.1.0.75", 5000); |
| 6 | +const connection = new NodeJSSerialConnection("/dev/cu.usbmodem14401"); |
| 7 | + |
| 8 | +// wait until connected |
| 9 | +connection.on("connected", async () => { |
| 10 | + |
| 11 | + // we are now connected |
| 12 | + console.log("Connected"); |
| 13 | + |
| 14 | + // find contact |
| 15 | + // const contact = await connection.findContactByName("Liam's Solar Repeater"); |
| 16 | + // const contact = await connection.findContactByPublicKeyPrefix([0x93, 0x5c, 0x6b, 0x69]); |
| 17 | + // const contact = await connection.findContactByPublicKeyPrefix(Buffer.from("935c6b69", "hex")); |
| 18 | + const contact = await connection.findContactByPublicKeyPrefix(Buffer.from("935c6b694200644710a374c250c76f7aed9ec2ff3e60261447d4eda7c246ce5d", "hex")); |
| 19 | + if(!contact){ |
| 20 | + console.log("Contact not found"); |
| 21 | + await connection.close(); |
| 22 | + return; |
| 23 | + } |
| 24 | + |
| 25 | + // login to repeater (with empty guest password) |
| 26 | + console.log("Logging in..."); |
| 27 | + const res = await connection.login(contact.publicKey, ""); |
| 28 | + console.log("res", res); |
| 29 | + |
| 30 | + // get repeater neighbours |
| 31 | + console.log("Fetching neighbours..."); |
| 32 | + const neighbours = await connection.getNeighbours(contact.publicKey); |
| 33 | + console.log(neighbours); |
| 34 | + |
| 35 | + // disconnect |
| 36 | + await connection.close(); |
| 37 | + |
| 38 | +}); |
| 39 | + |
| 40 | +// connect to meshcore device |
| 41 | +await connection.connect(); |
0 commit comments