Page 1 of 1

Wi-Fi on-off switch

Posted: Sat Nov 26, 2016 1:19 pm
by Maggiore81
Hello
is it possible to reprogram in the Hap Lite AC or similar routers, the button to enable or disable the wifi?

Re: Wi-Fi on-off switch

Posted: Mon Nov 28, 2016 10:04 pm
by w32pamela
In Webfig go to Wireless->Interfaces and click on the button with the "D" or "E" in the first column of the wireless interface you want to disable or enable. "D" will disable and "E" will enable.

In Winbox there won't be a "D" or "E" button. Just highlight the wireless interface you want to change and click the blue check mark to enable or the red X to disable.

Re: Wi-Fi on-off switch

Posted: Sat Dec 03, 2016 6:49 pm
by Maggiore81
I know how to disable end enable the interface. The purpose of programming the button is to tell that to dumb users :D so they can disable the wifi because they think that wifi is not safe!

Re: Wi-Fi on-off switch

Posted: Sat Dec 03, 2016 7:19 pm
by etm7469
Perhaps a specific time on off
sheduler 23.00 off 6.00 on

add interval=1d name="wifi off" on-event="/interface disable wlan1" policy=\
ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon \
start-date=oct/27/2016 start-time=23:00:00
add interval=1d name="wifi on" on-event="/interface enable wlan1" policy=\
ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon \
start-date=oct/27/2016 start-time=06:00:00

Re: Wi-Fi on-off switch

Posted: Sat Dec 03, 2016 7:25 pm
by Maggiore81
no no scheduler!

My users would like to shutdown the wifi as in the cheap TP LINK routers.

Re: Wi-Fi on-off switch

Posted: Fri Sep 22, 2017 12:56 pm
by nelfou
Same here.
It'd be nice to be able to customize the hAP button behavior, like having it trigger a script.
We usually don't need WPS while some customers want to be able to easily turn the Wi-Fi on/off.

Re: Wi-Fi on-off switch

Posted: Fri Sep 22, 2017 2:03 pm
by normis
newer devices have the MODE button that you can use to run any script.

Re: Wi-Fi on-off switch

Posted: Sat Sep 23, 2017 6:30 pm
by petterg
My home router runs a script that has the intention to enable wlan when someone tries to connect, and disables wlan when no clients are connected. This is scheduled to run every 150seconds. It's not as effective as it sounds. wlan is only disabled 93% of the time when disabled. The reminding 7% of the time it's enabled to check if someone wants to connect. The way it works is:
Enable wireless
sleep for 20 seconds (give clients the possibility to connect if they are there)
if registration table is empty (no clients connected): disable wireless

Windows default wlan scan interval is 60 seconds. If this script runs every X minutes, you frequently will experience that windows will not connect while the wlan is on to check if someone wants to connect. With 150seconds interval, clients usually connects within 70 seconds. In worst case it may take 280 seconds.

Also, I think it's possible to make a button by offering one ethernet port. If you make a microswitch with an ethernet port, where a press of the button will connect the RX and TX pins of the ethernetport, you could use the link up status to trigger a script. I would use a microswitch that only connects the pins while the button is pressed, rather than one that remains connected until button is pressed again.

Finally, if your device has a serial port, I would guess a button could be connected to this as well and trigger a script when pressed.

Re: Wi-Fi on-off switch

Posted: Sat Sep 23, 2017 7:54 pm
by jspool
Imagine if RouterOS supported Bluetooth! You could scan for specific Bluetooth devices and run scripts based on the results.

Re: Wi-Fi on-off switch

Posted: Sun Sep 24, 2017 2:41 pm
by petterg
I suppose you could even make a sort of switch by inserting a usb stick. If file1 is present on usb storage, run script1. If file2 is present run script2.... Multiple sticks act as different switches.

Re: Wi-Fi on-off switch

Posted: Mon May 20, 2019 11:30 am
by el berto
Any update?
I mean through button...
My customers don't want wait for script detection, they say "Netgear wireless routers have external button to enable/disable wifi, why installing MikroTik?"...

Re: Wi-Fi on-off switch

Posted: Tue Oct 27, 2020 1:00 pm
by kelner
/system leds add interface=wlan1 leds=user-led type=wireless-status
/system routerboard mode-button set enabled=yes hold-time=3s..10s on-event=on-mode-button-pressed
/system script add dont-require-permissions=yes name=on-mode-button-pressed owner=system source="{}"
/system script edit 0 value-name=source

Place following code into script body:

{
:local DISABLED;
:log info "MODE Button pressed";
:if ( [ /interface wireless get 0 disabled ] ) do={ :set DISABLED "no"; } else={ :set DISABLED "yes"; };
:log info "Switching WiFi disabled mode to [$DISABLED]";
:do { /interface wireless set 0 disabled=$DISABLED } on-error={ :log info "Can not switch WiFi disabled mode to [$DISABLED]"; };
}


Re: Wi-Fi on-off switch

Posted: Thu Nov 26, 2020 11:14 am
by hengst
i found this a nice one using the big button for wifi on/off in the whole building on a Cap(Ac) , and using this Cap(Ac) as Caps manager.

pressing the button will switch off/on all Caps interfaces ( i would set all radio freq of the cap interfaces to static ones also )
user is also sure its off , because leds are all off as well.

:if ([system leds settings get all-leds-off] = "never") do={ /caps-man interface disable [find];
/system leds settings set all-leds-off=immediate
} else={ /caps-man interface enable [find];
/system leds settings set all-leds-off=never
}




/system routerboard mode-button
set enabled=yes on-event=dark-mode

/system script
add comment=defconf dont-require-permissions=no name=dark-mode owner=admin \
    policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon \
    source="\r\
    \n   :if ([system leds settings get all-leds-off] = \"never\") do={ /caps-m
    n interface disable [find];\r\
    \n     /system leds settings set all-leds-off=immediate \r\
    \n   } else={ /caps-man interface enable [find];\r\
    \n     /system leds settings set all-leds-off=never \r\
    \n   }\r\
    \n "

Re: Wi-Fi on-off switch

Posted: Tue Dec 29, 2020 5:13 pm
by rl2019
/system leds add interface=wlan1 leds=user-led type=wireless-status
/system routerboard mode-button set enabled=yes hold-time=3s..10s on-event=on-mode-button-pressed
/system script add dont-require-permissions=yes name=on-mode-button-pressed owner=system source="{}"
/system script edit 0 value-name=source

Place following code into script body:

{
:local DISABLED;
:log info "MODE Button pressed";
:if ( [ /interface wireless get 0 disabled ] ) do={ :set DISABLED "no"; } else={ :set DISABLED "yes"; };
:log info "Switching WiFi disabled mode to [$DISABLED]";
:do { /interface wireless set 0 disabled=$DISABLED } on-error={ :log info "Can not switch WiFi disabled mode to [$DISABLED]"; };
}

i tested this script on CAP AC but it work only on wlan1. it's possible to work with wlan2?

Re: Wi-Fi on-off switch

Posted: Tue Dec 29, 2020 7:16 pm
by mkx
The script only toggles wlan interface #0. You can change script to
{
:local DISABLED;
:log info "MODE Button pressed";
:if ( [ /interface wireless get [ find name=wlan2 ] disabled ] ) do={ :set DISABLED "no"; } else={ :set DISABLED "yes"; };
:log info "Switching WiFi disabled mode to [$DISABLED]";
:do { /interface wireless set [ find name=wlan2 ] disabled=$DISABLED } on-error={ :log info "Can not switch WiFi disabled mode to [$DISABLED]"; };
}

To operate explicitly named interface. And you can alter script to toggle both interfaces (and the state will follow the first one) this way:
{
    :local DISABLED;
    :log info "MODE Button pressed";
    :if ( [ /interface wireless get [ find name=wlan1 ] disabled ] ) do={ :set DISABLED "no"; } else={ :set DISABLED "yes"; };
    :log info "Switching WiFi disabled mode to [$DISABLED]";
    :do { /interface wireless set [ find name=wlan1 ] disabled=$DISABLED } on-error={ :log info "Can not switch wlan1 disabled mode to [$DISABLED]"; };
    :do { /interface wireless set [ find name=wlan2 ] disabled=$DISABLED } on-error={ :log info "Can not switch wlan2 disabled mode to [$DISABLED]"; };
}
If you changed names from default, then adapt the script accordingly.

Re: Wi-Fi on-off switch

Posted: Fri Apr 09, 2021 11:49 am
by samueljazz
When there is an issue with the router or the network then maximum of the time, if we switch the Wi-Fi on-off the problem gets resolved. The connectivity gets re-establish and stable.

Re: Wi-Fi on-off switch  [SOLVED]

Posted: Mon May 17, 2021 11:13 am
by rextended
search tag # rextended wireless on off with mode button

For 6.46.8 / 6.47.9 and up

This disable/enable all wifi on board,
the "master" is wlan1, all the others change accordingly

this is the script to put on "on-event" event on mode button and change user-led status accordingly (wi-fi led, if present are turnded off/on automatically)
/system leds
:if ([:len [find where leds=user-led]] < 1) do={add leds=user-led type=on}
:log info "Premuto Pulsante"
/interface wireless
:if ([get [find default-name=wlan1] disabled]) do={
    :log info "Wi-Fi Attivato"
    set [find] disabled=no
    /sys leds set [find where leds=user-led] type=on
} else={
    :log info "Wi-Fi Disattivato"
    set [find] disabled=yes
    /sys leds set [find where leds=user-led] type=off
}

or set directly
/system routerboard mode-button
set enabled=yes on-event="/system leds\r\
    \n:if ([:len [find where leds=user-led]] < 1) do={add leds=user-led type=on}\r\
    \n:log info \"Premuto Pulsante\"\r\
    \n/interface wireless\r\
    \n:if ([get [find default-name=wlan1] disabled]) do={\r\
    \n :log info \"Wi-Fi Attivato\"\r\
    \n set [find] disabled=no\r\
    \n /sys leds set [find where leds=user-led] type=on\r\
    \n} else={\r\
    \n :log info \"Wi-Fi Disattivato\"\r\
    \n set [find] disabled=yes\r\
    \n /sys leds set [find where leds=user-led] type=off\r\
    \n}\r\
    \n"

Re: Wi-Fi on-off switch

Posted: Mon May 17, 2021 10:37 pm
by enlace101
Thank you. I'll try it tomorrow

Re: Wi-Fi on-off switch

Posted: Wed Sep 22, 2021 10:14 pm
by Triforce
Hello!
I am a big fan of Mikrotik and I am trying to learn litlle by little this interesting technology.
I have a little Mikrotik hAP mini RB931-2nD.
I tried the scypt above for disabling and it is working fine. But I need a scrypt, that can switch with MODE button Wi-fi - ON or OFF. Press one time - ON. Press one time more - OFF.
Can you give me such a scipt or a link, where I can copy it?
I am not a programmer and I am not some guy who is super user of nets. But I really like to learn new things and when you give me the script I will try to learn it and why it is works this way.
Thank you in advance!

Thank you, but I found the script on this post:
viewtopic.php?f=2&t=127597&p=658230&hil ... on#p658230

Re: Wi-Fi on-off switch

Posted: Mon Oct 31, 2022 7:07 pm
by dot02
For those interrested in using the button on the mAP lite for turning Wifi on/off on the mAP lite, I modified kelner's script slightly (the button to use is the reset button in this case). Also, you only need a short push (less than 1s) for turning wifi on/off.

The LED already reflects the Wifi state, so no need to specify it in the config.

The script only needs read and write permissions.
/system routerboard reset-button
set enabled=yes hold-time=0s..1s on-event=on-mode-button-pressed
and the script itself:
/system script
add comment="Enabling/disable Wifi Interface when pressing button" dont-require-permissions=yes name=on-mode-button-pressed owner=system policy=read,write source="{\
    \n:local DISABLED;\
    \n:log info \"MODE Button pressed\";\
    \n:if ( [ /interface wireless get 0 disabled ] ) do={ :set DISABLED \"no\"; } else={ :set DISABLED \"yes\"; };\
    \n:log info \"Switching WiFi disabled mode to [\$DISABLED]\";\
    \n:do { /interface wireless set 0 disabled=\$DISABLED } on-error={ :log info \"Can not switch WiFi disabled mode to [\$DISABLED]\"; };\
    \n}"

enjoy!

Re: Wi-Fi on-off switch

Posted: Mon Oct 31, 2022 7:13 pm
by rextended
the script is wrong in many parts, for example a major error is "set 0", it should not be used, must be used set [find where default-name=wlan1], and so on...

On previous post #17 already exist one script compatible with all wireless interface, not only the first...
for apply the script to only one wireless interface, replace [find] with [find where default-name=<INTERFACE_NAME>]
:log info "Button Pressed"
/interface wireless
:if ([get [find where default-name=wlan1] disabled]) do={
    :log info "Wi-Fi ON"
    set [find] disabled=no
} else={
    :log info "Wi-Fi OFF"
    set [find] disabled=yes
}

Re: Wi-Fi on-off switch

Posted: Mon Oct 31, 2022 7:16 pm
by dot02
comments are welcome to improve the script! However, the script does work as it is.

Re: Wi-Fi on-off switch

Posted: Mon Oct 31, 2022 7:19 pm
by dot02
Your script works very well, too, so I switched to this version too. thanks!

Re: Wi-Fi on-off switch

Posted: Mon Oct 31, 2022 7:21 pm
by rextended
I try to teach scripting, it's not a controversy, only English is not my language...


:local DISABLED;
:if ( [ /interface wireless get 0 disabled ] ) do={ :set DISABLED "no"; } else={ :set DISABLED "yes"; };
can be simply replaced with
:local DISABLED [/interface wireless get wlan1 disabled]


for simply "invert" disabled status on button press, without any logging frills:
/interface wireless set wlan1 disabled=(![get wlan1 disabled])

Re: Wi-Fi on-off switch

Posted: Mon Oct 31, 2022 7:25 pm
by dot02
Much appreciated, thanks (I'm serious, this is not sarcasm!). I'm really bad at scripting, and even if I was good at it, I would still appreciate comments and improvements!
:)

Re: Wi-Fi on-off switch

Posted: Mon Oct 31, 2022 7:55 pm
by dot02
Another cool feature would be to add a timer (In a separate script to give the admin some flexibility) that would disable Wifi after a hard-timeout. After 6 hours for instance.

The button could still be used to switch wifi on/off manually with the current script, but if the user leaves the site and forgot to turn the wifi off, it will be turned off automagically when the timer expires.
If the user is still working onsite then the timer expires, he would simply have to reactivate the Wifi by pressing the button (and the timer would restart for 6 hours)...

This would be very useful if these AP's are used in Datacenters where many clients share the same physical location. You don't want to broadcast your SSID to potential competitors hosted in the racks next to yours...

Re: Wi-Fi on-off switch

Posted: Tue Nov 01, 2022 7:09 pm
by gotsprings
Need like a 3 position toggle.
Forced On
Forced Off
Use the Scheduler

Re: Wi-Fi on-off switch

Posted: Wed Nov 02, 2022 12:24 am
by anav
I try to teach scripting, it's not a controversy, only English is not my language...
Okay, so Wine, Coffee, fresh Tuscany air....... and scripting in the garden.
Im in!!!

Re: Wi-Fi on-off switch

Posted: Tue Apr 16, 2024 7:35 am
by csaba
Perhaps a specific time on off
sheduler 23.00 off 6.00 on

add interval=1d name="wifi off" on-event="/interface disable wlan1" policy=\
ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon \
start-date=oct/27/2016 start-time=23:00:00
add interval=1d name="wifi on" on-event="/interface enable wlan1" policy=\
ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon \
start-date=oct/27/2016 start-time=06:00:00
Hello.
How can I setting?

add interval=1d name="wifi off" on-event="/interface disable wlan2" policy=\

Off= 23:00. On=06:00

Re: Wi-Fi on-off switch

Posted: Tue Apr 16, 2024 8:22 am
by normis
Make a new topic for your other scripting questions, no need to raise old topic about button use