Skip to content

Commit

Permalink
arduino service added
Browse files Browse the repository at this point in the history
  • Loading branch information
Kalvinci committed Apr 8, 2022
1 parent f661b78 commit 4834db4
Show file tree
Hide file tree
Showing 4 changed files with 498 additions and 2 deletions.
22 changes: 22 additions & 0 deletions arduinoService.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const { SerialPort } = require("serialport");
require("dotenv").config();

const arduinoSerialPort = new SerialPort({
path: process.env.PORT_PATH,
baudRate: 9600,
});

arduinoSerialPort.on("open", () => {
console.log("Serial Port is open");
});

function writeToSerialPort(jsonData) {
try {
arduinoSerialPort.write(jsonData);
} catch (error) {
console.log(error);
throw new Error("Arduino error");
}
}

exports.writeToSerialPort = writeToSerialPort;
Loading

0 comments on commit 4834db4

Please sign in to comment.