# Serial woes.. buffer issue?

**URL:** <https://discourse.nodered.org/t/serial-woes-buffer-issue/33141>\
**Category:** General\
**Created:** [21 September 2020 09:12 UTC](https://discourse.nodered.org/t/serial-woes-buffer-issue/33141 "2020-09-21T09:12:17Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![muggins](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/muggins/32/63013_2.png) [@muggins](https://discourse.nodered.org/u/muggins)\
**Post date:** [21 September 2020 09:12 UTC](https://discourse.nodered.org/t/serial-woes-buffer-issue/33141/1 "2020-09-21T09:12:17Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [21 September 2020 09:27 UTC](https://discourse.nodered.org/t/serial-woes-buffer-issue/33141/2 "2020-09-21T09:27:22Z")

</div>

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).

---

<div class="post-metadata">

**Author:** ![muggins](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/muggins/32/63013_2.png) [@muggins](https://discourse.nodered.org/u/muggins)\
**Post date:** [21 September 2020 17:05 UTC](https://discourse.nodered.org/t/serial-woes-buffer-issue/33141/3 "2020-09-21T17:05:53Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [21 September 2020 20:24 UTC](https://discourse.nodered.org/t/serial-woes-buffer-issue/33141/4 "2020-09-21T20:24:35Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![muggins](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/muggins/32/63013_2.png) [@muggins](https://discourse.nodered.org/u/muggins)\
**Post date:** [21 September 2020 20:44 UTC](https://discourse.nodered.org/t/serial-woes-buffer-issue/33141/5 "2020-09-21T20:44:07Z")

</div>

```auto
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

```

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [21 September 2020 20:50 UTC](https://discourse.nodered.org/t/serial-woes-buffer-issue/33141/6 "2020-09-21T20:50:56Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![muggins](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/muggins/32/63013_2.png) [@muggins](https://discourse.nodered.org/u/muggins)\
**Post date:** [21 September 2020 21:05 UTC](https://discourse.nodered.org/t/serial-woes-buffer-issue/33141/7 "2020-09-21T21:05:09Z")

</div>

```auto
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

```

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [21 September 2020 21:15 UTC](https://discourse.nodered.org/t/serial-woes-buffer-issue/33141/8 "2020-09-21T21:15:49Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![muggins](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/muggins/32/63013_2.png) [@muggins](https://discourse.nodered.org/u/muggins)\
**Post date:** [21 September 2020 21:24 UTC](https://discourse.nodered.org/t/serial-woes-buffer-issue/33141/9 "2020-09-21T21:24:59Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [21 September 2020 21:27 UTC](https://discourse.nodered.org/t/serial-woes-buffer-issue/33141/10 "2020-09-21T21:27:33Z")

</div>

> [@muggins](#):
>
> I'm not sure what has changed as in the past a reboot caused no problems.

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

---

<div class="post-metadata">

**Author:** ![muggins](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/muggins/32/63013_2.png) [@muggins](https://discourse.nodered.org/u/muggins)\
**Post date:** [21 September 2020 21:49 UTC](https://discourse.nodered.org/t/serial-woes-buffer-issue/33141/11 "2020-09-21T21:49:43Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![muggins](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/muggins/32/63013_2.png) [@muggins](https://discourse.nodered.org/u/muggins)\
**Post date:** [22 September 2020 07:46 UTC](https://discourse.nodered.org/t/serial-woes-buffer-issue/33141/12 "2020-09-22T07:46:20Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [22 September 2020 07:49 UTC](https://discourse.nodered.org/t/serial-woes-buffer-issue/33141/13 "2020-09-22T07:49:16Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [22 September 2020 07:54 UTC](https://discourse.nodered.org/t/serial-woes-buffer-issue/33141/14 "2020-09-22T07:54:59Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![muggins](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/muggins/32/63013_2.png) [@muggins](https://discourse.nodered.org/u/muggins)\
**Post date:** [22 September 2020 08:23 UTC](https://discourse.nodered.org/t/serial-woes-buffer-issue/33141/15 "2020-09-22T08:23:11Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [22 September 2020 08:43 UTC](https://discourse.nodered.org/t/serial-woes-buffer-issue/33141/16 "2020-09-22T08:43:04Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![muggins](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/muggins/32/63013_2.png) [@muggins](https://discourse.nodered.org/u/muggins)\
**Post date:** [22 September 2020 09:01 UTC](https://discourse.nodered.org/t/serial-woes-buffer-issue/33141/17 "2020-09-22T09:01:44Z")

</div>

yes I am to the best of my knowledge

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [22 September 2020 09:33 UTC](https://discourse.nodered.org/t/serial-woes-buffer-issue/33141/18 "2020-09-22T09:33:23Z")

</div>

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

```auto
[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.

---

<div class="post-metadata">

**Author:** ![muggins](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/muggins/32/63013_2.png) [@muggins](https://discourse.nodered.org/u/muggins)\
**Post date:** [22 September 2020 13:19 UTC](https://discourse.nodered.org/t/serial-woes-buffer-issue/33141/19 "2020-09-22T13:19:19Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [22 September 2020 14:44 UTC](https://discourse.nodered.org/t/serial-woes-buffer-issue/33141/20 "2020-09-22T14:44:37Z")

</div>

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.

> [@muggins](#):
>
> Maybe have to re-install serial.

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.

[Next page](https://discourse.nodered.org/t/serial-woes-buffer-issue/33141.md?page=2)
