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.
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";
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’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.
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”
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).