Serial port /dev/ttyUSB0 closed unexpectedly again

I have the problem with serial port closed unexpectedly again. See this topic

Tried today updating NR to V1.1.2, no problems with that. However also the Serial node is update then to 0.10.3 and that gives me the problems again.
The port will give me Serial port /dev/ttyUSB0 closed unexpectedly in the debug window.
This time downgrading the serial node to 0.8.3 was not possible, couldn't get it working.

The usb serial port is an FTDI convertor connected to my smart meter. One side usb and the other side rj11 connector. This smart meter will dump every second some data at 115K.
If I put in the usb connector to my pi3b+ and the rj11 at the other end of the cable NOT to my smartmeter if works, the serial node has the status connected and no error in the debug window.
But as soon I'm plugging in the rj11 in the smartmeter and the data is coming in the node status is disconnected and the debug window shows the above message.

Resorted a backup and i'm back at NR 1.0.3 with serial node 0.8.3 works fine again.
However I can't stay forever at these versions and want to upgrade asap.

How can we solve or debug this problem?

NR LogFile:

5 Aug 14:54:49 - [error] serial port /dev/ttyUSB0 closed unexpectedly
5 Aug 14:55:04 - [info] serial port /dev/ttyUSB0 opened at 115200 baud 8N1
5 Aug 14:55:04 - [error] serial port /dev/ttyUSB0 closed unexpectedly
5 Aug 14:55:19 - [info] serial port /dev/ttyUSB0 opened at 115200 baud 8N1
5 Aug 14:55:20 - [error] serial port /dev/ttyUSB0 closed unexpectedly

While this seems like a software issue, my guess is that it isn't. I'm wondering if the physical connection is marginal and something in the newer version of the serial module has a tighter tolerance and is therefore dropping the link.

First thing to try is a different power supply and cable. If you have the appropriate testing kit, apply a load to the output of the power supply and measure the output from the power cable. Otherwise, you will need to try swapping things around.

There might be something interesting in the system log, run
sudo journalctl -f
and watch the output when it fails. There might be something about the usb port for example as well as the node red error.

More then in the NR log is there not to see.

Aug 05 19:05:37 RaspBroker Node-RED[311]: 5 Aug 19:05:37 - [error] serial port /dev/ttyUSB0 closed unexpectedly
Aug 05 19:05:39 RaspBroker influxd[585]: [httpd] 127.0.0.1 - root [05/Aug/2020:19:05:39 +0200] "POST /write?db=JoshuaSensors&p=%5BREDACTED%5D&precision=n&rp=&u=root HTTP/1.1" 204 0 "-" "-" e312c9d7-d73d-11ea-8048-b827eb633815 14854
Aug 05 19:05:52 RaspBroker Node-RED[311]: 5 Aug 19:05:52 - [info] serial port /dev/ttyUSB0 opened at 115200 baud 8N1
Aug 05 19:05:52 RaspBroker Node-RED[311]: 5 Aug 19:05:52 - [error] serial port /dev/ttyUSB0 closed unexpectedly
Aug 05 19:05:52 RaspBroker influxd[585]: [httpd] 127.0.0.1 - root [05/Aug/2020:19:05:52 +0200] "POST /write?db=JoshuaSensors&p=%5BREDACTED%5D&precision=n&rp=&u=root HTTP/1.1" 204 0 "-" "-" eb27faad-d73d-11ea-8049-b827eb633815 27163
Aug 05 19:05:52 RaspBroker influxd[585]: [httpd] 127.0.0.1 - root [05/Aug/2020:19

One other strange thing I noticed today for the first time, and I'm sure this wasn't earlier is that NR will not work at all when the smartmeter is connected.
Dashboard give "problem during loading" .
Node-red service is running, manual restart with node-red-stop/start will give only give "started Node-red graphical wiring tool"
The other things like "welcome to Node-red" and "5 Aug 19:26:51 - [info]...." lines are not there.

 node-red-start

Start Node-RED

Once Node-RED has started, point a browser at http://192.168.1.127:1880
On Pi Node-RED works better with the Firefox or Chrome browser

Use   node-red-stop                          to stop Node-RED
Use   node-red-start                         to start Node-RED again
Use   node-red-log                           to view the recent log output
Use   sudo systemctl enable nodered.service  to autostart Node-RED at every boot
Use   sudo systemctl disable nodered.service to disable autostart on boot

To find more nodes and example flows - go to http://flows.nodered.org

Starting as a systemd service.
Started Node-RED graphical event wiring tool.

I wondered whether the usb port might be disconnecting, but it is not that.

I had a similar problem when I updated NR to version 1.1.2. I got the message that my version of node was outdated. I upgraded to the latest version and then the problems began. I couldn't connect to my Postgresql database anymore and the serial node that I use to get the data from my smart meter gave an error. After a lot of googling I found out that the problems were indeed caused by the upgrade. The following set of versions works for me:

Node-RED - v1.1.2
nodejs - v14.7.0
node - v12.18.3
serial node - v0.10.3

In order to downgrade node you have to install n

sudo npm install -g n

and then install the version you want (version 12.18.3 is an LTS version with support until 2022)

sudo n 12.18.3

After that, uninstall your serial node and upgrade Node-RED again. It will install the latest version of the serial node (0.10.3) since the serial node is a core node.

nodejs and node are the same thing.

You do not have to do it that way, there are other options.

I have everything working again and that is what mattered for me. I just wrote down what worked for me. If there are other options please share.

And when node and nodejs are the same why do I get different results for:nodejs -v and node -v? This is not a rhetorical question. I'm here to learn.

The reason why you have 2 versions is because you are using n, which is a version manager for nodejs.
Why not just install nodejs the normal way ?

1 Like

Ah, I see. When I start Node-RED I get this:

9 Aug 18:20:55 - [info] Node-RED version: v1.1.2
9 Aug 18:20:55 - [info] Node.js  version: v12.18.3
9 Aug 18:20:55 - [info] Linux 4.19.118-v7+ arm LE

does that mean I can remove 14.7.0?

If v12 is the version you want to run with, yes.

But you should probably remove n first since doing so may disrupt other things.

Yes, I want to use v12 because v14 is giving problems with the PostgresQL and serial nodes. I googled on how to downgrade Node and "n" is what I found. If I wanted to downgrade whitout using n, how should I have done that.

This was the site I found by the way: https://www.surrealcms.com/blog/how-to-upgrade-or-downgrade-nodejs-using-npm.html

It's a bit overkill but if you feel that things are in a mess, I'd remove n, remove all remaining traces of nodejs/node and then install Node.js 12 "correctly" following the instructions on their website.

Once you've done that, you will need to rebuild all of your installed nodes to make sure that any compiled code is compiled against the correct libraries. So remove node-red if you installed it globally then reinstall. Then cd to ~/.node-red and do npm rebuild.

If this is a Pi, you could, after removing n, node and node-red, run Dave's install script which is probably sensible unless you are happy maintaining this yourself (which is what I do). You would still need to rebuild though.

I think I leave things as they are since everything works fine now. Nevertheless thank you for your answers and your time.

It's time to give up... :frowning:

Tried other power supply and a powered usb hub for the serial to usb convertor to eliminate power issues, thanks @TotallyInformation for the tips.
Updated the OS from the pi to 5.4.51-v7+
Updated node to V12.18.3 as described by @Sjoerd.
Updated npm to 6.14.7 and rebuilded everything.
Did run the node-red curl install script between every step

But unfortunately no luck, as soon as there arrives data on the ttyUSB0 the port will close unexpectedly.

Tried it with an fresh install of pi os and NR and then it works fine with the same hardware, data is coming in fine from ttyUSB0 then. This suggest that's not a HW problem.
So there's something wrong in the OS or...................

I have lost track of the thread. If it is working fine then what is the problem?