forked from meshtastic/js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.js
66 lines (53 loc) · 1.9 KB
/
example.js
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import { SerialPort } from "serialport";
import { NodeSerialConnection } from "./dist/index.js";
const Connect = async () => {
const connection = new NodeSerialConnection();
// COM4 is the port that works for me, you'll have to get your path from SerialPort.list()
await connection.connect({
portPath: "COM4",
concurrentLogOutput: false,
});
console.log(await SerialPort.list());
connection.events.onMessagePacket.subscribe((packet) => {
onMessage(packet.from, packet.data);
});
connection.events.onPrivatePacket.subscribe((packet) => {
onMessage(packet.from, packet.data);
});
connection.events.onLogEvent.subscribe((packet) => {
console.log("LogEvent: ", packet);
});
connection.events.onDeviceMetadataPacket.subscribe((packet) => {
console.log("DeviceMetadataPacket: ", packet);
});
connection.events.onDeviceDebugLog.subscribe((packet) => {
console.log("DeviceDebugLog: ", packet);
});
connection.events.onFromRadio.subscribe((packet) => {
console.log("FromRadio: ", packet);
});
connection.events.onDeviceStatus.subscribe((packet) => {
console.log("DeviceStatus: ", packet);
});
connection.events.onMyNodeInfo.subscribe((packet) => {
console.log("NodeInfo: ", packet);
});
const onMessage = (sender, message) => {
console.log(`Message from: ${sender}`);
console.log(`Message was: ${message}`);
};
connection.events.onRemoteHardwarePacket.subscribe((packet) => {
console.log("Remote Hardware Packet: ", packet);
});
connection.events.onRoutingPacket.subscribe((packet) => {
console.log("Routing packet: ", packet);
});
connection.events.onConfigPacket.subscribe((packet) => {
console.log("Config: ", packet);
});
// Request configuration data from device (I think this will help trigger other serial events being processed)
await connection.configure();
};
Connect().catch((err) => {
console.log(err);
});