Skip to content

Instantly share code, notes, and snippets.

@sub314xxl
Created April 10, 2024 04:41
Show Gist options
  • Save sub314xxl/1abca0918c92909491407b583ffab5b6 to your computer and use it in GitHub Desktop.
Save sub314xxl/1abca0918c92909491407b583ffab5b6 to your computer and use it in GitHub Desktop.
mikrotik wifi tricks
# 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";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment