meshcore.js/examples/get_contacts.js

30 lines
809 B
JavaScript
Raw Permalink Normal View History

2025-04-08 14:32:44 +12:00
import TCPConnection from "../src/connection/tcp_connection.js";
2025-04-08 12:14:21 +12:00
import NodeJSSerialConnection from "../src/connection/nodejs_serial_connection.js";
2025-04-08 14:41:59 +12:00
// create connection
2025-04-08 14:32:44 +12:00
// const connection = new TCPConnection("10.1.0.226", 5000);
2025-04-08 12:18:12 +12:00
const connection = new NodeJSSerialConnection("/dev/cu.usbmodem14401");
2025-04-08 12:14:21 +12:00
// wait until connected
connection.on("connected", async () => {
// we are now connected
console.log("Connected");
// log contacts
const contacts = await connection.getContacts();
for(const contact of contacts) {
console.log(`Contact: ${contact.advName}`);
}
// send message to public channel
// await connection.sendChannelTextMessage(0, "test");
// disconnect
await connection.close();
});
// connect to meshcore device
2025-04-08 12:18:12 +12:00
await connection.connect();