# How to optimise TX power for ESP8266?

I have multiple ESP8266 units programmed using Arduino SDK and I would like each one of them to adjust the transmission power to lower the power requirements.

Arduino allows setting the TX power of the ESP8266 using the function WiFi.setOutputPower(), however it is not clear to me how to choose that value.

I know that RFM69 using the LowPower library has automatic gain control using the ACK packet sent by another RFM69 module. However, with ESP8266 there is a standard AP and a similar approach would not be obvious.

How can I perform optimal gain control?

This question is independent from the choice of the WiFi mode b/g/n using WiFi.setPhyMode().

Edit

An idea could be to detect AP station signal strength and transmit at a power level offset by a fixed amount, decreasing that delta by one tick at every wake up, until no connection is achievable. At that point the delta should be increased by an amount corresponding to a sort of hysteresis, to jump above the no-connection threshold, and kept.

After a predefined amount of successful wake ups, for example 100, the process of decreasing the calculated delta would be tried again.

For example: AP strength -60 dB, transmission +12 dB: success -> delta 48 dB is good.

Next wake up, delta 48.25 dB: is AP is at -55 dB, transmission would be 55-48.25 dB = 6.75 dB. If success, delta increased to 48.50 dB.

• one issue with that algo as described is that it seems to ignore time. the relatively high-level of the wifi lib masks repeated connection attempts. Think of a ping with a 25% return rate, it's going to take at least 4X as much power to transmit the data 4 times. If you can get the quality to 50%, you'll use half as much wifi, and wifi is 80%+ of the ESP's current draw. in short, i would drop power until half my attempts took twice as long as other attempts, then tick it back a notch or two for one bounce connections. Commented Oct 8, 2017 at 6:36
• Well the connection time is the first thing that can be monitored easily and if significantly higher than the one at maximum power, failure can be recorded.
– FarO
Commented Oct 8, 2017 at 19:28
• Is the reason your WiFi.setOutputPower() link points to that "links2004" fork of the ESP8266 core for Arduino simply that the fork has better documentation of the function than the parent repo (esp8266/Arduino)? Commented Nov 4, 2017 at 6:00
• @per1234 I found that one first
– FarO
Commented Nov 4, 2017 at 16:12

I would like ... to adjust the transmission power to lower the power requirements.

Is your goal to reduce overall/average power consumption, or peak current draw? If the former, then because of the high-level nature of the wifi API exposed by the ESP system, you may get a greater level of success by optimizing the time you are connected, rather than the power consumption.

That is, make sure WiFi radio is disabled while you are preparing whatever data you may wish to send over WiFi, then turn the radio on, connect+send, go back to sleep.

This blog post gives experimental details, but the gist is

In `Setup()`:

``````WiFi.mode( WIFI_OFF );
WiFi.forceSleepBegin();
delay( 1 );
``````

Just before you choose to connect:

``````WiFi.forceSleepWake();
delay( 1 );

// Bring up the WiFi connection
WiFi.mode( WIFI_STA );
WiFi.begin( WLAN_SSID, WLAN_PASSWD );
``````

And, when you go to sleep, tell the system to keep the radio off by default:

``````WiFi.disconnect( true );
delay( 1 );

// WAKE_RF_DISABLED to keep the WiFi radio disabled when we wake up
ESP.deepSleep( SLEEPTIME, WAKE_RF_DISABLED );
``````

Part 3 of this blog also notes that if you will continually be connecting to the same WiFi network, you can tell the ESP8266 to not spend the time loading the previous connection's details from flash memory, but requiring you to provide them in the connection call:

``````WiFi.forceSleepWake();
delay( 1 );

// Disable the WiFi persistence.  The ESP8266 will not load and save WiFi settings in the flash memory.
WiFi.persistent( false );

WiFi.mode( WIFI_STA );
WiFi.begin( WLAN_SSID, WLAN_PASSWD );
``````
• My idea was to add TX power control in addition to those steps, to get an even lower consumption: optimisation of connection time is something known.
– FarO
Commented Feb 9, 2018 at 8:55