-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathsend_channel_message.js
More file actions
36 lines (27 loc) · 1.08 KB
/
send_channel_message.js
File metadata and controls
36 lines (27 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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();
// find channel
const channel = await connection.findChannelByName("Public");
// const channel = await connection.findChannelBySecret(Buffer.from("8b3387e9c5cdea6ac9e5edbaa115cd72", "hex"));
if(!channel){
console.log("Channel not found");
await connection.close();
return;
}
// send message to channel
console.log("Sending message...");
await connection.sendChannelTextMessage(channel.channelIdx, "Hello from MeshCore.js");
// disconnect
await connection.close();
});
// connect to meshcore device
await connection.connect();