Refactor dynamic wifi tx power

This commit is contained in:
Theo Arends 2023-05-17 11:44:14 +02:00
parent 57f85ae478
commit 4a7e4f9a17
2 changed files with 11 additions and 12 deletions

View File

@ -1242,10 +1242,8 @@ void Every100mSeconds(void)
}
}
if (0 == Settings->wifi_output_power) {
WiFiSetTXpowerBasedOnRssi();
}
}
/*-------------------------------------------------------------------------------------------*\
* Every 0.25 second
@ -2227,7 +2225,7 @@ void GpioInit(void)
TasmotaGlobal.i2c_enabled = I2cBegin(Pin(GPIO_I2C_SDA), Pin(GPIO_I2C_SCL));
#ifdef ESP32
if (TasmotaGlobal.i2c_enabled) {
AddLog(LOG_LEVEL_DEBUG, PSTR("I2C: Pins bus1 SCL %d, SDA %d"), Pin(GPIO_I2C_SCL), Pin(GPIO_I2C_SDA));
AddLog(LOG_LEVEL_INFO, PSTR("I2C: Bus1 using GPIO%02d(SCL) and GPIO%02d(SDA)"), Pin(GPIO_I2C_SCL), Pin(GPIO_I2C_SDA));
}
#endif
}
@ -2236,7 +2234,7 @@ void GpioInit(void)
if (TasmotaGlobal.i2c_enabled_2) {
TasmotaGlobal.i2c_enabled_2 = I2c2Begin(Pin(GPIO_I2C_SDA, 1), Pin(GPIO_I2C_SCL, 1));
if (TasmotaGlobal.i2c_enabled_2) {
AddLog(LOG_LEVEL_DEBUG, PSTR("I2C: Pins bus2 SCL %d, SDA %d"), Pin(GPIO_I2C_SCL, 1), Pin(GPIO_I2C_SDA, 1));
AddLog(LOG_LEVEL_INFO, PSTR("I2C: Bus2 using GPIO%02d(SCL) and GPIO%02d(SDA)"), Pin(GPIO_I2C_SCL, 1), Pin(GPIO_I2C_SDA, 1));
}
}
#endif

View File

@ -198,7 +198,6 @@ void WiFiSetSleepMode(void)
WiFi.setSleepMode(WIFI_MODEM_SLEEP); // Sleep (Esp8288/Arduino core and sdk default)
}
}
WifiSetOutputPower();
}
void WifiBegin(uint8_t flag, uint8_t channel) {
@ -224,6 +223,7 @@ void WifiBegin(uint8_t flag, uint8_t channel) {
#endif
WiFiSetSleepMode();
WifiSetOutputPower();
// if (WiFi.getPhyMode() != WIFI_PHY_MODE_11N) { WiFi.setPhyMode(WIFI_PHY_MODE_11N); } // B/G/N
// if (WiFi.getPhyMode() != WIFI_PHY_MODE_11G) { WiFi.setPhyMode(WIFI_PHY_MODE_11G); } // B/G
#ifdef ESP32
@ -972,14 +972,15 @@ String WifiGetOutputPower(void) {
void WifiSetOutputPower(void) {
if (Settings->wifi_output_power) {
WiFi.setOutputPower((float)(Settings->wifi_output_power) / 10);
} else {
AddLog(LOG_LEVEL_DEBUG, PSTR("WIF: Dynamic Tx power enabled")); // WifiPower 0
}
}
/*
Dynamic WiFi transmit power based on RSSI lowering overall DC power usage.
Original idea by ESPEasy (@TD-er)
*/
void WiFiSetTXpowerBasedOnRssi(void) {
// Dynamic WiFi transmit power based on RSSI lowering overall DC power usage.
// Original idea by ESPEasy (@TD-er)
if (!Settings->flag4.network_wifi || Settings->wifi_output_power) { return; }
const WiFiMode_t cur_mode = WiFi.getMode();
if (cur_mode == WIFI_OFF) { return; }
@ -1077,7 +1078,7 @@ void WifiConnect(void)
}
#endif // ESP32
WifiSetState(0);
WifiSetOutputPower();
// WifiSetOutputPower();
//#ifdef ESP8266
// https://github.com/arendst/Tasmota/issues/16061#issuecomment-1216970170