Thursday, February 23, 2017

Modified script to reduce Wi-Fi transmitter power on schedule/at night (Mikrotik/RouterOS)

by / Saturday, 11 April 2015 / Published in Linux, BSD, Unix

There are multiple reasons to switch off your WiFi router at night - from lowering the risk to affect your health or cause insomnia to save planet's energy resources. Most routers do not have this feature, so you will have to do it manually. However, if you own a MikroTik RouterBOARD one, you can easily do it. Moreover, you can even make this automated!

Another alternative is to lower WiFi output power to minimal values. I usually run my router with 100mW output during the working hours, and 8 mW at night. Fortunately, Mikrotik RouterOS also allows to change this setting from scripts, so you can program your own power scheme.

There is a popular script on Mikrotik forums that does the thing described above. I modified it to match my case - where there are not only two values for day/night, but also different ones (higher than NormalPower - to reach a client far beyond my usual range). So this script lowers any transmitter power level to LowPower setting at night, and raises only LowPower level to NormalPower during the day.

Please take into account that the values below are in dBm. Also, effective output value is 3 dBm higher:

tx power

You can use PW = 10(PdBm + 3) / 10 / 1000 formula for this certain case or use this online tool (remember to add 3 dBm your values!).

Also you should take into account local regulations in different countries. Some countries restrict WiFi power to 100 mW (17 dBm->20dBm), some to 1 Watt (27 dBm->30dBm). Make sure you do not break the local laws.

# Script to turn down radio power based on a schedule
# Schedule this script to run every 15-30 minutes to make
# certain the changeover has occurred.
# User variables are listed below:
#####################################
## Set the Radio NormalPower and LowPower times here ##
:local RadioNormalPowerTime "08:00";
:local RadioLowPowerTime "00:30";
:local LowPower 6;
:local NormalPower 17;
:local RadioName "wlan1";
:local RadioPowerState;
:local RadioPower;
#####################################
:local CurrentTime [/system clock get time];
:set RadioPower [:put [/interface wireless get value-name=tx-power $RadioName]];
:if ($RadioPower = $LowPower) do {
		:set RadioPowerState 0;
} else {
	:if ($RadioPower > $NormalPower) do {
		:set RadioPowerState 2;
	} else {
		:set RadioPowerState 1;
	}
}
# Where the NormalPower time is set earlier than the LowPower time #
:if ($RadioNormalPowerTime < $RadioLowPowerTime) do {
# 	NormalPower interval #
	:if (($CurrentTime > $RadioNormalPowerTime) and ($CurrentTime < $RadioLowPowerTime)) do {	
		:if ($RadioPowerState=0) do {
			:log info "[$CurrentTime] Switching to NormalPower";
			:put [/interface wireless set $RadioName tx-power=$NormalPower];
		}
# 	LowPower interval #		
	} else {	
#		We should go to LowPower in any case at LowPower interval #
		:if ($RadioPowerState!=0) do {
			:log info "[$CurrentTime] Switching to LowPower";
			:put [/interface wireless set $RadioName tx-power=$LowPower];
		}
	}
}
# Where the NormalPower time is set later than the LowPower time #
:if ($RadioNormalPowerTime > $RadioLowPowerTime) do {
# 	LowPower interval #
	:if (($CurrentTime < $RadioNormalPowerTime) and ($CurrentTime > $RadioLowPowerTime)) do {
#		We should go to LowPower in any case at LowPower interval #
		:if ($RadioPowerState!=0) do {
			:log info "[$CurrentTime] Switching to LowPower";
			:put [/interface wireless set $RadioName tx-power=$LowPower];
		}
# 	NormalPower interval #
	} else {	
		:if ($RadioPowerState=0) do {
			:log info "[$CurrentTime] Switching to NormalPower";
			:put [/interface wireless set $RadioName tx-power=$NormalPower];
		}
	}
}
Read 2397 times Last modified on Saturday, 11 April 2015 12:27

Do you like this? Please share!

Simon Tushev

Simon is IT professional with interests in web design, electronics, photography and astronomy. He writes about PHP, Yii, Joomla!, Arduino and several other topics.

Welcome!

Here I publish articles related to my areas of interest, my brief notes that may save some time to others, as well as some of my works.

This site is a work in progress. I will add more sections in the future, such as

  • More photos to photogallery
  • More Joomla!-related articles
  • ...

 

themeforest

New Posts

Using dynamic GeoIP module with nginx (CentOS)

nginx introduced dynamic module support in v. 1.9.11. This brief article provides step-by-step procedure...

13-04-2016 in Linux, BSD, Unix

READ MORE

Visual difference between pseudo and true random data

This is is "random" image generated using PHP rand() function: And this is an image...

20-11-2015 in Blog

READ MORE

Best EEPROM practices

(this article is a work in progress). My own advice will be added later...   Having...

12-10-2015 in Arduino

READ MORE
Scroll to top

We use cookies, just to track visits to our website, we store no personal details Privacy policy