Community discussions

MikroTik App
 
DottorT86
newbie
Topic Author
Posts: 36
Joined: Fri Aug 09, 2019 7:51 am

hAP AC2 - Mode button to enable/disable wifi

Fri Apr 02, 2021 10:57 am

Hi everybody,
I know this topic has been raised many times but I have not been able to find a solution to my case.
I would like to use the "mode button" to activate / deactivate the wifi on my hAP AC2 following these rules:
- if wlan1 or wlan2 or both are enabled then disable both of them
- if wlan1 and wlan2 are both disabled then enable them both
I made many attempts and with the last attempt I was forced to do a factory reset.
This is my last attempt:
:local int1 wlan1
:local int2 wlan2
:local status1 [interface get $int1 enabled]
:local status2 [interface get $int2 enabled]
:if ($status1=true) or ($status2=true) do={
  /interface disable [/interface find name=$int1,$int2]
};
:if ($status1=false) and ($status2=false) do={
  /interface enable [/interface find name=$int1,$int2]
};
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3291
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: hAP AC2 - Mode button to enable/disable wifi  [SOLVED]

Fri Apr 02, 2021 5:29 pm

Here you go. (Tested on hAP AC2)

Make a script with name

wifi-change
:if ([/interface wireless get wlan1 disabled]=yes) do={
	/interface wireless set wlan1 disabled=no
	:log info message="Wifi turned on"
	} else={
	/interface wireless set wlan1 disabled=yes
	:log info message="Wifi turned off"
}
Add this from cli
/system routerboard mode-button set on-event=wifi-change enabled=yes
Or copy this to cli and take all in one go.
/system script
add dont-require-permissions=no name=wifi-change owner=admin policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon source=":if ([/\
    interface wireless get wlan1 disabled]=yes) do={\r\
    \n\t/interface wireless set wlan1 disabled=no\r\
    \n\t:log info message=\"Wifi turned on\"\r\
    \n\t} else={\r\
    \n\t/interface wireless set wlan1 disabled=yes\r\
    \n\t:log info message=\"Wifi turned off\"\r\
    \n}"
/system routerboard mode-button
set enabled=yes on-event=wifi-change
Remember AC2 has two interface, so to change 5Ghz as well, just add
/interface wireless set wlan2 disabled=no
/interface wireless set wlan2 disabled=yes
 
DottorT86
newbie
Topic Author
Posts: 36
Joined: Fri Aug 09, 2019 7:51 am

Re: hAP AC2 - Mode button to enable/disable wifi

Fri Apr 02, 2021 8:25 pm

Thank you so much for your reply!!!
I have made some changes to your script to suit my needs and now it seems to work perfectly! Thank you very much!
:if ([/interface wireless get wlan1 disabled]=no or [/interface wireless get wlan2 disabled]=no) do={
	/interface wireless set wlan1 disabled=yes
	/interface wireless set wlan2 disabled=yes
	:log info message="Wifi turned off"
	} else={
	/interface wireless set wlan1 disabled=no
	/interface wireless set wlan2 disabled=no
	:log info message="Wifi turned off"
}
Last edited by DottorT86 on Fri Apr 02, 2021 8:36 pm, edited 1 time in total.
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3291
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: hAP AC2 - Mode button to enable/disable wifi

Fri Apr 02, 2021 8:35 pm

You do not need to test both wifi interface since you always change them at the same time.
But if for some reason interface are not the same status, you change is ok.
Your log info are the same for on/off, so you need to fix that.

PS no need to quote the whole post above you. Use Post Reply button under the post insted.
 
DottorT86
newbie
Topic Author
Posts: 36
Joined: Fri Aug 09, 2019 7:51 am

Re: hAP AC2 - Mode button to enable/disable wifi

Fri Apr 02, 2021 8:40 pm

You do not need to test both wifi interface since you always change them at the same time.
But if for some reason interface are not the same status, you change is ok.
I made those changes for this reason.

Sorry for the previous quote. I just removed it.

Thank you again
 
User avatar
pothi
newbie
Posts: 46
Joined: Fri Sep 14, 2018 7:48 pm
Location: Srivilliputhur, Tamil Nadu, India
Contact:

Re: hAP AC2 - Mode button to enable/disable wifi

Thu May 27, 2021 7:24 am

If we have more wireless interfaces (than the default wlan1 and wlan2), then the following code works across the board...
:if ([/interface wireless get wlan1 disabled]=no) do={
	/interface wireless disable [find]
	:log info message="Wifi turned off"
	} else={
	/interface wireless enable [find]
	:log info message="Wifi turned on"
}

Who is online

Users browsing this forum: No registered users and 25 guests