// const { SerialPort } = require('serialport') // // Create a port // const port = new SerialPort({ // path: 'COM7', // baudRate: 9600, // }) // port.on('readable', function () { // console.log('Data:', port.read()) // }) // // Switches the port into "flowing mode" // port.on('data', function (data) { // console.log('Data:', data.toString('UTF8')) // }) const { SerialPort } = require('serialport') const { ReadlineParser } = require('@serialport/parser-readline') const http = require('node:http'); const port = new SerialPort({ path: 'COM7', baudRate: 9600 }) var value_arduino = ""; const parser = port.pipe(new ReadlineParser({ delimiter: '\r\n' })) parser.on('data', (data=> { if (value_arduino != data) { console.log(data); } value_arduino=data; })); // Create a local server to receive data from const server = http.createServer((req, res) => { res.writeHead(200, { 'Content-Type': 'application/json' }); res.end(value_arduino); }) server.listen(2048);