Page 1 of 1

Controlling USB power

Posted: Mon Jun 15, 2020 3:44 pm
by MariusL
Hi guys,

I am using MikroTik devices in industrial environments, where one of the requirements is that all networking devices can generate alarm signals for use with PLCs. This must be a potential free relay output, that can be monitored using a PLC digital input. Conditions that trig this alarm can be an interface going down, or a power supply failure.

For the CCR1036-12G-4S, i am using the following script that runs at boot:
:global StopAlarmScript false;
:delay 30
:do {
:if (([/interface ethernet get ether1 running]=false) = true  \
or ([/interface ethernet get sfp1 running]=false) = true  \
or ([/interface ethernet get sfp2 running]=false) = true  \
or ([/system health get psu1-state]="fail") = true \
or ([/system health get psu2-state]="fail") = true) \
do={[/system leds set leds=fault-led type=on 0]\ [/system routerboard usb power-reset duration=1d]} \
else={[/system leds set leds=fault-led type=off 0]\ [/system routerboard usb power-reset duration=0]}
:delay 5
} while=(!$StopAlarmScript)

Together with this piece of hardware:
Image


This works (almost) perfectly, and disables the 5V output of the USB port if any of the defined interfaces goes down, or if one of the power supplies fails. When the alarm condition goes away, the power returns immediately.

However, if the alarm condition persist for more than 24 hours, the power turns back on again for a split second. This is enough to re-trigger the alarm condition in the PLC, which messes with timestamps and confuses the operators of the plant.

Is there any way to disable the power of the USB port, rather than just defining a reset duration?
If no, can this be considered a feature request? :-)

Best,
Marius

Re: Controlling USB power

Posted: Tue Jun 16, 2020 2:58 pm
by mutluit
I would suggest to use a global counter (inc / dec), and trigger the alarm only if that counter is for example >= 2.

And I think it's caused by this command in your script:
/system routerboard usb power-reset duration=1d
Ie. 1d is then too short, you should set it much higher.

Re: Controlling USB power

Posted: Tue Jun 16, 2020 3:24 pm
by MariusL
Hello mutluit,
Thank you for your reply. :-)

As i understand from this thread: viewtopic.php?t=94788
It isn't so simple. I tested it on mAP. It seems to work for one day on two, but in a long period USB power will return enabled randomly before the duration requested from the script. I don't know why, at this moment. Tested with routeros 6.43.8

...having a reset-duration longer than 1 day may cause unpredictable behaviour.

It would be very nice if there were a feature to simply disable the USB-port altogether, instead of (ab)using the reset function.

Best regards,
Marius

Re: Controlling USB power

Posted: Tue Jun 16, 2020 3:46 pm
by mutluit
@MariusL, I think you should make an official Feature Request. And/or if you think the current version has a bug then post a bug report.
Per this page https://wiki.mikrotik.com/wiki/Manual:USB_Features currently the USB powering-off can be done only for a duration of user-specified time (or default 3s if not specified).
As a workaround you can use a counter that I described above.

Re: Controlling USB power

Posted: Tue Jun 16, 2020 4:06 pm
by markom
I have asked same question Normis et MUM Belgrade 3 (or 4 ? )years ago.
He told me that USB power disable should be minor intervention and that he will transfer my request.
Until then, nothing.