Hello, I have a WiFi radio from Mikrotik that I switch on and off at certain hours. This with a script.
If there is a power failure, this script no longer works because the start time has been exceeded.
Can a script be created that reactivates the script?
why don’t you schedule a repeatable task and put the logic to trigger or not in the script?
I’m a noob in writing scripts.
Can you help me to turn on the WiFi every day from 7:00 am to 10:00 pm.
Looking at other posts, ex http://forum.mikrotik.com/t/if-time-between-help/130844/1 is a good start
:local time [/system clock get time];
:if ($time >= "07:00:00" && $time < "21:59:00") do={
:if (<is_wifi_off>) do={
:log warning "Switching wifi on"
# add code here
}
} else {
:if (<is_wifi_on>) do={
:log warning "Switching wifi off"
# add code here
}
}
trigger that every minute from 1970 midnight…
Edit: simplified script a bit
Ok, i try this and thanks for your reply.
Also you can create two scripts (one to turn on and the other to turn off) your WiFi, and create two tasks on scheduler to turn on and turn off the interface on the hours that you need.
Assuming that your clock is correct and your interface is “wlan1” you can try:
Script to turn on:
Name: EnableWlan
Script: interface wireless set wlan1 disabled=no
Script to turn off:
Name Disabled man
Script: interface wireless set wlan1 disabled=yes
Scheduler1:
Name: EnableWlan
Start time: 07:00:00
Interval: 1d 00:00:00
Event: EnableWlan
Scheduler2:
Name: DisableWlan
Start time: 22:00:00
Interval: 1d 00:00:00
Enent: DisableWlan
Regards.
@krafg I did this, but if the power goes out, this entire script is disrupted. This is because the start time of the first time it has started has passed.
I’m looking for a solution (a script) to correct the start time.
A kind of reset of this script so that it works again.
Hence why you need a script that will be triggered often and can determine what to do …
It’s weird. On scheduler, try to put on both the start date as 01 Jan 2019. Also try to use a NTP server to synchronize the time like pool.ntp.org or time.windows.com.
Regards.