Skip to content

Instantly share code, notes, and snippets.

@zoutepopcorn
Created February 17, 2023 10:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zoutepopcorn/09db89f3af9991f759725bd9f9269ee5 to your computer and use it in GitHub Desktop.
Save zoutepopcorn/09db89f3af9991f759725bd9f9269ee5 to your computer and use it in GitHub Desktop.
const serialport = require('serialport');
const SerialPort = serialport.SerialPort;
const PORT = "/dev/ttyUSB0";
serialPort = new SerialPort({
path: PORT,
baudRate: 115200,
});
serialPort.on("open", () => {
console.log("-- Connection opened --");
serialPort.on("data", (data) => {
const SERIAL_IN = data.toString();
const [from, command] = SERIAL_IN.split("::").filter(Boolean);
console.log(`from: \t\t${from}`);
console.log(`command: \t${command}`);
});
});
{
"name": "serial",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"serialport": "^10.5.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment