lapsio
August 29, 2017, 2:09pm
1
Hi
I’m using mAP lite as my pocket swiss-knife ap / station for rackmount servers configuration when i need to connect them to dirty line or simply as ap on the go if there’s no wifi in around. I made quite streamlined config scheme and script that is simple on/off toggle for station / ap mode (more detailed defaults selection is done via entries comments). It uses cAP LED to indicate which mode is active. I’d like to be able to somehow “select” initial mode after router boots up without necessity to connect via required medium (wireless or wired) and log into admin panel. Of course it is using basic, necessary firewall policy so in ap mode it won’t allow me to get into config over ether1 or in station mode over wifi and the thing is I just might not be able to obtain device with rj45 / wifi in some places. So I need to somehow trigger it more physically. I thought about binding it to WPS button but iirc it wasn’t possible so…
Any other ideas? It’s brainstorm, all ideas are welcome. I thought about some clever way of detecting maybe if cable is plugged in during boot and if yes then select station mode, otherwise ap mode? idk. maybe someone has better idea.
lapsio:
Hi
I’m using mAP lite as my pocket swiss-knife ap / station for rackmount servers configuration when i need to connect them to dirty line or simply as ap on the go if there’s no wifi in around. I made quite streamlined config scheme and script that is simple on/off toggle for station / ap mode (more detailed defaults selection is done via entries comments). It uses cAP LED to indicate which mode is active. I’d like to be able to somehow “select” initial mode after router boots up without necessity to connect via required medium (wireless or wired) and log into admin panel. Of course it is using basic, necessary firewall policy so in ap mode it won’t allow me to get into config over ether1 or in station mode over wifi and the thing is I just might not be able to obtain device with rj45 / wifi in some places. So I need to somehow trigger it more physically. I thought about binding it to WPS button but iirc it wasn’t possible so…
Any other ideas? It’s brainstorm, all ideas are welcome. I thought about some clever way of detecting maybe if cable is plugged in during boot and if yes then select station mode, otherwise ap mode? idk. maybe someone has better idea.
Actually initial support for “mode-button” on hEX [RB750Gr3], when button is pressed, one script is runned.
RouterOS 6.40.2:
/system routerboard mode-button
set enabled=yes on-event="#script"
You can switch config inside script like <is ap-bridge ‘convert to station’ else ‘convert to ap-bridge’>
lapsio
August 31, 2017, 7:46pm
3
I ran into an issue. Many issues:
[lapsio@PiPi] > /system routerboard mode-button set enabled=yes on-event=autorun
Error, please generate supout file blah blah blah
So i upgraded to release-candidate. Now it doesn’t say anything. But I can’t really print value and it doesn’t seem to work
[lapsio@PiPi] /system routerboard mode-button> :put [get enabled]
[lapsio@PiPi] /system routerboard mode-button> print
[lapsio@PiPi] /system routerboard mode-button>
I found that it’s possible to use scheduler but… script doesn’t execute properly:
1 name="autorun" owner="lapsio" policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon last-started=aug/31/2017 21:35:28 run-count=25
source=
/log warning message="autorun start"
:delay delay-time=3s
/log warning message="autorun phase 1"
/system leds
set [find leds=wlan-led] type=off
set [find leds=link-act-led] type=off
:local choice "none"
/log warning message="autorun phase 2"
:while ($choice = "none") do={
/log warning message="autorun phase 3"
:if ($choice = "none") do={
:for counter=i from=1 to=10 do={
/log warning message="autorun phase 3b"
:delay delay-time=200ms
:if ([get [find leds=wlan-led] type] = "off") do={set [find leds=wlan-led] type=on} else={set [find leds=wlan-led] type=off}
:if ([/interface ethernet get ether1 running] = true) do={:set choice "ap"}
/log warning message="autorun phase 3c"
}
}
:if ($choice = "none") do={
:for counter=i from=1 to=10 do={
:delay delay-time=200ms
:if ([get [find leds=link-act-led] type] = "off") do={set [find leds=link-act-led] type=on} else={set [find leds=link-act-led] type=off}
:if ([/interface ethernet get ether1 running] = true) do={:set choice "station"}
}
}
}
/log warning message="autorun phase 4"
set [find leds=wlan-led] type=on
set [find leds=link-act-led] type=on
:delay delay-time=2s
set [find leds=wlan-led] type=wireless-status interface=wlan1
set [find leds=link-act-led] type=interface-activity interface=ether1
/log warning message="autorun phase 5"
:put $choice
:if ($choice = "ap") do={
/interface wireless set 0 mode=station disabled=no
:delay delay-time=2s
/system script run modetoggle
} else {
/interface wireless set 0 mode=ap-bridge disabled=no
:delay delay-time=2s
/system script run modetoggle
}
/log warning message="autorun end"
It stops on phase 3b according to logs. However when I run it manually via /system script run it works as expected :C
modetoggle does exactly what you said (if ap-bridge then change to station otherwise change to ap-bridge) I decided to split script in order to make it more flexible
Halp
Besides - it actually used to work properly but then after few reboots something crashed on mAP and I had to netinstall it. Now it stops just like I said even though I simply restored backup.
lapsio
August 31, 2017, 9:32pm
4
It turns out mikrotik is not ready after boot. Even after those 3 seconds. Waiting a bit more and doing everything really slowly makes scripts work properly. In case someone would be interested here are full scripts:
[lapsio@PiPi] /system script> print without-paging
Flags: I - invalid
0 name="modetoggle" owner="lapsio" policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon last-started=aug/31/2017 23:11:40 run-count=28
source=
if ([/interface wireless get 0 mode] = "station") do={
:put "enabling AP mode"
/log warning message="enabling AP mode"
/ip firewall filter
enable [find comment=ap]
disable [find comment=station]
/ip firewall nat
enable [find comment=ap]
disable [find comment=station]
/ip dhcp-client
enable [find comment=ap]
disable [find comment=station]
/ip dhcp-server
enable ap
disable station
/ip address
enable [find comment=ap]
disable [find comment=station]
/interface wireless security-profiles
:local newssid [get [find comment=ap] name]
:put $newssid
/interface wireless
set 0 ssid=$newssid security-profile=$newssid mode=ap-bridge
/system leds
:for counter=i from=0 to=39 do={
:delay delay-time=200ms
:if ([get [find leds=cap-led] type] = "off") do={set [find leds=cap-led] type=on} else={set [find leds=cap-led] type=off}
}
/system leds
set [find leds=cap-led] type=on
/ip dhcp-client
release [find comment=station]
renew [find comment=ap]
/interface wireless set 0 mode=ap-bridge
} else={
:put "enabling STATION mode"
/log warning message="enabling STATION mode"
/ip firewall filter
disable [find comment=ap]
enable [find comment=station]
/ip firewall nat
disable [find comment=ap]
enable [find comment=station]
/ip dhcp-client
disable [find comment=ap]
enable [find comment=station]
/ip dhcp-server
disable ap
enable station
/ip address
disable [find comment=ap]
enable [find comment=station]
/interface wireless security-profiles
:local newssid [get [find comment=station] name]
:put $newssid
/interface wireless
set 0 ssid=$newssid security-profile=$newssid mode=station
:delay delay-time=1s
/ip dhcp-client
renew [find comment=station]
release [find comment=ap]
/system leds
set [find leds=cap-led] type=off
}
1 name="autorun" owner="lapsio" policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon last-started=aug/31/2017 23:11:10 run-count=34
source=
/log warning message="autorun start"
/system leds
set [find leds=wlan-led] type=off
set [find leds=link-act-led] type=off
set [find leds=cap-led] type=off
:local choice "none"
:delay delay-time=2s
:for counter=i from=1 to=16 do={
:delay delay-time=125ms
set [find leds=wlan-led] type=on
set [find leds=link-act-led] type=off
:delay delay-time=125ms
set [find leds=wlan-led] type=off
set [find leds=link-act-led] type=on
:delay delay-time=125ms
set [find leds=link-act-led] type=off
set [find leds=cap-led] type=on
:delay delay-time=125ms
set [find leds=link-act-led] type=on
set [find leds=cap-led] type=off
}
set [find leds=wlan-led] type=off
set [find leds=link-act-led] type=off
set [find leds=cap-led] type=off
:delay delay-time=2s
:while ($choice = "none") do={
:if ($choice = "none") do={
:for counter=i from=1 to=20 do={
:delay delay-time=200ms
:if ([get [find leds=wlan-led] type] = "off") do={set [find leds=wlan-led] type=on} else={set [find leds=wlan-led] type=off}
:if ([/interface ethernet get ether1 running] = true) do={:set choice "ap"}
}
}
:if ($choice = "none") do={
:for counter=i from=1 to=20 do={
:delay delay-time=200ms
:if ([get [find leds=link-act-led] type] = "off") do={set [find leds=link-act-led] type=on} else={set [find leds=link-act-led] type=off}
:if ([/interface ethernet get ether1 running] = true) do={:set choice "station"}
}
}
}
set [find leds=wlan-led] type=on
set [find leds=link-act-led] type=on
:delay delay-time=1s
:put $choice
:if ($choice = "ap") do={
/interface wireless set 0 mode=station disabled=no
:delay delay-time=2s
/system script run modetoggle
} else={
/interface wireless set 0 mode=ap-bridge disabled=no
:delay delay-time=2s
/system script run modetoggle
}
:delay delay-time=1s
set [find leds=wlan-led] type=wireless-status interface=wlan1
set [find leds=link-act-led] type=interface-activity interface=ether1
/log warning message="autorun end"
They use LEDs quite a lot to indicate status of script execution and ask for choice but it looks quite nice overall.
TheDon
October 12, 2019, 4:39pm
5
I was so excited to try get this working - congrats if you did!
However, I cannot get the button to work and run a script when I click the button.
Incidentally - do you see the mode button on the /system/routerboard screen? It does not show up for me.
I am on firmware 6.54.6 on the Map-lite.
Even after running :
/system routerboard mode-button set on-event=SCRIPTNAME
and
/system routerboard mode-button set enabled=yes
When I press the mode-button I only see the following in the logs :
wlan1:WPS physical button pushed
eworm
October 13, 2019, 8:06pm
6
The mAP lite does not have a mode button.
bpwl
December 16, 2021, 10:40pm
7
Since 6.47.10 you can program the “reset” button