Skip to content

Instantly share code, notes, and snippets.

@TheSkorm
Created December 24, 2017 08:02
Show Gist options
  • Select an option

  • Save TheSkorm/72b4a2eaba010fa63d8839215da4ecea to your computer and use it in GitHub Desktop.

Select an option

Save TheSkorm/72b4a2eaba010fa63d8839215da4ecea to your computer and use it in GitHub Desktop.
Magic Mikrotik Relay USB Battery Thing
/system routerboard usb
set usb-mode=force-host
/system scheduler
add name=schedule1 on-event=relay policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon start-time=startup
/system script
add name=relay owner=admin policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon source="#CONFIG\
\n# number of seconds until we turn off USB power\
\n:global Timeout 60\
\n\
\n\
\n#Start script\
\n:global clients 1\
\n:global remainingTime \$Timeout\
\n:do {\
\n :global clients [/interface wireless registration-table print count-only]\
\n :if (\$clients = 0) do={\
\n :if (\$remainingTime <= 0) do={ \
\n # this is where we reset the USB power to trigger the relay because there hasn't been a client connected\
\n /system routerboard usb power-reset duration=5\
\n # if the router doesn't reboot after this then we reset the timer\
\n :set remainingTime \$Timeout\
\n }\
\n :set remainingTime (\$remainingTime - 1)\
\n } else={\
\n :set remainingTime \$Timeout\
\n }\
\n :delay delay-time=1\
\n} while=(true = true)\
\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment