【RouterOS】—— How to schedule wireless
Source : http://forum.mikrotik.com/viewtopic.php?f=9&t=63139
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.- # 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";
複製代碼 |