mirror of
https://github.com/meshcore-dev/meshcore.js.git
synced 2026-04-20 22:13:49 +00:00
add nodejs serial example
This commit is contained in:
parent
a324e15553
commit
d5099eec20
2 changed files with 28 additions and 2 deletions
27
examples/nodejs_serial_connection.js
Normal file
27
examples/nodejs_serial_connection.js
Normal file
|
|
@ -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");
|
||||
|
|
@ -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));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue