# Serial port /dev/ttyUSB0 closed unexpectedly again

**URL:** <https://discourse.nodered.org/t/serial-port-dev-ttyusb0-closed-unexpectedly-again/31175>\
**Category:** General\
**Created:** [5 August 2020 12:50 UTC](https://discourse.nodered.org/t/serial-port-dev-ttyusb0-closed-unexpectedly-again/31175 "2020-08-05T12:50:11Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![edje11](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/edje11/32/572_2.png) [@edje11](https://discourse.nodered.org/u/edje11)\
**Post date:** [5 August 2020 12:50 UTC](https://discourse.nodered.org/t/serial-port-dev-ttyusb0-closed-unexpectedly-again/31175/1 "2020-08-05T12:50:11Z")

</div>

I have the problem with serial port closed unexpectedly again. See this [topic](https://discourse.nodered.org/t/serial-port-dev-ttyusb0-closed-unexpectedly/20549)

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:

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

```

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [5 August 2020 13:57 UTC](https://discourse.nodered.org/t/serial-port-dev-ttyusb0-closed-unexpectedly-again/31175/2 "2020-08-05T13:57:59Z")

</div>

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.

---

<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:** [5 August 2020 14:44 UTC](https://discourse.nodered.org/t/serial-port-dev-ttyusb0-closed-unexpectedly-again/31175/3 "2020-08-05T14:44:32Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![edje11](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/edje11/32/572_2.png) [@edje11](https://discourse.nodered.org/u/edje11)\
**Post date:** [5 August 2020 17:33 UTC](https://discourse.nodered.org/t/serial-port-dev-ttyusb0-closed-unexpectedly-again/31175/4 "2020-08-05T17:33:05Z")

</div>

> [@Colin](#):
>
> sudo journalctl -f

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

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

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

```

---

<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:** [5 August 2020 19:35 UTC](https://discourse.nodered.org/t/serial-port-dev-ttyusb0-closed-unexpectedly-again/31175/5 "2020-08-05T19:35:05Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Sjoerd](https://avatars.discourse-cdn.com/v4/letter/s/54ee81/32.png) [@Sjoerd](https://discourse.nodered.org/u/Sjoerd)\
**Post date:** [9 August 2020 14:37 UTC](https://discourse.nodered.org/t/serial-port-dev-ttyusb0-closed-unexpectedly-again/31175/6 "2020-08-09T14:37:07Z")

</div>

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

```auto
sudo npm install -g n

```

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

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

---

<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:** [9 August 2020 15:04 UTC](https://discourse.nodered.org/t/serial-port-dev-ttyusb0-closed-unexpectedly-again/31175/7 "2020-08-09T15:04:00Z")

</div>

> [@Sjoerd](#):
>
> nodejs - v14.7.0  
> node - v12.18.3

nodejs and node are the same thing.

> [@Sjoerd](#):
>
> In order to downgrade node you have to install n

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

---

<div class="post-metadata">

**Author:** ![Sjoerd](https://avatars.discourse-cdn.com/v4/letter/s/54ee81/32.png) [@Sjoerd](https://discourse.nodered.org/u/Sjoerd)\
**Post date:** [9 August 2020 15:53 UTC](https://discourse.nodered.org/t/serial-port-dev-ttyusb0-closed-unexpectedly-again/31175/8 "2020-08-09T15:53:22Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [9 August 2020 15:58 UTC](https://discourse.nodered.org/t/serial-port-dev-ttyusb0-closed-unexpectedly-again/31175/9 "2020-08-09T15:58:10Z")

</div>

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 ?

---

<div class="post-metadata">

**Author:** ![Sjoerd](https://avatars.discourse-cdn.com/v4/letter/s/54ee81/32.png) [@Sjoerd](https://discourse.nodered.org/u/Sjoerd)\
**Post date:** [9 August 2020 16:24 UTC](https://discourse.nodered.org/t/serial-port-dev-ttyusb0-closed-unexpectedly-again/31175/10 "2020-08-09T16:24:09Z")

</div>

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

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

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [9 August 2020 16:26 UTC](https://discourse.nodered.org/t/serial-port-dev-ttyusb0-closed-unexpectedly-again/31175/11 "2020-08-09T16:26:16Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Sjoerd](https://avatars.discourse-cdn.com/v4/letter/s/54ee81/32.png) [@Sjoerd](https://discourse.nodered.org/u/Sjoerd)\
**Post date:** [9 August 2020 16:29 UTC](https://discourse.nodered.org/t/serial-port-dev-ttyusb0-closed-unexpectedly-again/31175/12 "2020-08-09T16:29:21Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Sjoerd](https://avatars.discourse-cdn.com/v4/letter/s/54ee81/32.png) [@Sjoerd](https://discourse.nodered.org/u/Sjoerd)\
**Post date:** [9 August 2020 16:30 UTC](https://discourse.nodered.org/t/serial-port-dev-ttyusb0-closed-unexpectedly-again/31175/13 "2020-08-09T16:30:33Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [9 August 2020 16:33 UTC](https://discourse.nodered.org/t/serial-port-dev-ttyusb0-closed-unexpectedly-again/31175/14 "2020-08-09T16:33:59Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Sjoerd](https://avatars.discourse-cdn.com/v4/letter/s/54ee81/32.png) [@Sjoerd](https://discourse.nodered.org/u/Sjoerd)\
**Post date:** [9 August 2020 16:36 UTC](https://discourse.nodered.org/t/serial-port-dev-ttyusb0-closed-unexpectedly-again/31175/15 "2020-08-09T16:36:42Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![edje11](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/edje11/32/572_2.png) [@edje11](https://discourse.nodered.org/u/edje11)\
**Post date:** [20 August 2020 11:50 UTC](https://discourse.nodered.org/t/serial-port-dev-ttyusb0-closed-unexpectedly-again/31175/16 "2020-08-20T11:50:31Z")

</div>

It's time to give up... ☹

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

---

<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:** [20 August 2020 13:02 UTC](https://discourse.nodered.org/t/serial-port-dev-ttyusb0-closed-unexpectedly-again/31175/17 "2020-08-20T13:02:36Z")

</div>

> [@edje11](#):
>
> it works fine

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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [19 October 2020 13:02 UTC](https://discourse.nodered.org/t/serial-port-dev-ttyusb0-closed-unexpectedly-again/31175/18 "2020-10-19T13:02:38Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
