電訊茶室's Archiver

角色 發表於 2014-10-5 09:39

【RouterOS】—— How to schedule wireless

Source : [url]http://forum.mikrotik.com/viewtopic.php?f=9&t=63139[/url]

Had a requirement to set the wireless radio on a RB751U to switch on and off at certain times.
E.g. On during business hours only (07:00 - 17:00)

The simplest solution was to use the scheduler to enable and disable the radio at the required times.
However, if the router was powered off sometime during the night in this example and only switched on after the 07:00 ON time, the scheduler ON time event, would never happen and the radio would remain off.

This script checks at whatever scheduled intervals the user requires, if the radio is supposed to be ON or OFF and then sets it accordingly.

It could be adapted for example to enable and disable your 3G modem WAN link, if you only wanted the router to have an active internet connection for certain time periods for example.[code]
# Script to ensure wireless lan radio is ON or OFF #
# between user selected times #
# The radio ON/OFF operation will not be performed if the system #
# clock is not in sync with local time, unless so required #
# Remember router is set back to default time after a reboot #
# Schedule this script at required intervals #
# Written by Peter James 2012-07-19 #
# Tested on RB751U and RouterOS v5.19 #

#####################################
## Set the Radio ON and OFF times here ##
:local RadioOnTime "07:00";
:local RadioOffTime "17:00";

# set to "no" if clock is being set manually after each reboot #
# set to "yes" if clock is being set using NTP client #
:local UseNTPClientStatus "yes";
#####################################

:log info "RadioOnOff Script Starting";
# get the name of the wlan radio interface #
:local RadioName [/interface get [find type=wlan] name];
:log info "Radio Name = $RadioName";

# First check if system clock has been syncronized with local time #
:local NTPSyncState [/system ntp client get status];
:log info "NTP Client Status = $NTPSyncState";

# Don't perform radio On or Off operation, if current real time is unknown, unless required #
:if (($NTPSyncState="synchronized") or ($UseNTPClientStatus="no")) do {

:local CurrentTime [/system clock get time];
:log info "Current Time = $CurrentTime";

# Check current ON or OFF status of radio #
:local RadioDisabled [/interface get $RadioName disabled];
:log info "Radio Disabled = $RadioDisabled";


# Where the ON time is set earlier than the OFF time #
:if ($RadioOnTime < $RadioOffTime) do {

# Radio should be ON between these times #
:if (($CurrentTime > $RadioOnTime) and ($CurrentTime < $RadioOffTime)) do {

if ($RadioDisabled=true) do {
:log info "Radio was OFF, now switching ON";
/interface enable $RadioName;
}
} else {

if ($RadioDisabled=false) do {
:log info "Radio was ON, now switching OFF";
/interface disable $RadioName;
}

}

}

# Where the ON time is set later than the OFF time #
:if ($RadioOnTime > $RadioOffTime) do {

# Radio should be OFF between these times #
:if (($CurrentTime < $RadioOnTime) and ($CurrentTime > $RadioOffTime)) do {

if ($RadioDisabled=false) do {
:log info "Radio was ON, now switching OFF";
/interface disable $RadioName;
}
} else {

if ($RadioDisabled=true) do {
:log info "Radio was OFF, now switching ON";
/interface enable $RadioName;
}

}

}

} else {

:log info "System clock may not be synchronized to local time, unable to perform operation";

}

:log info "RadioOnOff Script completed";
[/code]

carlchan 發表於 2016-5-3 17:39

How to make it for "Mikrotik hAP AC - RB962UiGS-5HacT2HnT"
dual wireless ...?

角色 發表於 2016-5-3 19:20

Just select the wireless that you want. Both wireless interfaces can be used at the same time.

carlchan 發表於 2016-5-3 20:18

[i=s] 本帖最後由 carlchan 於 2016-5-3 20:20 編輯 [/i]

It get error ...
Need to change line 22?
I changed but get error

角色 發表於 2016-5-4 00:07

[b]回復 [url=http://www.telecom-cafe.com/forum/redirect.php?goto=findpost&pid=42759&ptid=6414]4#[/url] [i]carlchan[/i] [/b]

I mis-interpreted your message. The code that I just copied from other website. The script is, I believe, applicable to single wireless interface. You need to modify it if you are able to do so for dual wireless interfaces.

carlchan 發表於 2016-5-4 10:20

Finally , I use the following with Scheduler:

:log info "Wireless , now switching ON";
/interface enable "wlan-2G";
/interface enable "wlan-5G";

:log info "Wireless , now switching OFF";
/interface disable "wlan-2G";
/interface disable "wlan-5G";

角色 發表於 2016-5-4 16:27

Thanks you very much for your information.

You meant you have two scripts running at different scheduled time interval, right?

頁: [1]

Powered by Discuz! Archiver 7.2  © 2001-2009 Comsenz Inc.