diff --git a/CHANGELOG.md b/CHANGELOG.md index 90c64bf08..389d150b4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,19 @@ All notable changes to this project will be documented in this file. ## [Unreleased] - Development -## [12.5.0.2] +## [12.5.0.3] +### Added +- Command ``WifiPower 0`` to enable dynamic wifi power based on RSSI by @TD-er (#15443) + +### Breaking Changed + +### Changed + +### Fixed + +### Removed + +## [12.5.0.2] 20230516 ### Added - Matter support for Shutters with Tilt - Matter POC for remote Relay @@ -31,8 +43,6 @@ All notable changes to this project will be documented in this file. - Berry fixed a rare condition when a GC causes a memory corruption - LED PWM ac_dimmer curve was wrongly applied instead of Gamma regression from v12.2.0.5 (#18666) -### Removed - ## [12.5.0.1] 20230505 ### Added - Matter sensors Humidity, Pressure, Illuminance; optimize memory (#18441) diff --git a/RELEASENOTES.md b/RELEASENOTES.md index c40f34581..38bcae2e0 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -110,11 +110,11 @@ The latter links can be used for OTA upgrades too like ``OtaUrl https://ota.tasm [Complete list](BUILDS.md) of available feature and sensors. -## Changelog v12.5.0.2 +## Changelog v12.5.0.3 ### Added -- Command ``SetOption152 0/1`` to select two (0 = default) pin bistable or one (1) pin -latching relay control [#18386](https://github.com/arendst/Tasmota/issues/18386) +- Command ``SetOption152 0/1`` to select two (0 = default) pin bistable or one (1) pin latching relay control [#18386](https://github.com/arendst/Tasmota/issues/18386) - Command ``I2cScan0`` to scan both busses on ESP32 with one command +- Command ``WifiPower 0`` to enable dynamic wifi power based on RSSI by @TD-er [#15443](https://github.com/arendst/Tasmota/issues/15443) - Support for TC74 temperature sensor by Michael Loftis [#18042](https://github.com/arendst/Tasmota/issues/18042) - Support for GM861 1D and 2D bar code reader [#18399](https://github.com/arendst/Tasmota/issues/18399) - Support for PCA9557 8-bit I/O expander [#18632](https://github.com/arendst/Tasmota/issues/18632) diff --git a/tasmota/include/tasmota_version.h b/tasmota/include/tasmota_version.h index a98d9e299..fc65acab4 100644 --- a/tasmota/include/tasmota_version.h +++ b/tasmota/include/tasmota_version.h @@ -20,6 +20,6 @@ #ifndef _TASMOTA_VERSION_H_ #define _TASMOTA_VERSION_H_ -const uint32_t VERSION = 0x0C050002; // 12.5.0.2 +const uint32_t VERSION = 0x0C050003; // 12.5.0.3 #endif // _TASMOTA_VERSION_H_ diff --git a/tasmota/tasmota.ino b/tasmota/tasmota.ino index 8e98f8002..96ead1bdb 100644 --- a/tasmota/tasmota.ino +++ b/tasmota/tasmota.ino @@ -105,6 +105,7 @@ const uint32_t VERSION_MARKER[] PROGMEM = { 0x5AA55AA5, 0xFFFFFFFF, 0xA55AA55A }; struct WIFI { + int last_tx_pwr; uint32_t last_event = 0; // Last wifi connection event uint32_t downtime = 0; // Wifi down duration uint16_t link_count = 0; // Number of wifi re-connect diff --git a/tasmota/tasmota_support/support_command.ino b/tasmota/tasmota_support/support_command.ino index 3f31dddc8..13269587f 100644 --- a/tasmota/tasmota_support/support_command.ino +++ b/tasmota/tasmota_support/support_command.ino @@ -2523,8 +2523,7 @@ void CmndLedPwmMode(void) { } } -void CmndWifiPower(void) -{ +void CmndWifiPower(void) { if (XdrvMailbox.data_len > 0) { Settings->wifi_output_power = (uint8_t)(CharToFloat(XdrvMailbox.data) * 10); if (Settings->wifi_output_power > 205) { @@ -2532,7 +2531,11 @@ void CmndWifiPower(void) } WifiSetOutputPower(); } - ResponseCmndChar(WifiGetOutputPower().c_str()); + if (Settings->wifi_output_power) { + ResponseCmndChar(WifiGetOutputPower().c_str()); + } else { + ResponseCmndNumber(Wifi.last_tx_pwr / 10); + } } void CmndWifi(void) diff --git a/tasmota/tasmota_support/support_tasmota.ino b/tasmota/tasmota_support/support_tasmota.ino index 2abe41635..8fe5eb3b0 100644 --- a/tasmota/tasmota_support/support_tasmota.ino +++ b/tasmota/tasmota_support/support_tasmota.ino @@ -1241,6 +1241,10 @@ void Every100mSeconds(void) } } } + + if (0 == Settings->wifi_output_power) { + WiFiSetTXpowerBasedOnRssi(); + } } /*-------------------------------------------------------------------------------------------*\ diff --git a/tasmota/tasmota_support/support_wifi.ino b/tasmota/tasmota_support/support_wifi.ino index 084d55bb5..72cd5fbc5 100644 --- a/tasmota/tasmota_support/support_wifi.ino +++ b/tasmota/tasmota_support/support_wifi.ino @@ -966,9 +966,114 @@ String WifiGetOutputPower(void) return String(stemp1); } -void WifiSetOutputPower(void) -{ - WiFi.setOutputPower((float)(Settings->wifi_output_power) / 10); +void WifiSetOutputPower(void) { + if (Settings->wifi_output_power) { + WiFi.setOutputPower((float)(Settings->wifi_output_power) / 10); + } +} + +/* + Dynamic WiFi transmit power based on RSSI lowering overall DC power usage + + Original idea by ESPEasy (@TD-er) +*/ +#ifdef ESP32 + #if defined(CONFIG_IDF_TARGET_ESP32S2) + #define MAX_TX_PWR_DBM_11b 195 + #define MAX_TX_PWR_DBM_54g 150 + #define MAX_TX_PWR_DBM_n 130 + #define WIFI_SENSITIVITY_11b -880 + #define WIFI_SENSITIVITY_54g -750 + #define WIFI_SENSITIVITY_n -720 + #elif defined(CONFIG_IDF_TARGET_ESP32S3) + #define MAX_TX_PWR_DBM_11b 210 + #define MAX_TX_PWR_DBM_54g 190 + #define MAX_TX_PWR_DBM_n 185 + #define WIFI_SENSITIVITY_11b -880 + #define WIFI_SENSITIVITY_54g -760 + #define WIFI_SENSITIVITY_n -720 + #elif defined(CONFIG_IDF_TARGET_ESP32C3) + #define MAX_TX_PWR_DBM_11b 210 + #define MAX_TX_PWR_DBM_54g 190 + #define MAX_TX_PWR_DBM_n 185 + #define WIFI_SENSITIVITY_11b -880 + #define WIFI_SENSITIVITY_54g -760 + #define WIFI_SENSITIVITY_n -730 + #else + #define MAX_TX_PWR_DBM_11b 195 + #define MAX_TX_PWR_DBM_54g 160 + #define MAX_TX_PWR_DBM_n 140 + #define WIFI_SENSITIVITY_11b -880 + #define WIFI_SENSITIVITY_54g -750 + #define WIFI_SENSITIVITY_n -700 + #endif +#endif +#ifdef ESP8266 + #define MAX_TX_PWR_DBM_11b 200 + #define MAX_TX_PWR_DBM_54g 170 + #define MAX_TX_PWR_DBM_n 140 + #define WIFI_SENSITIVITY_11b -910 + #define WIFI_SENSITIVITY_54g -750 + #define WIFI_SENSITIVITY_n -720 +#endif + +void WiFiSetTXpowerBasedOnRssi(void) { + const WiFiMode_t cur_mode = WiFi.getMode(); + if (cur_mode == WIFI_OFF) { return; } + + // Range ESP32 : 2dBm - 20dBm + // Range ESP8266: 0dBm - 20.5dBm +// int maxTXpwr = Settings->wifi_output_power; + int maxTXpwr = 210; + int threshold = WIFI_SENSITIVITY_n; + int phy_mode = WiFi.getPhyMode(); + switch (phy_mode) { + case 1: // 11b (WIFI_PHY_MODE_11B) + threshold = WIFI_SENSITIVITY_11b; + if (maxTXpwr > MAX_TX_PWR_DBM_11b) maxTXpwr = MAX_TX_PWR_DBM_11b; + break; + case 2: // 11bg (WIFI_PHY_MODE_11G) + threshold = WIFI_SENSITIVITY_54g; + if (maxTXpwr > MAX_TX_PWR_DBM_54g) maxTXpwr = MAX_TX_PWR_DBM_54g; + break; + case 3: // 11bgn (WIFI_PHY_MODE_11N) + threshold = WIFI_SENSITIVITY_n; + if (maxTXpwr > MAX_TX_PWR_DBM_n) maxTXpwr = MAX_TX_PWR_DBM_n; + break; + } + threshold += 30; // Margin in dBm * 10 on top of threshold + int minTXpwr = 0; + + // Assume AP sends with max set by ETSI standard. + // 2.4 GHz: 100 mWatt (20 dBm) + // US and some other countries allow 1000 mW (30 dBm) + int rssi = WiFi.RSSI() * 10; + int newrssi = rssi - 200; // We cannot send with over 20 dBm, thus it makes no sense to force higher TX power all the time. + + if (newrssi < threshold) { + minTXpwr = threshold - newrssi; + } + if (minTXpwr > maxTXpwr) { + minTXpwr = maxTXpwr; + } + int dBm = 0; + if (dBm > maxTXpwr) { + dBm = maxTXpwr; + } else if (dBm < minTXpwr) { + dBm = minTXpwr; + } + WiFi.setOutputPower((float)dBm / 10); + + delay(Wifi.last_tx_pwr < dBm); // If increase the TX power, give power supply of the unit some rest + Wifi.last_tx_pwr = dBm; + +/* + int TX_pwr_int = Wifi.last_tx_pwr * 4; + int maxTXpwr_int = maxTXpwr * 4; + if (TX_pwr_int != maxTXpwr_int) { + AddLog(LOG_LEVEL_DEBUG, PSTR("WIF: TX power %d, Sensitivity %d, RSSI %d"), dBm / 10, threshold/ 10, rssi / 10); + } +*/ } /*