Community discussions

 
plisken
Forum Guru
Forum Guru
Topic Author
Posts: 2390
Joined: Sun May 15, 2011 12:24 am
Location: Belgium
Contact:

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

Thu Jun 13, 2019 9:37 pm

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?
 
User avatar
sebastia
Forum Guru
Forum Guru
Posts: 1593
Joined: Tue Oct 12, 2010 3:23 am
Location: Antwerp, BE

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

Thu Jun 13, 2019 10:02 pm

why don't you schedule a repeatable task and put the logic to trigger or not in the script?
 
plisken
Forum Guru
Forum Guru
Topic Author
Posts: 2390
Joined: Sun May 15, 2011 12:24 am
Location: Belgium
Contact:

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

Thu Jun 13, 2019 10:06 pm

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.
 
User avatar
sebastia
Forum Guru
Forum Guru
Posts: 1593
Joined: Tue Oct 12, 2010 3:23 am
Location: Antwerp, BE

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

Thu Jun 13, 2019 10:28 pm

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
Last edited by sebastia on Fri Jun 14, 2019 11:03 am, edited 4 times in total.
 
plisken
Forum Guru
Forum Guru
Topic Author
Posts: 2390
Joined: Sun May 15, 2011 12:24 am
Location: Belgium
Contact:

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

Thu Jun 13, 2019 11:43 pm

Ok, i try this and thanks for your reply.
 
User avatar
krafg
Member Candidate
Member Candidate
Posts: 193
Joined: Sun Jun 28, 2015 7:36 pm

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

Fri Jun 14, 2019 12:19 am

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.
Image
 
plisken
Forum Guru
Forum Guru
Topic Author
Posts: 2390
Joined: Sun May 15, 2011 12:24 am
Location: Belgium
Contact:

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

Fri Jun 14, 2019 5:32 am

@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.
 
User avatar
sebastia
Forum Guru
Forum Guru
Posts: 1593
Joined: Tue Oct 12, 2010 3:23 am
Location: Antwerp, BE

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

Fri Jun 14, 2019 11:00 am

Hence why you need a script that will be triggered often and can determine what to do ...
 
User avatar
krafg
Member Candidate
Member Candidate
Posts: 193
Joined: Sun Jun 28, 2015 7:36 pm

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

Fri Jun 14, 2019 6:13 pm

@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.
Image

Who is online

Users browsing this forum: No registered users and 4 guests