enable / disable radio script

Hello, I’m looking for a way to enable radio at 8am and disable at 10pm every day.

As I found out I need a one script to turn it off, then another to turn it back on. I need to schedule the scripts.

I have no idea how to write scripts, found this http://forum.mikrotik.com/t/create-schedule-for-wifi/29291/1
but it only disables the interface and I need to turn off the transmitter/radio

Thank you.

Nobody knows how to turn off radio with scripting :open_mouth:

Surely disabling the interface disables the wireless?

first add a scheduler with this script for enable the interface wlan1

interface wireless enable  wlan1

and then add other scheduler wiht this script for disable interface wlan1

interface wireless disable wlan1

Thank you the above commands work perfect. Is there a way (script command) to change the wlan card tx power?

interface wireless set wlan1 tx-power=20 tx-power-mode=all-rates-fixed

change tx-power for your txpower, remember is in dbm


if my answer helped you, please give me karma

I gave you Karma, I always do for posts that are helpful :slight_smile:

Mikrotik sugests to use “card-rates” insted of “all-rates-fixed” no? I have a new idea, need your help a script to detect if there a reconnected users that sets predefined tx rate is possible? The idea is to use 2 scripts.

Scripts would be ran at an interval set in scheduler like every 10sec.

1st. script would check

if interface wlan1 is enabled

if true and there are connected authenticated WPA2 clients the script then would set tx rate based on client signal strenght:

if client signal strenght <=-60dbm signal strenght set tx power to 15dbm card rates.
if client signal strenght <=-70dbm signal strenght set tx power to 16dbm card rates.
if client signal strenght <=-80dbm signal strenght set tx power to default rates.

2nd. script would check if there are connected clients then it would set lower tx rate like 15dbm if nobody is connected, else do nothing.

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";

Thank you for your script, do you have ideas about the tx power script I described on my post above or the
script to set wlan3 frequency same as scanned frequency http://forum.mikrotik.com/t/set-wlan3-frequency-same-as-scanned-frequency/57994/1

I tried this and it does not work.

I get “Radio name = wlan1” in the log then nothing.

Any packages I need to get this to work?

my version is 5.14 and the equipment is RB411U

Base122’s script was tested on v5.19… that might be the problem, might not. Sometimes syntax changes between versions. I noticed that the following line errors out for me on v5.22 because the “status” option does not exist (no info about it on the wiki). I wonder if the separate NTP package is being used instead of the default SNTP?
:local NTPSyncState [/system ntp client get status];

What I would do is enclose the entire script in curly braces: { }, and then paste it in the terminal. Then you can see where the error is and know where to start fixing :slight_smile:

Thanks.

I installed the NTP package and now it appears to work.

I never upgraded, so it works in v5.14

I test on 5.25 all solution (in this post) for disable/enable wlan but wired connection together go down .

Have an idea ???

Thanks

I have a RB951G running RouterOS 6.2 and I have tried to run this script. I am getting the following Script Error: not enough permissions (9).

I have checked the user rights and it seems as if I have full administrator rights. Any assistance would be much appreciated thanks.

I also installed the NTP package but still get the same result.

I’m going through somewhat of a learning curve here. RoS 6.21.1 also does not support the “status” option. but when I run \system ntp client print: it displays the following info.

enabled: yes
mode: unicast
primary-ntp: 146.64.24.58
secondary-ntp: 146.64.28.1
dynamic-servers:
status: synchronized

How would use a script to check if ntp time is synchronised?

Thanks

Anyone???

You mean to check if it is really synchronised or just reported as synchronised?

Thanks for the reply.

If you look at the preceding script, with my limited understanding, it is just to check if it is reported as synchronised.

ie Base122 used the following code to check the status of synchronisation [/system ntp client get status]; but the status option apparently does not exist anymore but clearly it reports on the status.

If I do :system ntp client print; then I get the status of the NTP client which includes – status: synchronised

When I use the following command
:local NTPSyncState [/ system ntp client get status];
:log info “NTPSyncState = $NTPSyncState”

All I see in the log is NTPSyncState =


Thanks

Unfortunatelly there is no such property like “status”:
[user@router] > /system ntp client get
active-server enabled last-bad-packet-before last-bad-packet-reason last-update-from poll-interval secondary-ntp value-name
dynamic-servers last-adjustment last-bad-packet-from last-update-before mode primary-ntp server-dns-names
[user@router] > /system ntp client print
enabled: yes
primary-ntp: 194.109.22.18
secondary-ntp: 216.171.120.36
mode: unicast
poll-interval: 15m
active-server: 194.109.22.18
last-update-from: 194.109.22.18
last-update-before: 4m13s310ms
last-adjustment: 4ms590us
last-bad-packet-from: 216.171.120.36
last-bad-packet-before: 17h6m33s300ms
last-bad-packet-reason: server-not-synchronizedsee manual:
http://wiki.mikrotik.com/wiki/Manual:System/Time

Maybe you can check if last-bad-packet-before has greater value than last-update-before. It means that success was more recently than fail so you can conclude you are fine with time. Also, I would check if the last-update-before is not older then some reasonable period (e.g. 24H).