Serial woes.. buffer issue?

I use node-red serial to interpret string messages from my "intelligent" burglar alarm system.
I have serial RX set to split input on character \r and this works fine until I reboot the system.
It then outputs nothing until I remove the \r . It then outputs all the individual characters and when I restore split input on \r all is good again. Is this some sort of buffer issue?

Are you sure it is removing the /r that fixes it? Have you tried just doing a Restart Flows (at the bottom of the Deploy button dropdown) or restarting node-red? Perhaps it is an issue acquiring or setting up the serial port on reboot.

It might also be worth specifying a timeout in the serial config so that it will give you something if there is a gap in the data even if no /r is seen for some reason (if there are gaps in the data).

An RPI reboot "kills" it every time but as you suggested restarting flows fixes it. Also I have a timeout of 10 seconds but it does not seem to help. I can now sort the problem with a flow restart but I would much prefer if serial worked each time on reboot.
thanks.

Reboot the pi (I presume that node red is auto-starting on boot) then, once it has had time to get all started up, run in a terminal
node-red-log
and you should see the node-red startup sequence that happened on boot. I suspect there will be some error shown there. Copy the whole output from node-red-log and paste it here. Use the </> button at the top of the forum edit window when pasting it here. Don't restart node-red before getting the log.

pi@atticPI:~ $ node-red-log


21 Sep 21:40:30 - [info] HTTP Static    : /home/pi/JMpics
21 Sep 21:40:30 - [info] Context store  : 'default' [module=localfilesystem]
21 Sep 21:40:30 - [info] User directory : /home/pi/.node-red
21 Sep 21:40:30 - [warn] Projects disabled : editorTheme.projects.enabled=false
21 Sep 21:40:30 - [info] Flows file     : /home/pi/.node-red/flows.json
21 Sep 21:40:30 - [info] Server now running at http://127.0.0.1:1880/
21 Sep 21:40:30 - [warn]
---------------------------------------------------------------------
Your flow credentials file is encrypted using a system-generated key.
If the system-generated key is lost for any reason, your credentials
file will not be recoverable, you will have to delete it and re-enter
your credentials.
You should set your own key using the 'credentialSecret' option in
your settings file. Node-RED will then re-encrypt your credentials
file using your chosen key the next time you deploy a change.
---------------------------------------------------------------------
21 Sep 21:40:30 - [info] Starting flows
21 Sep 21:40:30 - [info] [tcp out:telnet] connecting to localhost:7072
21 Sep 21:40:30 - [info] [tcp out:telnet] connecting to localhost:7072
21 Sep 21:40:31 - [info] Started flows
21 Sep 21:40:31 - [info] [sqlitedb:c37d97a8.1b07c8] opened /home/pi/dbs/iot.db ok
21 Sep 21:40:31 - [info] serial port /dev/ttyUSB0 opened at 9600 baud 8N1
21 Sep 21:40:31 - [info] [mqtt-broker:fc8b5c33.494e8] Connected to broker: mqtt://127.0.0.1:1883
21 Sep 21:40:31 - [info] [tcp out:telnet] connected to localhost:7072
21 Sep 21:40:31 - [info] [tcp out:telnet] connected to localhost:7072


Nothing obvious there, it is a pity the log has truncated the first lines. Can you leave the log running (or reopen it if you have closed it) and then restart node-red and post the restart output please.

Starting as a systemd service.
21 Sep 22:02:38 - [info]
Welcome to Node-RED
===================
21 Sep 22:02:38 - [info] Node-RED version: v1.0.3
21 Sep 22:02:38 - [info] Node.js  version: v10.22.0
21 Sep 22:02:38 - [info] Linux 5.4.51-v7l+ arm LE
21 Sep 22:02:38 - [info] Loading palette nodes
21 Sep 22:02:42 - [info] Dashboard version 2.23.3 started at /ui
21 Sep 22:02:42 - [info] Settings file  : /home/pi/.node-red/settings.js
21 Sep 22:02:42 - [info] HTTP Static    : /home/pi/JMpics
21 Sep 22:02:42 - [info] Context store  : 'default' [module=localfilesystem]
21 Sep 22:02:42 - [info] User directory : /home/pi/.node-red
21 Sep 22:02:42 - [warn] Projects disabled : editorTheme.projects.enabled=false
21 Sep 22:02:42 - [info] Flows file     : /home/pi/.node-red/flows.json
21 Sep 22:02:42 - [info] Server now running at http://127.0.0.1:1880/
21 Sep 22:02:42 - [warn]
---------------------------------------------------------------------
Your flow credentials file is encrypted using a system-generated key.
If the system-generated key is lost for any reason, your credentials
file will not be recoverable, you will have to delete it and re-enter
your credentials.
You should set your own key using the 'credentialSecret' option in
your settings file. Node-RED will then re-encrypt your credentials
file using your chosen key the next time you deploy a change.
---------------------------------------------------------------------
21 Sep 22:02:42 - [info] Starting flows
21 Sep 22:02:42 - [info] [tcp out:telnet] connecting to localhost:7072
21 Sep 22:02:43 - [info] [tcp out:telnet] connecting to localhost:7072
21 Sep 22:02:43 - [info] Started flows
21 Sep 22:02:43 - [info] [sqlitedb:c37d97a8.1b07c8] opened /home/pi/dbs/iot.db ok
21 Sep 22:02:43 - [info] serial port /dev/ttyUSB0 opened at 9600 baud 8N1
21 Sep 22:02:43 - [info] [mqtt-broker:fc8b5c33.494e8] Connected to broker: mqtt://127.0.0.1:1883
21 Sep 22:02:43 - [info] [tcp out:telnet] connected to localhost:7072
21 Sep 22:02:43 - [info] [tcp out:telnet] connected to localhost:7072


I can't see anything wrong there. It would be worth your while upgrading node-red, I think there were some issues with that version. I don't expect it to make a difference to your problem, but worth a try. You can run the pi install/upgrade script, or you can just run
sudo npm -g --unsafe-perm node-red

Also check that you have the latest version of node-red-node-serialport installed. You can check that in the Manage Palette feature.

When you reboot the pi are you restarting the device at the other end too?
Does the pi have to ask the other device for data or is it streaming all the time?

thanks I will do the upgrade. I'm not sure what has changed as in the past a reboot caused no problems.
The other device does not get rebooted and it streams data all the time.

I don't think you mentioned that previously, or I missed it. Something must have changed.

node-red now at v1.1.3 and serial up to date. Same problem that requires flow restart to fix it.
Looks like I'll just have to live with it.
thanks again

Is there a way to restart a flow using a dashboard button?

Let me count the ways.... https://discourse.nodered.org/search?q=restart%20flow

If you disable node red from starting automatically at boot
sudo systemctl disable nodered
and then reboot and then start node-red using
sudo systemct start nodered
is it ok? It may be that node-red is starting too early and something is getting messed up. The reason for saying to start node red in that way is to make sure it it will use the same systemd service to start up as it does on reboot.

Tried that and yes when I restart node-red serial works.

Are you using the standard systemd script installed using the pi install script from https://nodered.org/docs/getting-started/raspberrypi?

yes I am to the best of my knowledge

One possibility is to delay the node-red start for a bit on boot to allow whatever is not ready to settle down first. To do that create a file /lib/systemd/system/nodered.timer (note, no - in nodered) and put in there

[Unit]
Description=timer for starting nodered.service

[Timer]
OnBootSec=2min

[Install]
WantedBy=timers.target

That will create a timer that will start nodered 2 minutes after boot. Tell systemd to reload its files
sudo systemctl daemon-reload
Stop node red from starting by itself (as the timer will start it)
sudo systemctl disable nodered.service
and enable the timer so it starts running on boot, and will start nodered when it times out
sudo systemctl enable nodered.timer
Then reboot. Node red should start automatically two minutes after booting. You can change the time in the timer file obviously. See if that fixes it. If not you could try a longer time, if it does then perhaps 1 minute would be enough.

I did that and then serial stopped working altogether Then re-enabled normal node-red service and still no serial. Log looks normal. Will investigate further. Maybe have to re-install serial.

Did it delay node red from starting for two minutes? That is all it does so it shouldn't be any different to booting without node-red enabled and then starting it.

That won't make any difference. This is not Windows.

[Edit] If you re-enable the nodered service don't forget to disable the timer or it will try to start nodered a second time.