I'm using Node-red on a Raspberry Pi 3B+ with Raspbian Stretch.
I'm also using UUgear 7-port USB hub.
I connected RS232 devices with node-red-node-serialport, using the serial request node.
For easier device management I gave names to my USB ports by adding udev rules using this and this tutorials.
This is working very well.
But sometimes my USB ports disconnect, often when I plug a new device or when I touch the hardware.
They reconnect immediatly and can be found using the cmd console, but Node-red lost them and I have to restart Node-red to get them back.
Do you know how I can manage this so Node-red can fin them back ?
Before disconnection it is written "connected" with a green dot below the node.
After it is written "disconnected" with a red dot.
And I have a message in the debug console :
"serial port /dev/port_usb_2 closed unexpectedly"
port_usb_2 is the name I gave to my USB port, instead of ttyUSBx
Yes I'm using the standard one.
The disconnection is due to the hardware however what I need is when I detect a disconnection (I can with status or catch), wait a bit and ask nodered to reconnect. But I have no idea how to do that.
Sometimes it reconnect by itself but most of the time it doesn't.
I suggest you raise an issue against the node, it should reliably reconnect without you doing anything.
I don't know whether there has been any work on that node that might have improved it recently, are you using the latest version?
It should reconnect automatically on a disconnect... but sometimes we get reports that once it disconnects it then comes back as another port so then of course it won't reconnect.... is that the case here ? if/when it does it again can you list he serial ports you now have available (I would say ls /dev/ttyU* but you have renamed them, so I'll let you figure that out...)
I fought and won this battle many moons ago with node-red-contrib-rfxcom, though recent versions of the serialport node did cause some trouble. It is a case of listening to serialport events, and using a timer to attempt reconnection at regular intervals if a disconnection is detected. But this is USB-serial device specific, and may cause problems with actual hardware UARTs. It could be made an option on the serialport node, maybe?
Edit to add: The logic is split between node-red-contrib-rfxcom and node-rfxcom.
I have also seen this sometimes. To solve the issue, I use a utility named usbreset (with google you will find it here: https://github.com/jkulesza/usbreset)
I configured NR to use a status node checking the status of rfx node. In case it showed "OK", everything is fine but if it shows "disconnected", the trigger node kicked in and activated the exec node. Shortly after, everything was working again. Today I do not recognize any communication problems with the RFXtrx
The command I use for the exec node is as follows:
RFXcom is a special product for a special purpose, obviously is of no interest if you just wanna do serial comms
Are you talking about "full deploy"? If so, I think it is restarting the flow and it might be that this in itself is releasing some handles to the serial port. In later versions of NR you have the possibility to restart the flow via the "Deploy" button in the editor. Next time you see the problem with the serial, you could try this to see if it is enough to fix it, just to verify
If it seems to help, you could implement a flow restarter in the dashboard using a template node, in this thread there is a possible solution discussed
@Charlotte have you found a solution for disconnect/reconnect issue with USB serial device as symlink? I have been struggling to get this right, but restarting the flow is not the solution for me. I have an open session in Node Red that I don't want to loose by restarting the flow.
@Charlotte I may have solved it myself with a temporary solution. It seems that something has changed or broken with node-serialport >=0.9.0? I can make it work by installing earlier version of it. It works just fine on my platform with node-serialport 0.8.8, and symlinks to physical ports work as well in my box.