mirror of
https://github.com/arendst/Tasmota.git
synced 2025-07-22 10:16:30 +00:00
Refactor dynamic wifi tx power
This commit is contained in:
parent
57f85ae478
commit
4a7e4f9a17
@ -1242,9 +1242,7 @@ void Every100mSeconds(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (0 == Settings->wifi_output_power) {
|
WiFiSetTXpowerBasedOnRssi();
|
||||||
WiFiSetTXpowerBasedOnRssi();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*-------------------------------------------------------------------------------------------*\
|
/*-------------------------------------------------------------------------------------------*\
|
||||||
@ -2227,7 +2225,7 @@ void GpioInit(void)
|
|||||||
TasmotaGlobal.i2c_enabled = I2cBegin(Pin(GPIO_I2C_SDA), Pin(GPIO_I2C_SCL));
|
TasmotaGlobal.i2c_enabled = I2cBegin(Pin(GPIO_I2C_SDA), Pin(GPIO_I2C_SCL));
|
||||||
#ifdef ESP32
|
#ifdef ESP32
|
||||||
if (TasmotaGlobal.i2c_enabled) {
|
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
|
#endif
|
||||||
}
|
}
|
||||||
@ -2236,7 +2234,7 @@ void GpioInit(void)
|
|||||||
if (TasmotaGlobal.i2c_enabled_2) {
|
if (TasmotaGlobal.i2c_enabled_2) {
|
||||||
TasmotaGlobal.i2c_enabled_2 = I2c2Begin(Pin(GPIO_I2C_SDA, 1), Pin(GPIO_I2C_SCL, 1));
|
TasmotaGlobal.i2c_enabled_2 = I2c2Begin(Pin(GPIO_I2C_SDA, 1), Pin(GPIO_I2C_SCL, 1));
|
||||||
if (TasmotaGlobal.i2c_enabled_2) {
|
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
|
#endif
|
||||||
|
@ -198,7 +198,6 @@ void WiFiSetSleepMode(void)
|
|||||||
WiFi.setSleepMode(WIFI_MODEM_SLEEP); // Sleep (Esp8288/Arduino core and sdk default)
|
WiFi.setSleepMode(WIFI_MODEM_SLEEP); // Sleep (Esp8288/Arduino core and sdk default)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
WifiSetOutputPower();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WifiBegin(uint8_t flag, uint8_t channel) {
|
void WifiBegin(uint8_t flag, uint8_t channel) {
|
||||||
@ -224,6 +223,7 @@ void WifiBegin(uint8_t flag, uint8_t channel) {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
WiFiSetSleepMode();
|
WiFiSetSleepMode();
|
||||||
|
WifiSetOutputPower();
|
||||||
// if (WiFi.getPhyMode() != WIFI_PHY_MODE_11N) { WiFi.setPhyMode(WIFI_PHY_MODE_11N); } // B/G/N
|
// 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
|
// if (WiFi.getPhyMode() != WIFI_PHY_MODE_11G) { WiFi.setPhyMode(WIFI_PHY_MODE_11G); } // B/G
|
||||||
#ifdef ESP32
|
#ifdef ESP32
|
||||||
@ -972,14 +972,15 @@ String WifiGetOutputPower(void) {
|
|||||||
void WifiSetOutputPower(void) {
|
void WifiSetOutputPower(void) {
|
||||||
if (Settings->wifi_output_power) {
|
if (Settings->wifi_output_power) {
|
||||||
WiFi.setOutputPower((float)(Settings->wifi_output_power) / 10);
|
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) {
|
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();
|
const WiFiMode_t cur_mode = WiFi.getMode();
|
||||||
if (cur_mode == WIFI_OFF) { return; }
|
if (cur_mode == WIFI_OFF) { return; }
|
||||||
|
|
||||||
@ -1021,7 +1022,7 @@ void WiFiSetTXpowerBasedOnRssi(void) {
|
|||||||
delay(Wifi.last_tx_pwr < min_tx_pwr); // If increase the TX power, give power supply of the unit some rest
|
delay(Wifi.last_tx_pwr < min_tx_pwr); // If increase the TX power, give power supply of the unit some rest
|
||||||
/*
|
/*
|
||||||
if (Wifi.last_tx_pwr != min_tx_pwr) {
|
if (Wifi.last_tx_pwr != min_tx_pwr) {
|
||||||
AddLog(LOG_LEVEL_DEBUG, PSTR("WIF: TX power %d, Sensitivity %d, RSSI %d"), min_tx_pwr / 10, threshold/ 10, rssi / 10);
|
AddLog(LOG_LEVEL_DEBUG, PSTR("WIF: TX power %d, Sensitivity %d, RSSI %d"), min_tx_pwr / 10, threshold / 10, rssi / 10);
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
Wifi.last_tx_pwr = min_tx_pwr;
|
Wifi.last_tx_pwr = min_tx_pwr;
|
||||||
@ -1077,7 +1078,7 @@ void WifiConnect(void)
|
|||||||
}
|
}
|
||||||
#endif // ESP32
|
#endif // ESP32
|
||||||
WifiSetState(0);
|
WifiSetState(0);
|
||||||
WifiSetOutputPower();
|
// WifiSetOutputPower();
|
||||||
|
|
||||||
//#ifdef ESP8266
|
//#ifdef ESP8266
|
||||||
// https://github.com/arendst/Tasmota/issues/16061#issuecomment-1216970170
|
// https://github.com/arendst/Tasmota/issues/16061#issuecomment-1216970170
|
||||||
|
Loading…
x
Reference in New Issue
Block a user