Community discussions

 
smilem
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 51
Joined: Tue Jun 26, 2012 10:16 pm

enable / disable radio script

Tue Jun 26, 2012 10:21 pm

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.
 
smilem
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 51
Joined: Tue Jun 26, 2012 10:16 pm

Re: enable / disable radio script

Wed Jun 27, 2012 10:11 pm

Nobody knows how to turn off radio with scripting :shock:
 
User avatar
TheWiFiGuy
Member
Member
Posts: 351
Joined: Thu Nov 24, 2011 7:26 pm
Location: UK

Re: enable / disable radio script

Thu Jun 28, 2012 6:28 pm

Surely disabling the interface disables the wireless?
----------------------
Mikrotik Consultant.
MTCNA, MTWCE, MTCTCE, MTCRE, MTCINE
 
User avatar
c0d3rSh3ll
Long time Member
Long time Member
Posts: 558
Joined: Mon Jul 25, 2011 9:42 pm
Location: [admin@Chile] >

Re: enable / disable radio script

Fri Jun 29, 2012 7:31 pm

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
nothing
 
smilem
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 51
Joined: Tue Jun 26, 2012 10:16 pm

Re: enable / disable radio script

Wed Jul 04, 2012 10:32 am

Thank you the above commands work perfect. Is there a way (script command) to change the wlan card tx power?
 
User avatar
c0d3rSh3ll
Long time Member
Long time Member
Posts: 558
Joined: Mon Jul 25, 2011 9:42 pm
Location: [admin@Chile] >

Re: enable / disable radio script

Wed Jul 04, 2012 7:17 pm

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
nothing
 
smilem
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 51
Joined: Tue Jun 26, 2012 10:16 pm

Re: enable / disable radio script

Mon Jul 09, 2012 3:12 am

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.
 
Base122
just joined
Posts: 10
Joined: Tue Mar 13, 2012 4:28 pm

Re: enable / disable radio script

Thu Jul 19, 2012 11:37 pm

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";
 
smilem
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 51
Joined: Tue Jun 26, 2012 10:16 pm

Re: enable / disable radio script

Wed Jul 25, 2012 4:23 am

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
 
murray654
newbie
Posts: 25
Joined: Sat Sep 15, 2007 1:28 pm
Location: Drakensberg, South Africa
Contact:

Re: enable / disable radio script

Fri Mar 22, 2013 6:55 pm

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
Oliviershoek Consulting
Safely Navigating your IT Storms
 
User avatar
skot
Long time Member
Long time Member
Posts: 586
Joined: Wed Nov 30, 2011 3:05 am

Re: enable / disable radio script

Sat Mar 23, 2013 5:27 am

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 :)
I don't need any karma... I have Ιησους Χριστος!
 
murray654
newbie
Posts: 25
Joined: Sat Sep 15, 2007 1:28 pm
Location: Drakensberg, South Africa
Contact:

Re: enable / disable radio script

Sun Mar 24, 2013 10:36 pm

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
Oliviershoek Consulting
Safely Navigating your IT Storms
 
triplostrike
just joined
Posts: 1
Joined: Mon Jun 03, 2013 12:22 pm

Re: enable / disable radio script

Mon Jun 03, 2013 12:33 pm

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

Have an idea ???

Thanks
 
Mars67
just joined
Posts: 9
Joined: Wed Jun 05, 2013 11:23 am

Re: enable / disable radio script

Tue Nov 04, 2014 7:00 am

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.
 
Mars67
just joined
Posts: 9
Joined: Wed Jun 05, 2013 11:23 am

Re: enable / disable radio script

Thu Nov 06, 2014 3:50 am

I also installed the NTP package but still get the same result.
 
Mars67
just joined
Posts: 9
Joined: Wed Jun 05, 2013 11:23 am

Re: enable / disable radio script

Thu Nov 06, 2014 1:59 pm

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
 
Mars67
just joined
Posts: 9
Joined: Wed Jun 05, 2013 11:23 am

Re: enable / disable radio script

Sun Nov 09, 2014 8:58 pm

Anyone???
 
jarda
Forum Guru
Forum Guru
Posts: 7601
Joined: Mon Oct 22, 2012 4:46 pm

Re: enable / disable radio script

Mon Nov 10, 2014 6:39 am

You mean to check if it is really synchronised or just reported as synchronised?
 
Mars67
just joined
Posts: 9
Joined: Wed Jun 05, 2013 11:23 am

Re: enable / disable radio script

Mon Nov 10, 2014 8:10 am

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
 
jarda
Forum Guru
Forum Guru
Posts: 7601
Joined: Mon Oct 22, 2012 4:46 pm

Re: enable / disable radio script

Mon Nov 10, 2014 9:30 am

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).
 
Mars67
just joined
Posts: 9
Joined: Wed Jun 05, 2013 11:23 am

Re: enable / disable radio script

Mon Nov 10, 2014 12:57 pm

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.
 
jarda
Forum Guru
Forum Guru
Posts: 7601
Joined: Mon Oct 22, 2012 4:46 pm

Re: enable / disable radio script

Mon Nov 10, 2014 7:32 pm

Glad I could point you to a better way. Post your achievements if any as they could help someone in similar situation.
 
mmv
Trainer
Trainer
Posts: 63
Joined: Wed Feb 24, 2010 5:03 pm
Location: Moscow, Russia
Contact:

Re: enable / disable radio script

Fri Dec 12, 2014 10:27 pm

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).
Mikhail Moskalev
 
gvango
just joined
Posts: 12
Joined: Fri Mar 16, 2012 11:21 pm

Re: enable / disable radio script

Tue May 26, 2015 11:04 am

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.
 
miczx
just joined
Posts: 3
Joined: Tue Sep 08, 2015 11:01 pm

Re: enable / disable radio script

Tue Sep 08, 2015 11:15 pm

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
 
Krisken
Member Candidate
Member Candidate
Posts: 132
Joined: Thu Oct 25, 2012 11:35 am

Re: enable / disable radio script

Wed Sep 09, 2015 12:14 pm

 
sonnyboy
newbie
Posts: 27
Joined: Fri May 03, 2013 7:45 am

Re: enable / disable radio script

Thu Oct 29, 2015 9:28 pm

Thought i would use this nice tutorial to keep my children off internet in the mornings :D

Edit

//Sonny
 
sonnyboy
newbie
Posts: 27
Joined: Fri May 03, 2013 7:45 am

Re: enable / disable radio script

Sat Oct 31, 2015 11:00 am

This works just like a charm :)

Is there any way to make the schema only works on weekends, Saturday and Sunday?

Who is online

Users browsing this forum: No registered users and 6 guests