Cant get serialport to work

#1

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:
`#!/user/bin/python
import serial
ser = serial.Serial('/dev/ttyS0',9600)

while True:
ser.write('A100')`

0 Likes

#2

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

0 Likes

#3

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

0 Likes

#4

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.

0 Likes

#5

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.

0 Likes

#6

what user are you when you start Node-RED ?

0 Likes

#7

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 ?

0 Likes

#8

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

0 Likes

#9

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

0 Likes

#10

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:
#!/user/bin/python
import serial
ser = serial.Serial('/dev/ttyS0',9600)

while True:
ser.write('A100')

0 Likes

#11

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

#12

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.

0 Likes