Cant get serialport to work

I have a node red installed om a RPI3. I'a new to node red so maybe this is easy...

I try to use node-red-node-serialport to send serial request. When i hit deploy i get this debug message: "serial port /dev/ttyS0 error: Error: Error: Permission denied, cannot open /dev/ttyS0"

And when i try to run my flow the serial request node i get this: {"_msgid":"405525b5.e8422c","topic":"","request_payload":"A100","request_msgid":"405525b5.e8422c","port":"/dev/ttyS0","status":"ERR_TIMEOUT"}

My flow:
[{"id":"753a664c.ef994","type":"inject","z":"323daace.0f9796","name":"","topic":"","payload":"A100","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":310,"y":480,"wires":[["5ae185b8.cf4aa4"]]},{"id":"5ae185b8.cf4aa4","type":"serial request","z":"323daace.0f9796","name":"","serial":"a94ce253.ff6bd","x":440,"y":480,"wires":[["9b09df4b.b7662"]]},{"id":"9b09df4b.b7662","type":"debug","z":"323daace.0f9796","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":570,"y":480,"wires":[]},{"id":"a94ce253.ff6bd","type":"serial-port","z":"","serialport":"/dev/ttyS0","serialbaud":"9600","databits":"8","parity":"none","stopbits":"1","newline":"\\n","bin":"false","out":"char","addchar":false,"responsetimeout":"10000"}]

This python script works, so i know serial works in my pi:
import serial
ser = serial.Serial('/dev/ttyS0',9600)

while True:

Only one thing can access the serial port make sure nothing else is accessing it

I have turned off bluetooth and reboot the pi. But I get the same result that's what you mean...

The error shows you exactly what is wrong.

The user id you are using to run Node-RED does not have rights to the serial ports.

Check the permissions on /dev/ttyS0 by issuing the command ls -l /dev/ttyS0 from a command prompt. You will see the owning user followed by the group. Make sure that the user id running Node-RED is in the group. Then restart Node-RED.

Okay thanks. When i run ls -l /dev/ttyS0 I get: crw--w---- 1 root tty 4, 64 Jan 12 14:02 /dev/ttyS0

There is a user called nodered so I added that to tty by running usermod -a -G tty nodered, but no luck.

what user are you when you start Node-RED ?

with those permissions - even the tty group only has write access which doesn't seem right. What created that serial port in the first place ?

I use DietPi and installed node-red via dietpi-software. So I guess user nodered is running node-red. But I don't know

Did you configure/enable the serialport correctly via the DietPi software ? Does it work OK outside of Node-RED ?

I installed serialport from "Manage Palette" in node-red. And i've tested so many things so I don't know any more what i've done and what was done by the installation process. Yes i tested with this simple python script and it works:
import serial
ser = serial.Serial('/dev/ttyS0',9600)

while True:

I solved it. It's a litle embarrassing. But i run this chmod a+rw /dev/ttyS0 so it was an access thing. I thought I've done that but clearly no. Thanks for the help :grinning:

1 Like

Generally, serial and USB ports should belong to the "dialout" group:

crw-rw---- 1 root dialout 188,  0 Jan 13 14:14 /dev/ttyUSB0

That's what most people would expect I think. Rather than adding your Node-RED user to tty which isn't especially safe.

When i run the command ls -l /dev/ttyS0 I can see follwoing

what could be the solution change the group for serial port from tty to dialout or anything else i should try,
while finding the solution i find out that people are chasing this issue since 2016 i hope some of then have found something. thanks

You can simply add the user running Node-RED to the tty group.

On Debian:

sudo adduser reduser tty

Just note that you will have to log the reduser (or whatever user is running Node-RED) out and back in again.

However, I don't think ttyS0 should have a group ownership of tty, it is not usual on any version of Linux I'm familiar with. While other real tty devices are root/tty owned, the serial ports should all be root/dialout.

So what I would actually do is change the ownership and add the user to the dialout group.

sudo chown root:dialout /dev/ttyS*
sudo adduser reduser dialout

This will give you a more standard configuration and it is generally more secure as well.

SystemGroups - Debian Wiki

Do you have a reference? Which version of Linux?