Community discussions

MikroTik App
 
galleon2006
just joined
Topic Author
Posts: 22
Joined: Fri Jan 17, 2014 7:59 am

Reboot when no wifi network available

Mon Jan 27, 2014 12:00 pm

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/viewtopic.php ... 29#p393705, 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
 
User avatar
skot
Long time Member
Long time Member
Posts: 584
Joined: Wed Nov 30, 2011 3:05 am

Re: Reboot when no wifi network available

Mon Jan 27, 2014 6:35 pm

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 ?
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.

ros code

/interface wireless registration-table
:if ([:len [find]] = 0) do={
  :delay 5m
  :if ([:len [find]] = 0) do={
    /system reboot
  }
}
 
galleon2006
just joined
Topic Author
Posts: 22
Joined: Fri Jan 17, 2014 7:59 am

Re: Reboot when no wifi network available

Tue Jan 28, 2014 5:49 am

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.

ros code

/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 .
 
User avatar
skot
Long time Member
Long time Member
Posts: 584
Joined: Wed Nov 30, 2011 3:05 am

Re: Reboot when no wifi network available

Tue Jan 28, 2014 6:36 am

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

Return how many clients are in registration table:

ros code

:put [:len [/interface wireless registration-table find]]

Add some additional checks for testing, only pause for a few seconds, reboot line commented out

ros code

{
: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
 
galleon2006
just joined
Topic Author
Posts: 22
Joined: Fri Jan 17, 2014 7:59 am

Re: Reboot when no wifi network available

Tue Jan 28, 2014 6:59 am

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

Return how many clients are in registration table:

ros code

:put [:len [/interface wireless registration-table find]]

Add some additional checks for testing, only pause for a few seconds, reboot line commented out

ros code

{
: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"
}
}
 
User avatar
skot
Long time Member
Long time Member
Posts: 584
Joined: Wed Nov 30, 2011 3:05 am

Re: Reboot when no wifi network available

Tue Jan 28, 2014 7:54 am

So I make little change in your script. I'm change " :put" to "/log info" string. Or I still need ":put" ?
/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.
 
n21roadie
Forum Guru
Forum Guru
Posts: 1949
Joined: Fri Aug 07, 2009 10:36 pm
Location: Limerick,Ireland

Re: Reboot when no wifi network available

Thu Jan 30, 2014 6:18 pm

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?

ros code

/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
 
User avatar
skot
Long time Member
Long time Member
Posts: 584
Joined: Wed Nov 30, 2011 3:05 am

Re: Reboot when no wifi network available

Tue Feb 04, 2014 2:11 am

Can this script be edited to detect
(1) PPP active clients - if 0 reboot - 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:

ros code

/ppp active
:if ([:len [find]] = 0) do={
  /tool email send ...
  /system reboot
}
(1) Ping dynamic local ppp ip address (example - 10.100.10.1) - reboot if no answer to pings
- email this action has taken place
[/quote][/quote]

ros code

: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.
 
cold123
just joined
Posts: 10
Joined: Wed Nov 04, 2009 1:50 pm

Re: Reboot when no wifi network available

Sun Jun 15, 2014 2:35 pm

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?
 
rabienz
newbie
Posts: 48
Joined: Tue Oct 13, 2015 5:51 pm

Re: Reboot when no wifi network available

Sun Mar 01, 2020 3:12 am

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
  }
}

Who is online

Users browsing this forum: dioeyandika and 6 guests