Page 1 of 1

switch on and off wifi radio script don't work anymore

Posted: Thu Jun 13, 2019 9:37 pm
by plisken
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?

Re: switch on and off wifi radio script don't work anymore

Posted: Thu Jun 13, 2019 10:02 pm
by sebastia
why don't you schedule a repeatable task and put the logic to trigger or not in the script?

Re: switch on and off wifi radio script don't work anymore

Posted: Thu Jun 13, 2019 10:06 pm
by plisken
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.

Re: switch on and off wifi radio script don't work anymore

Posted: Thu Jun 13, 2019 10:28 pm
by sebastia
Looking at other posts, ex viewtopic.php?t=149298 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

Re: switch on and off wifi radio script don't work anymore

Posted: Thu Jun 13, 2019 11:43 pm
by plisken
Ok, i try this and thanks for your reply.

Re: switch on and off wifi radio script don't work anymore

Posted: Fri Jun 14, 2019 12:19 am
by krafg
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.

Re: switch on and off wifi radio script don't work anymore

Posted: Fri Jun 14, 2019 5:32 am
by plisken
@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.

Re: switch on and off wifi radio script don't work anymore

Posted: Fri Jun 14, 2019 11:00 am
by sebastia
Hence why you need a script that will be triggered often and can determine what to do ...

Re: switch on and off wifi radio script don't work anymore

Posted: Fri Jun 14, 2019 6:13 pm
by krafg
@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.
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.