[Solved] Serial node not working in node-red 1.0.2

I migrated my flows from node-red 0.17.x to 1.0.2 and my serial node is now behaving strangely.

When I boot up the raspberry pi (Linux version 4.19.75-v7+ (dom@buildbot) (gcc version 4.9.3 (crosstool-NG crosstool-ng-1.22.0-88-g8460611)) #1270 SMP Tue Sep 24 18:45:11 BST 2019), the serial node can't communicate with the device. It waits and then times out.

However, when I move a node and deploy, it starts working normally.

When I reboot again, same problem. Has anyone seen this?

Start node red in a terminal, then re-deploy. Post the terminal log here (copy/paste not screenshot if possible please). That is the log with the Welcome to node-RED message.

Tried to get a log showing the issue, but I can't reproduce the problem when I start from a command line. I have node-red configured to start at boot time, using this command:

sudo systemctl enable nodered.service

When I did a hard restart (power off and on), the serial port was hanging, as expected. I started a terminal session and ran "node-red-stop", then "node-red-start". The serial port problem went away.

So, I ran sudo systemctl disable nodered.service and did a hard restart. I started a terminal session, ran node-red-start, and...the serial port was working.

It seems that the only time it doesn't work is when I auto-start node-red at boot time. It's as if something isn't getting setup in time.

Reboot (with it enabled obviously) and look in /var/log/syslog. You will find the node red log there.

log200lines.txt (21.2 KB)

Did you look at the log? looks like you have an error in your exec node. I'd fix that and try again.

Yes, I looked. That error is unrelated. It happens when I run it on older versions of node-red, as well. But the serial port works on the older versions.

Same exact behavior on Raspberry Pi 4. Prior tests were with Raspberry Pi model 3 B+.

Did you also upgrade the version of node.js ? If so did you npm rebuild the serialport node as it has a binary component.

I'm using nodejs v10.17.0. I did a clean install of buster and then (after sudo apt update/upgrade) I ran update-nodejs-and-nodered. Is there a step that I missed?

You don't appear to have posted the relevant bit of the log. Look for the Welcome to node red message, it is from just before there, through it not working and then working after a deploy that we want.
The shutdown at 11:15 looks a bit odd, did you just power off?

cp: cannot stat '/media/pi//wpa_supplicant.conf': No such file or directory

You have two slashes in the path. I would fix that.

I'm perfectly aware of the path issue. It is not related to the serial port problem.

So I ended up backing down to 0.20.5, which works fine. There's an issue here, and I'll be happy to continue working on it, if you want my assistance.

Yes please. Just struggling to know what to suggest to try to isolate the problem. Not seen it here.

@dceejay if it's help, it seems to be an issue with serialport 0.8.8

So does updating the underlying library fix it for both docker and non-docker?

I'm trying to debug this problem. I'm now using a Raspberry Pi 4 with Raspbian GNU/Linux 10 (buster) Release: 10 and node-red 1.0.2. The symptom is still that the serial node waits and times out until I move a node and deploy, and then it magically works.

I ran a couple of commands to look at the serial ports, starting with:

dmesg | grep tty

which returns

[    0.000000] Kernel command line: coherent_pool=1M 8250.nr_uarts=1 cma=64M cma=256M video=HDMI-A-1:1440x900M@60,margin_left=0,margin_right=0,margin_top=0,margin_bottom=0 smsc95xx.macaddr=DC:A6:32:32:F2:1F vc_mem.mem_base=0x3ec00000 vc_mem.mem_size=0x40000000  console=ttyS0,115200 console=tty1 root=/dev/mmcblk0p7 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait
[    0.000709] console [tty1] enabled
[    1.032885] fe201000.serial: ttyAMA0 at MMIO 0xfe201000 (irq = 34, base_baud = 0) is a PL011 rev2
[    1.037484] console [ttyS0] disabled
[    1.038934] fe215040.serial: ttyS0 at MMIO 0x0 (irq = 36, base_baud = 62500000) is a 16550
[    1.104443] console [ttyS0] enabled

I'm using /dev/ttyS0 in my serial node, configured to 19200-8N1. Then I ran

setserial -g /dev/ttyS[0123]

which returned:

/dev/ttyS0, UART: 16550, Port: 0x0000, IRQ: 36

Not sure if any of that is helpful. I'm trying to get logs but I haven't found the one that contains the text that you see when you run node-red-start.

Try node-red-log command.

OK, here's the log you requested.

nr-log.txt (18.0 KB)

looks ok

[info] serial port /dev/ttyS0 opened at 19200 baud 8N1

but you have some other errors that are probably worth looking at

Nov 14 19:27:06 raspberrypi Node-RED[366]: 14 Nov 19:27:06 - [info] [exec:1a703c44.1790c4] error:Error: Command failed: sudo rm /home/pi/hvo/data/lpmflow.*
Nov 14 19:27:06 raspberrypi Node-RED[366]: rm: cannot remove '/home/pi/hvo/data/lpmflow.*': No such file or directory
Nov 14 19:27:06 raspberrypi Node-RED[366]: 14 Nov 19:27:06 - [error] [function:Get PSI, Purity & Settings] TypeError: Cannot read property 'temperature' of undefined
Nov 14 19:27:07 raspberrypi Node-RED[366]: 14 Nov 19:27:07 - [error] [function:Get PSI, Purity & Settings] TypeError: Cannot read property 'temperature' of undefined
Nov 14 19:27:10 raspberrypi Node-RED[366]: 14 Nov 19:27:10 - [error] [http request:ff600b9a.6e3b58] Error: getaddrinfo EAI_AGAIN seeingeye.highvolumeoxygen.com seeingeye.highvolumeoxygen.com:443
Nov 14 19:27:10 raspberrypi Node-RED[366]: 14 Nov 19:27:10 - [error] [http request:ff600b9a.6e3b58] Error: getaddrinfo EAI_AGAIN seeingeye.highvolumeoxygen.com seeingeye.highvolumeoxygen.com:443