-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsend.js
More file actions
41 lines (34 loc) · 1.1 KB
/
send.js
File metadata and controls
41 lines (34 loc) · 1.1 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
37
38
39
40
41
import { WebSocket } from "ws";
import { Constants, Protobuf } from "@meshtastic/js";
// connect to meshtastic-websocket-proxy
const ws = new WebSocket("ws://127.0.0.1:8080");
// send a text message to default channel
ws.onopen = () => {
// create ToRadio message
const toRadio = new Protobuf.Mesh.ToRadio({
payloadVariant: {
case: "packet",
value: new Protobuf.Mesh.MeshPacket({
to: Constants.broadcastNum,
payloadVariant: {
case: "decoded",
value: {
portnum: Protobuf.Portnums.PortNum.TEXT_MESSAGE_APP,
payload: Buffer.from("Hello from NodeJS!"),
},
},
}),
},
});
// convert protobuf to base64
const protobuf = Buffer.from(toRadio.toBinary()).toString("base64");
console.log({
protobuf: protobuf,
to_radio: toRadio,
});
// send packet to radio via websocket
ws.send(JSON.stringify({
"type": "to_radio",
"protobuf": protobuf,
}));
};