Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add functionality to connect to serial via NodeJS #98

66 changes: 66 additions & 0 deletions example/nodeSerial/example.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,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);
});
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@meshtastic/js",
"version": "2.3.7-0",
"version": "2.3.7-1",
"description": "Browser library for interfacing with meshtastic devices",
"license": "GPL-3.0-only",
"scripts": {
Expand Down Expand Up @@ -35,7 +35,8 @@
"dependencies": {
"crc": "^4.3.2",
"ste-simple-events": "^3.0.11",
"tslog": "^4.9.2"
"tslog": "^4.9.2",
"serialport": "^12.0.0"
},
"devDependencies": {
"@biomejs/biome": "^1.6.3",
Expand Down
Loading
Loading