Reboot when no wifi network available

Hello. I’ve got problem with my RB Metal 2SHPn.
It’s now configured as AP for 3 another Mikrotiks.

But sometimes all clients are just disconnect and don’t reconnect. I’ve tried to make off/on wireless module, but this doesn’t help.
Then I just reboot my 2SHPn and all clients can connect again and all working fine.

Can someone help me with scripts for automatic reboot when no WiFi clients is connected.

For example - There are was 3 client in “Wireless Tables>Registration” and now it’s 0 clients >>> then wait 5 minutes >>>> reboot

I found script here http://forum.mikrotik.com/t/mikrotik-metal-2-4-wihtout-wireless/65786/1 but i don’t understand how does it work. Why there is :pick $a +4 ?

local a [/in wi reg get number=0 last-activity]; :local b {[:pick $a +4]}; :if (b>=2) do={[/system reboot;];}

Thanks, and sorry for my english

The script you mentioned won’t do what you want… it gets the last-activity value of associated client number 0, which doesn’t exist if there are no associated clients.

You would be better off doing something like the following scirpt. It finds how many items are in the registration table, and if there are 0, it waits 5 minutes, checks one more time and then reboots.
/interface wireless registration-table
:if ([:len [find]] = 0) do={
:delay 5m
:if ([:len [find]] = 0) do={
/system reboot
}
}

Thanks! But when I test it, my router rebooting after 5 minutes and there was active clients on it.
I think the return answer was 0. How can I test it in Terminal?
I’m trying "/interface wireless registration-table find " command but it’s return nothing .

You can do some testing in a few ways. Paste these into the terminal.

Return how many clients are in registration table:
:put [:len [/interface wireless registration-table find]]
Add some additional checks for testing, only pause for a few seconds, reboot line commented out
{
:local numClients [:len [/interface wireless registration-table find]]
:if ($numClients = 0) do={
:put “0 associated clients, pausing for a bit”
:delay 3s
:if ($numClients = 0) do={
:put “still 0 associated clients, router reboot”

/system reboot

} else={
:put “$numClients associated clients, do not reboot”
}
} else={
:put “$numClients associated clients, cancel script”
}
}HTH

Thank you! “:put [:len [/interface wireless registration-table find]]” works perfect in terminal.
So I make little change in your script. I’m change " :put" to “/log info” string. Or I still need “:put” ?
I just want to read log messages. Can you check it please?

{
:local numClients [:len [/interface wireless registration-table find]]
:if ($numClients = 0) do={
   /log info "0 associated clients, pausing for a bit"
  :delay 30s
  :if ($numClients = 0) do={
   /log info " $still 0 associated clients, router reboot"
    /system reboot
  } else={
   /log info  "$numClients associated clients, do not reboot"
  }
} else={
 /log info " $numClients associated clients, cancel script"
}
}

/log info is a good way to do it. :put is helpful for testing in the terminal, but you don’t need those statements for the final script.

The script looks good. Only change is to remove the $ in the word $still.

Sorry for hi-jacking this thread?

I have a issue with PPPoE on a live production AP and need a quick solution to fix the effects of the issue until
I am sure a upgrade will actually fix this problem and not generate other issues, I certainly don’t want to make a bad situation worst for now?
/interface wireless registration-table
:if ([:len [find]] = 0) do={
:delay 5m
:if ([:len [find]] = 0) do={
/system reboot
}
}Can this script be edited to detect
(1) PPP active clients - if 0 reboot - email this action has taken place

(1) Ping dynamic local ppp ip address (example - 10.100.10.1) - reboot if no answer to pings

  • email this action has taken place

This is untested, but I assume the active clients show up in /ppp active, so something like this might work:
/ppp active
:if ([:len [find]] = 0) do={
/tool email send …
/system reboot
}

[/quote][/quote]
:if ([/ping 10.100.10.1 count=5] = 0) do={
/tool email send …
/system reboot
}For testing, I would change the /system reboot lines to /log info “rebooting now…” until you’re sure the scripts will work.

Hello. I’ve got problem with my RB Metal 2SHPn.
It’s now configured as AP for 3 another Mikrotiks.

But sometimes all clients are just disconnect and don’t reconnect. I’ve tried to make off/on wireless module, but this doesn’t help.
Then I just reboot my 2SHPn and all clients can connect again and all working fine.

Can someone help me with scripts for automatic reboot when no WiFi clients is connected.

For example - There are was 3 client in “Wireless Tables>Registration” and now it’s 0 clients >>> then wait 5 minutes >>>> reboot

I found script here viewtopic.php?f=3&t=72229#p393705, but i don’t understand how does it work. Why there is :pick $a +4 ?

Quote:
local a [/in wi reg get number=0 last-activity]; :local b {[:pick $a +4]}; :if (b>=2) do={[/system reboot;];}

Thanks, and sorry for my english

Hi,

i have same problem on multiple AP. Is there any solution fixing WiFi freezing?

you can use the following code

:if ([/interface wireless registration-table print count-only]=0) do={
  :delay 5m
  :if ([/interface wireless registration-table print count-only]=0) do={
    /system reboot
  }
}