diff --git a/tasmota/_changelog.ino b/tasmota/_changelog.ino index 80f514ab8..4cc3a85ef 100644 --- a/tasmota/_changelog.ino +++ b/tasmota/_changelog.ino @@ -1,4 +1,7 @@ /*********************************************************************************************\ + * 7.0.0.4 20191108 + * Add command WifiPower 0 .. 20.5 to set Wifi Output Power which will be default set to 17dB + * * 7.0.0.3 20191103 * Initial support for I2C driver runtime control using command I2CDriver and document I2CDEVICES.md * Fix random crash caused by UPNP flood diff --git a/tasmota/i18n.h b/tasmota/i18n.h index 424b0ef3a..1002983c2 100644 --- a/tasmota/i18n.h +++ b/tasmota/i18n.h @@ -279,6 +279,7 @@ #define D_CMND_LEDPOWER "LedPower" #define D_CMND_LEDSTATE "LedState" #define D_CMND_LEDMASK "LedMask" +#define D_CMND_WIFIPOWER "WifiPower" #define D_CMND_I2CSCAN "I2CScan" #define D_CMND_I2CDRIVER "I2CDriver" #define D_CMND_SERIALSEND "SerialSend" diff --git a/tasmota/settings.h b/tasmota/settings.h index 696a5ca1d..d7a06c778 100644 --- a/tasmota/settings.h +++ b/tasmota/settings.h @@ -270,8 +270,9 @@ struct SYSCFG { SysBitfield4 flag4; // 1E0 - uint8_t free_1e4[2]; // 1E4 + uint8_t free_1e4; // 1E4 + uint8_t wifi_output_power; // 1E5 uint8_t shutter_accuracy; // 1E6 uint8_t mqttlog_level; // 1E7 uint8_t sps30_inuse_hours; // 1E8 diff --git a/tasmota/settings.ino b/tasmota/settings.ino index 036c19f15..a3a565872 100644 --- a/tasmota/settings.ino +++ b/tasmota/settings.ino @@ -656,6 +656,7 @@ void SettingsDefaultSet2(void) Settings.seriallog_level = SERIAL_LOG_LEVEL; // Wifi + Settings.wifi_output_power = 170; ParseIp(&Settings.ip_address[0], WIFI_IP_ADDRESS); ParseIp(&Settings.ip_address[1], WIFI_GATEWAY); ParseIp(&Settings.ip_address[2], WIFI_SUBNETMASK); @@ -1131,6 +1132,9 @@ void SettingsDelta(void) if (Settings.version < 0x07000003) { SettingsEnableAllI2cDrivers(); } + if (Settings.version < 0x07000004) { + Settings.wifi_output_power = 170; + } Settings.version = VERSION; SettingsSave(1); } diff --git a/tasmota/support_command.ino b/tasmota/support_command.ino index 14fb7a575..877ff7547 100644 --- a/tasmota/support_command.ino +++ b/tasmota/support_command.ino @@ -26,7 +26,7 @@ const char kTasmotaCommands[] PROGMEM = "|" // No prefix D_CMND_BUTTONDEBOUNCE "|" D_CMND_SWITCHDEBOUNCE "|" D_CMND_SYSLOG "|" D_CMND_LOGHOST "|" D_CMND_LOGPORT "|" D_CMND_SERIALSEND "|" D_CMND_BAUDRATE "|" D_CMND_SERIALDELIMITER "|" D_CMND_IPADDRESS "|" D_CMND_NTPSERVER "|" D_CMND_AP "|" D_CMND_SSID "|" D_CMND_PASSWORD "|" D_CMND_HOSTNAME "|" D_CMND_WIFICONFIG "|" D_CMND_FRIENDLYNAME "|" D_CMND_SWITCHMODE "|" D_CMND_INTERLOCK "|" D_CMND_TELEPERIOD "|" D_CMND_RESET "|" D_CMND_TIME "|" D_CMND_TIMEZONE "|" D_CMND_TIMESTD "|" - D_CMND_TIMEDST "|" D_CMND_ALTITUDE "|" D_CMND_LEDPOWER "|" D_CMND_LEDSTATE "|" D_CMND_LEDMASK "|" + D_CMND_TIMEDST "|" D_CMND_ALTITUDE "|" D_CMND_LEDPOWER "|" D_CMND_LEDSTATE "|" D_CMND_LEDMASK "|" D_CMND_WIFIPOWER "|" #ifdef USE_I2C D_CMND_I2CSCAN "|" D_CMND_I2CDRIVER "|" #endif @@ -41,7 +41,7 @@ void (* const TasmotaCommand[])(void) PROGMEM = { &CmndButtonDebounce, &CmndSwitchDebounce, &CmndSyslog, &CmndLoghost, &CmndLogport, &CmndSerialSend, &CmndBaudrate, &CmndSerialDelimiter, &CmndIpAddress, &CmndNtpServer, &CmndAp, &CmndSsid, &CmndPassword, &CmndHostname, &CmndWifiConfig, &CmndFriendlyname, &CmndSwitchMode, &CmndInterlock, &CmndTeleperiod, &CmndReset, &CmndTime, &CmndTimezone, &CmndTimeStd, - &CmndTimeDst, &CmndAltitude, &CmndLedPower, &CmndLedState, &CmndLedMask, + &CmndTimeDst, &CmndAltitude, &CmndLedPower, &CmndLedState, &CmndLedMask, &CmndWifiPower, #ifdef USE_I2C &CmndI2cScan, CmndI2cDriver, #endif @@ -1530,6 +1530,20 @@ void CmndLedMask(void) ResponseCmndChar(stemp1); } +void CmndWifiPower(void) +{ + if (XdrvMailbox.data_len > 0) { + Settings.wifi_output_power = (uint8_t)(CharToFloat(XdrvMailbox.data) * 10); + if (Settings.wifi_output_power > 205) { + Settings.wifi_output_power = 205; + } + WifiSetOutputPower(); + } + char stemp1[TOPSZ]; + dtostrfd((float)(Settings.wifi_output_power) / 10, 1, stemp1); + Response_P(S_JSON_COMMAND_XVALUE, XdrvMailbox.command, stemp1); // Return float value without quotes +} + #ifdef USE_I2C void CmndI2cScan(void) { diff --git a/tasmota/support_wifi.ino b/tasmota/support_wifi.ino index 1201511a2..70eea5c1a 100644 --- a/tasmota/support_wifi.ino +++ b/tasmota/support_wifi.ino @@ -108,6 +108,25 @@ void WifiConfig(uint8_t type) } } +void WifiSetMode(WiFiMode_t wifi_mode) +{ + if (WiFi.getMode() == wifi_mode) { return; } + + if (wifi_mode != WIFI_OFF) { + // See: https://github.com/esp8266/Arduino/issues/6172#issuecomment-500457407 + WiFi.forceSleepWake(); // Make sure WiFi is really active. + delay(100); + } + + if (wifi_mode == WIFI_OFF) { + delay(1000); + WiFi.forceSleepBegin(); + delay(1); + } else { + delay(30); // Must allow for some time to init. + } +} + void WiFiSetSleepMode(void) { /* Excerpt from the esp8266 non os sdk api reference (v2.2.1): @@ -143,13 +162,15 @@ void WifiBegin(uint8_t flag, uint8_t channel) #ifdef ARDUINO_ESP8266_RELEASE_2_3_0 // (!strncmp_P(ESP.getSdkVersion(),PSTR("1.5.3"),5)) AddLog_P(LOG_LEVEL_DEBUG, S_LOG_WIFI, PSTR(D_PATCH_ISSUE_2186)); - WiFi.mode(WIFI_OFF); // See https://github.com/esp8266/Arduino/issues/2186 +// WiFi.mode(WIFI_OFF); // See https://github.com/esp8266/Arduino/issues/2186 + WifiSetMode(WIFI_OFF); #endif WiFi.persistent(false); // Solve possible wifi init errors (re-add at 6.2.1.16 #4044, #4083) WiFi.disconnect(true); // Delete SDK wifi config delay(200); - WiFi.mode(WIFI_STA); // Disable AP mode +// WiFi.mode(WIFI_STA); // Disable AP mode + WifiSetMode(WIFI_STA); WiFiSetSleepMode(); // 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 @@ -549,9 +570,15 @@ int WifiState(void) return state; } +void WifiSetOutputPower(void) +{ + WiFi.setOutputPower((float)(Settings.wifi_output_power) / 10); +} + void WifiConnect(void) { WifiSetState(0); + WifiSetOutputPower(); WiFi.persistent(false); // Solve possible wifi init errors Wifi.status = 0; Wifi.retry_init = WIFI_RETRY_OFFSET_SEC + ((ESP.getChipId() & 0xF) * 2); @@ -581,3 +608,6 @@ void EspRestart(void) // ESP.restart(); // This results in exception 3 on restarts on core 2.3.0 ESP.reset(); } + + + diff --git a/tasmota/tasmota_version.h b/tasmota/tasmota_version.h index 7553f6686..9cd601086 100644 --- a/tasmota/tasmota_version.h +++ b/tasmota/tasmota_version.h @@ -20,6 +20,6 @@ #ifndef _TASMOTA_VERSION_H_ #define _TASMOTA_VERSION_H_ -const uint32_t VERSION = 0x07000003; +const uint32_t VERSION = 0x07000004; #endif // _TASMOTA_VERSION_H_ diff --git a/tasmota/xdrv_01_webserver.ino b/tasmota/xdrv_01_webserver.ino index b6cef85e9..64194c9c9 100644 --- a/tasmota/xdrv_01_webserver.ino +++ b/tasmota/xdrv_01_webserver.ino @@ -614,10 +614,12 @@ void WifiManagerBegin(bool reset_only) { // setup AP if (!global_state.wifi_down) { - WiFi.mode(WIFI_AP_STA); +// WiFi.mode(WIFI_AP_STA); + WifiSetMode(WIFI_AP_STA); AddLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_WIFI D_WIFIMANAGER_SET_ACCESSPOINT_AND_STATION)); } else { - WiFi.mode(WIFI_AP); +// WiFi.mode(WIFI_AP); + WifiSetMode(WIFI_AP); AddLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_WIFI D_WIFIMANAGER_SET_ACCESSPOINT)); }