From d5099eec2045700a506f8a918bd06573b6d37ed1 Mon Sep 17 00:00:00 2001 From: liamcottle Date: Tue, 8 Apr 2025 12:14:21 +1200 Subject: [PATCH] add nodejs serial example --- examples/nodejs_serial_connection.js | 27 +++++++++++++++++++++++++ src/connection/web_serial_connection.js | 3 +-- 2 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 examples/nodejs_serial_connection.js diff --git a/examples/nodejs_serial_connection.js b/examples/nodejs_serial_connection.js new file mode 100644 index 0000000..2ecb353 --- /dev/null +++ b/examples/nodejs_serial_connection.js @@ -0,0 +1,27 @@ +import NodeJSSerialConnection from "../src/connection/nodejs_serial_connection.js"; + +// create tcp connection +const connection = new NodeJSSerialConnection(); + +// 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 +await connection.connect("/dev/cu.usbmodem14401"); diff --git a/src/connection/web_serial_connection.js b/src/connection/web_serial_connection.js index 803ad1d..c289c27 100644 --- a/src/connection/web_serial_connection.js +++ b/src/connection/web_serial_connection.js @@ -63,8 +63,7 @@ class WebSerialConnection extends SerialConnection { } - // override - async write(bytes) { + /* override */ async write(bytes) { const writer = this.writable.getWriter(); try { await writer.write(new Uint8Array(bytes));