0
votes

I need advice on setting up a web server on a Raspberry Pi that can communicate with the serial port.

Im leaning towards doing this i php/python/nodejs or c if necessary.

Requirements: 1. incoming data on serial port => update webpage through web sockets 2. some event on webpage => send data to serial port

A continuous loop to check for serial data will be heavy on the cpu. Is there any way to get an event on incoming serial data and then read it? Found https://github.com/voodootikigod/node-serialport that has an on data event. Is that a good option?

Can the serial communication be handled by the web server or will i have to create a service?

1
"Can the serial communication be handled by the web server" -- I've only done one embedded web server (in C), but IIRC a CGI program is only invoked when an HTTP request is received (and should terminate after responding). Opening and closing the serial port for each request doesn't seem practical. An ongoing process to service the serial port makes much more sense. Choose an IPC method (pipes, share memory, files).sawdust
"A continuous loop to check for serial data will be heavy on the cpu" -- Blocking I/O (in a thread if necessary) takes care of that. There's also poll() and select().sawdust

1 Answers

0
votes

Best approach for me was to use node.js and https://github.com/voodootikigod/node-serialport in combination with socker.io. That gives men an event when serial data received that can be communicated via socket.