USB Communication Problem on Reboot

Hi All,

I have been using Node-RED to control a variety of different devices (mostly Arduinos), and I have ran into the following issue. Every time when I reboot the main computer, all of the Arduino devices seem to be "connected" (showing a green light next to the serial port node), but I cannot communicate with them. In order to establish a proper connection, I have to unplug the USB and plug it back in. And then it works as usual. I already set up Udev rules for all devices, and they are all being recognized properly as far as I know.

One possible solution, that I'm really trying to avoid, is to get a programmable USB hub, where I can connect and disconnect the USB cables remotely. I was hoping that there could be a solution through NR.

Note: I have notices people had similar issues, but they manage to solve it by restarting the flow, which for me doesn't work.

Thanks!

Does it help if you restart the Arduino?

When you say you cannot communicate do you mean you get an error of some sort or the Arduino does not reply? If the latter have you put some debug in the Arduino to see whether it is receiving anything?

Hi Colin,

Yes I have put a debugger, and there is absolutely no communication. The Arduino doesn't send a reply. Usually when I send the following message:

,

I should get the following replay from the device. However, only physical disconnection, fixes the issue. As soon as I unplug and plug the USB back in, the communication works flawlessly.

Any idea what could be the issue? Some people suggested that the Arduino was counterfiet, but I tried it on an genuine one as well, and the issue remains. Thanks for your help!

Is the Arduino receiving anything?
You didn't say what happens if you restart the Arduino.

Sorry about that. So the Arduino doesn't receive anything, at least nothing I can see in the debugger. When I press reset on the Arduino the serial port is disconnecting (of course) and then the error is: "Error resource temporarily unavailable cannot lock port." - so again zero communication. I tried to reset the arduino via exec command, but I encountered the same issue. Did I answer your question? Thanks!

Update: if I press the reset button again, the issue is resolved. Now I have a command that can reset the arduino based on the bus and device number that is assigned to. But when I press restart the first time, the device number is changed, so I cannot execute the same command twice. For example:
exe command 1: sudo ./usbreset /dev/bus/usb/001/007

but then if I want to do that again, the second number 007, is changing for the same device, so I cannot execute that again, unless I know what is the device number. Is there a way to reset all usb devices all? That might solve he problem

Another update: even when I reset twice or three times, it is now connected, but still no communication. So I overcame the "port lock" issue, but it doesn't help me with the serial communication.

I thought you had used udev to setup fixed device names.

I have used it. I'm talking about "lsusb" comman. it keep switching device numbers. The device name remains the same, and connects automatically. However, still same issue where there is no communication unless I unplug the device physically. I'm trying right now to find a way to reset the arduino using a DTR pulse.

DTR pulse doesn't work as well...

Potential solution: I'm not sure if there is a way to do it, but if I press on reset 2-3 times, it finally works. Is there a way to mimic this action? Sorry for the mass messaging.

What happens if you power down the arduino and up again obviously.

I'm only using a micro-usb to power the arduino as well as to communicate with it. So if by powering down the arduino you mean "remove the power cable" which in my case is the usb, yes, the issue is resolved. Is there a way to power down the arduino via NR?

Ah yes, so you can't power it down without disconnecting the usb.

I was attempting to identify whether the problem is with the arduino or the PC (or whatever it is).
If you power down the main machine (which powers down everything I presume) and power it up does it work reliably then?

Yes, if I shutdown the main PC, and turn it on again, the communication work properly.
I can resolve that issue by sending a signal to a relay that will shut down the computer, than go back on, but it would be great if this can be avoided. Any ideas?

So shutting down the whole system and powering up again works, but just rebooting doesn't? I think that must mean that it is the Arduino that is in a confused state. Are you sure it is definitely listening on the serial port when you get to this state?

yes I'm confident - shutdown the machine completely resolve the issue. I'm looking into a few possible solutions:

  1. shutdown power to usbhub completely
  2. connect a relay that I can control to shutdown the PC.
  3. shutdown the PC and wakeup via LAN.

If there is a way to do it via NR it would be great, but I don't think there is a solution...

You could use something like a Sonoff Basic with one of the alternative s/w packages such as Tasmota or ESPEasy, communicating with node-red via MQTT. Then in node-red you could initiate a sequence that runs in the sonoff which would wait a bit while node-red tells the PC to shutdown, then switches off the power to the PC and then switches it back on again. Have a look in the PC BIOS, you may be able to tell the PC to autorun when the power comes back on, rather than having to do a LAN wakeup.

I think this is the route I have to take - either a relay with a timer, or LAN wakeup. Couldn't find anything in BIOS that does autostart. Thanks for your help!

My solution I ended up with:
I splice the hot wire of the USB into a switch that is controlled from NR, and I just inject true after 5 seconds (when I reboot, it goes off, and then inject true automatically so I don't have to do worry about every time.) Thanks for your help again!

1 Like