Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 3963

Troubleshooting • Arduino data --> rasperryPi5 --> nodejs webserver

$
0
0
I'm trying to read data from the UART GPIO pin from my raspberry pi 5 and display the read data on a webpage hosted on the pi. I keep getting the same error, and cant find anything that solves it.

Code here is from server.js

Code:

const { SerialPort } = require('serialport');const ReadlineParser = require('@serialport/parser-readline');const express = require('express');const http = require('http');const WebSocket = require('ws');const app = express();const port = 3000; // Port for your server;var Serialport  = new SerialPort('/dev/ttyAMA0',{baudRate:9600,dataBits:8,parity: 'none',flowControl: false});const parser = Serialport.pipe(new ReadlineParser({ delimiter: '\r\n' }));// Create an HTTP serverconst server = http.createServer(app);// Create a WebSocket server attached to the HTTP serverconst wss = new WebSocket.Server({ server });// Define the route to serve the HTML pageapp.get('/', (req, res) => {  res.sendFile(__dirname + '/index.html');});// Start listening to UART dataparser.on('open', function(data) {  console.log('Serial port is open');  parser.on('data', (data) => {    console.log('Received data from UART:', data);    // Broadcast the received data to all WebSocket clients    wss.clients.forEach((client) => {      if (client.readyState === WebSocket.OPEN) {        client.send(data);      }    });  });});// Start the HTTP serverserver.listen(port, () => {  console.log(`Server listening at http://localhost:${port}`);});
the error i am getting :

Code:

pi@raspberrypi:~/Documents/Webserver $ node server.js/home/pi/Documents/Webserver/node_modules/@serialport/stream/dist/index.js:57            throw new TypeError(`"path" is not defined: ${settings.path}`);            ^TypeError: "path" is not defined: undefined    at new SerialPortStream (/home/pi/Documents/Webserver/node_modules/@serialport/stream/dist/index.js:57:19)    at new SerialPort (/home/pi/Documents/Webserver/node_modules/serialport/dist/serialport.js:15:9)    at Object.<anonymous> (/home/pi/Documents/Webserver/server.js:11:19)    at Module._compile (node:internal/modules/cjs/loader:1356:14)    at Module._extensions..js (node:internal/modules/cjs/loader:1414:10)    at Module.load (node:internal/modules/cjs/loader:1197:32)    at Module._load (node:internal/modules/cjs/loader:1013:12)    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:128:12)    at node:internal/main/run_main_module:28:49
i have enabled the seriel port in preferences/Raspberry Pi Configuration/ interface. I have tried giving my user dialout status.

Statistics: Posted by Asger774 — Thu Mar 21, 2024 7:16 pm



Viewing all articles
Browse latest Browse all 3963

Trending Articles