Community discussions

MikroTik App
 
User avatar
Maggiore81
Trainer
Trainer
Topic Author
Posts: 581
Joined: Sun Apr 15, 2012 12:10 pm
Location: Italy
Contact:

Wi-Fi on-off switch

Sat Nov 26, 2016 1:19 pm

Hello
is it possible to reprogram in the Hap Lite AC or similar routers, the button to enable or disable the wifi?
 
User avatar
w32pamela
Member Candidate
Member Candidate
Posts: 212
Joined: Fri Jul 12, 2013 4:22 pm

Re: Wi-Fi on-off switch

Mon Nov 28, 2016 10:04 pm

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.
 
User avatar
Maggiore81
Trainer
Trainer
Topic Author
Posts: 581
Joined: Sun Apr 15, 2012 12:10 pm
Location: Italy
Contact:

Re: Wi-Fi on-off switch

Sat Dec 03, 2016 6:49 pm

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!
 
etm7469
just joined
Posts: 9
Joined: Wed Apr 22, 2015 10:28 pm
Location: Poland

Re: Wi-Fi on-off switch

Sat Dec 03, 2016 7:19 pm

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
 
User avatar
Maggiore81
Trainer
Trainer
Topic Author
Posts: 581
Joined: Sun Apr 15, 2012 12:10 pm
Location: Italy
Contact:

Re: Wi-Fi on-off switch

Sat Dec 03, 2016 7:25 pm

no no scheduler!

My users would like to shutdown the wifi as in the cheap TP LINK routers.
 
nelfou
just joined
Posts: 17
Joined: Wed Mar 22, 2017 3:10 pm

Re: Wi-Fi on-off switch

Fri Sep 22, 2017 12:56 pm

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.
 
User avatar
normis
MikroTik Support
MikroTik Support
Posts: 26823
Joined: Fri May 28, 2004 11:04 am
Location: Riga, Latvia
Contact:

Re: Wi-Fi on-off switch

Fri Sep 22, 2017 2:03 pm

newer devices have the MODE button that you can use to run any script.
 
petterg
Member Candidate
Member Candidate
Posts: 230
Joined: Wed Sep 16, 2009 2:55 pm

Re: Wi-Fi on-off switch

Sat Sep 23, 2017 6:30 pm

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.
 
User avatar
jspool
Member
Member
Posts: 472
Joined: Sun Oct 04, 2009 4:06 am
Location: Oregon

Re: Wi-Fi on-off switch

Sat Sep 23, 2017 7:54 pm

Imagine if RouterOS supported Bluetooth! You could scan for specific Bluetooth devices and run scripts based on the results.
 
petterg
Member Candidate
Member Candidate
Posts: 230
Joined: Wed Sep 16, 2009 2:55 pm

Re: Wi-Fi on-off switch

Sun Sep 24, 2017 2:41 pm

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.
 
el berto
Member Candidate
Member Candidate
Posts: 223
Joined: Wed Sep 26, 2007 10:53 am

Re: Wi-Fi on-off switch

Mon May 20, 2019 11:30 am

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?"...
 
kelner
just joined
Posts: 10
Joined: Fri Sep 28, 2018 2:10 pm

Re: Wi-Fi on-off switch

Tue Oct 27, 2020 1:00 pm

/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]"; };
}

 
hengst
Frequent Visitor
Frequent Visitor
Posts: 91
Joined: Sun Jan 03, 2010 3:04 pm

Re: Wi-Fi on-off switch

Thu Nov 26, 2020 11:14 am

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 "
 
rl2019
just joined
Posts: 3
Joined: Wed Nov 06, 2019 12:58 pm

Re: Wi-Fi on-off switch

Tue Dec 29, 2020 5:13 pm

/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?
 
User avatar
mkx
Forum Guru
Forum Guru
Posts: 12651
Joined: Thu Mar 03, 2016 10:23 pm

Re: Wi-Fi on-off switch

Tue Dec 29, 2020 7:16 pm

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.
 
samueljazz
just joined
Posts: 1
Joined: Fri Apr 09, 2021 11:01 am

Re: Wi-Fi on-off switch

Fri Apr 09, 2021 11:49 am

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.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 12445
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

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

Mon May 17, 2021 11:13 am

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"
Last edited by rextended on Sat Sep 11, 2021 11:39 pm, edited 4 times in total.
 
enlace101
Frequent Visitor
Frequent Visitor
Posts: 51
Joined: Thu Jan 03, 2019 8:03 pm

Re: Wi-Fi on-off switch

Mon May 17, 2021 10:37 pm

Thank you. I'll try it tomorrow
 
Triforce
just joined
Posts: 3
Joined: Wed Sep 22, 2021 9:47 pm

Re: Wi-Fi on-off switch

Wed Sep 22, 2021 10:14 pm

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
 
dot02
Member Candidate
Member Candidate
Posts: 131
Joined: Tue Jun 15, 2021 1:23 am

Re: Wi-Fi on-off switch

Mon Oct 31, 2022 7:07 pm

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!
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 12445
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Wi-Fi on-off switch

Mon Oct 31, 2022 7:13 pm

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
}
Last edited by rextended on Mon Oct 31, 2022 7:17 pm, edited 2 times in total.
 
dot02
Member Candidate
Member Candidate
Posts: 131
Joined: Tue Jun 15, 2021 1:23 am

Re: Wi-Fi on-off switch

Mon Oct 31, 2022 7:16 pm

comments are welcome to improve the script! However, the script does work as it is.
 
dot02
Member Candidate
Member Candidate
Posts: 131
Joined: Tue Jun 15, 2021 1:23 am

Re: Wi-Fi on-off switch

Mon Oct 31, 2022 7:19 pm

Your script works very well, too, so I switched to this version too. thanks!
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 12445
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Wi-Fi on-off switch

Mon Oct 31, 2022 7:21 pm

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])
 
dot02
Member Candidate
Member Candidate
Posts: 131
Joined: Tue Jun 15, 2021 1:23 am

Re: Wi-Fi on-off switch

Mon Oct 31, 2022 7:25 pm

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!
:)
 
dot02
Member Candidate
Member Candidate
Posts: 131
Joined: Tue Jun 15, 2021 1:23 am

Re: Wi-Fi on-off switch

Mon Oct 31, 2022 7:55 pm

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...
 
gotsprings
Forum Guru
Forum Guru
Posts: 2285
Joined: Mon May 14, 2012 9:30 pm

Re: Wi-Fi on-off switch

Tue Nov 01, 2022 7:09 pm

Need like a 3 position toggle.
Forced On
Forced Off
Use the Scheduler
 
User avatar
anav
Forum Guru
Forum Guru
Posts: 21360
Joined: Sun Feb 18, 2018 11:28 pm
Location: Nova Scotia, Canada
Contact:

Re: Wi-Fi on-off switch

Wed Nov 02, 2022 12:24 am

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!!!
 
csaba
just joined
Posts: 1
Joined: Tue Apr 16, 2024 7:29 am

Re: Wi-Fi on-off switch

Tue Apr 16, 2024 7:35 am

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
 
User avatar
normis
MikroTik Support
MikroTik Support
Posts: 26823
Joined: Fri May 28, 2004 11:04 am
Location: Riga, Latvia
Contact:

Re: Wi-Fi on-off switch

Tue Apr 16, 2024 8:22 am

Make a new topic for your other scripting questions, no need to raise old topic about button use

Who is online

Users browsing this forum: erlinden, GoogleOther [Bot], holvoetn, mkx and 11 guests