Page 1 of 1
enable / disable radio script
Posted: Tue Jun 26, 2012 10:21 pm
by smilem
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/viewtopic.php ... 21#p160693
but it only disables the interface and I need to turn off the transmitter/radio
Thank you.
Re: enable / disable radio script
Posted: Wed Jun 27, 2012 10:11 pm
by smilem
Nobody knows how to turn off radio with scripting
Re: enable / disable radio script
Posted: Thu Jun 28, 2012 6:28 pm
by TheWiFiGuy
Surely disabling the interface disables the wireless?
Re: enable / disable radio script
Posted: Fri Jun 29, 2012 7:31 pm
by c0d3rSh3ll
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
Re: enable / disable radio script
Posted: Wed Jul 04, 2012 10:32 am
by smilem
Thank you the above commands work perfect. Is there a way (script command) to change the wlan card tx power?
Re: enable / disable radio script
Posted: Wed Jul 04, 2012 7:17 pm
by c0d3rSh3ll
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
Re: enable / disable radio script
Posted: Mon Jul 09, 2012 3:12 am
by smilem
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
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.
Re: enable / disable radio script
Posted: Thu Jul 19, 2012 11:37 pm
by Base122
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";
Re: enable / disable radio script
Posted: Wed Jul 25, 2012 4:23 am
by smilem
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/viewtopic.php?f=9&t=63522
Re: enable / disable radio script
Posted: Fri Mar 22, 2013 6:55 pm
by murray654
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)
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
Re: enable / disable radio script
Posted: Sat Mar 23, 2013 5:27 am
by skot
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
Re: enable / disable radio script
Posted: Sun Mar 24, 2013 10:36 pm
by murray654
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
Thanks.
I installed the NTP package and now it appears to work.
I never upgraded, so it works in v5.14
Re: enable / disable radio script
Posted: Mon Jun 03, 2013 12:33 pm
by triplostrike
I test on 5.25 all solution (in this post) for disable/enable wlan but wired connection together go down .
Have an idea ???
Thanks
Re: enable / disable radio script
Posted: Tue Nov 04, 2014 7:00 am
by Mars67
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.
Re: enable / disable radio script
Posted: Thu Nov 06, 2014 3:50 am
by Mars67
I also installed the NTP package but still get the same result.
Re: enable / disable radio script
Posted: Thu Nov 06, 2014 1:59 pm
by Mars67
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
Re: enable / disable radio script
Posted: Sun Nov 09, 2014 8:58 pm
by Mars67
Anyone???
Re: enable / disable radio script
Posted: Mon Nov 10, 2014 6:39 am
by jarda
You mean to check if it is really synchronised or just reported as synchronised?
Re: enable / disable radio script
Posted: Mon Nov 10, 2014 8:10 am
by Mars67
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
Re: enable / disable radio script
Posted: Mon Nov 10, 2014 9:30 am
by jarda
Unfortunatelly there is no such property like "status":
ros code
[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-synchronized
see 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).
Re: enable / disable radio script
Posted: Mon Nov 10, 2014 12:57 pm
by Mars67
Yes that is what I wanted to know thanks. I will give it a try. Still trying to learn ROS syntax.
Thank you very much Jarda.
Re: enable / disable radio script
Posted: Mon Nov 10, 2014 7:32 pm
by jarda
Glad I could point you to a better way. Post your achievements if any as they could help someone in similar situation.
Re: enable / disable radio script
Posted: Fri Dec 12, 2014 10:27 pm
by mmv
In this situation I check
[/system ntp client get last-update-before] < 3* [/system ntp client get poll-interval]
# tested on v5.4
# work with ntp package
# Resolve NTP server ip from name if time not synchronized
#
# Set ntp server names. Set to empty striing to keep untouched
:local primaryntp "ru.pool.ntp.org"
:local secondaryntp "2.ru.pool.ntp.org"
#
:if ([:len [/system package find name=ntp]] <= 0) do={
:error "NTP update script work only with ntp package"
}
/system ntp client
:if ([get status] != "synchronized") do={
:put "First NTP unsync"
:delay 60;
:if ([get status] != "synchronized") do={
:put "Second NTP unsync. Update NTP IP.";
:if ([:len $primaryntp] > 0) do={
set primary-ntp [:resolve $primaryntp]}
:if ([:len $secondaryntp] > 0) do={
set secondary-ntp [:resolve $secondaryntp]}
set enabled=no;
:delay 1;
set enabled=yes;
:log warning "NTP client IP updated."
}
}
It still dont make problems. Now work on 6.23 but i dont do deep verify.
Unfortunatelly there is no such property like "status":
ros code
[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-synchronized
see 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).
Re: enable / disable radio script
Posted: Tue May 26, 2015 11:04 am
by gvango
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";
It works GREAT..!!!
I use it and tested RB-751G-2HnD with OS versions 5.19, 6.27 and 6.28 and it works perfectly.
Thank James for a terrific script.
I hope to also find one to do the same with an ethernet port..!!
George V.
Re: enable / disable radio script
Posted: Tue Sep 08, 2015 11:15 pm
by miczx
Hi,
I found all necessary steps here:
http://mlapshin.com/index.php/2015/09/0 ... -dads-job/
How to create scripts
- Open System -> Scripts window
Press Add button and the script editor window will open
Type a script name like DisableWLAN
Select policies required by the script or check all of them
Type script into the source text area: interface wireless disable wlan1
Make sure you are using the proper name of the wireless interface. It could be found in the Interfaces section.
Next you can try to test the script with “Run Script” button
Save the script with “OK” button
Create a similar EnableWLAN script.
How to schedule scripts
- Open System -> Scheduler window
Press Add button to open the Scheduler window
Type some meaningful name for the scheduled task like DisableWLAN
Type the name of your script into the On Event text area like DisableWLAN
Select the start date, start time (hh:mm:ss format) and the interval for repeating the action like 1d 00:00:00 (it means one day and no hours, minutes and secs)
Select required policies or check them all
Save the schedule with “OK” button
Repeat the same to schedule the enabling script
Re: enable / disable radio script
Posted: Wed Sep 09, 2015 12:14 pm
by Krisken
Re: enable / disable radio script
Posted: Thu Oct 29, 2015 9:28 pm
by sonnyboy
Thought i would use this nice tutorial to keep my children off internet in the mornings
Edit
//Sonny
Re: enable / disable radio script
Posted: Sat Oct 31, 2015 11:00 am
by sonnyboy
This works just like a charm
Is there any way to make the schema only works on weekends, Saturday and Sunday?