mirror of
https://github.com/meshcore-dev/meshcore.js.git
synced 2026-04-20 22:13:49 +00:00
add example to send message to channel
This commit is contained in:
parent
15ca8fc660
commit
f5dc7c95f6
1 changed files with 27 additions and 0 deletions
27
examples/send_channel_message.js
Normal file
27
examples/send_channel_message.js
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
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.226", 5000);
|
||||
const connection = new NodeJSSerialConnection("/dev/cu.usbmodem14401");
|
||||
|
||||
// wait until connected
|
||||
connection.on("connected", async () => {
|
||||
|
||||
// we are now connected
|
||||
console.log("Connected");
|
||||
|
||||
// update clock on meshcore device
|
||||
await connection.syncDeviceTime();
|
||||
|
||||
// send message to channel 0
|
||||
console.log("Sending message...");
|
||||
await connection.sendChannelTextMessage(0, "Hello from MeshCore.js");
|
||||
|
||||
// disconnect
|
||||
await connection.close();
|
||||
|
||||
});
|
||||
|
||||
// connect to meshcore device
|
||||
await connection.connect();
|
||||
Loading…
Add table
Add a link
Reference in a new issue