From daebb379620f78a3d8121048f556991ae80753eb Mon Sep 17 00:00:00 2001 From: Adrian Scillato <35405447+ascillato@users.noreply.github.com> Date: Fri, 4 Jun 2021 09:44:23 -0300 Subject: [PATCH 1/6] WiFi Command: Move wifi modes char to be global --- tasmota/tasmota.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tasmota/tasmota.h b/tasmota/tasmota.h index 46d554ad7..d087bd5fb 100644 --- a/tasmota/tasmota.h +++ b/tasmota/tasmota.h @@ -105,6 +105,9 @@ const uint8_t MAX_FRIENDLYNAMES = 8; // Max number of Friendly names const uint8_t MAX_BUTTON_TEXT = 16; // Max number of GUI button labels const uint8_t MAX_GROUP_TOPICS = 4; // Max number of Group Topics const uint8_t MAX_DEV_GROUP_NAMES = 4; // Max number of Device Group names + +const static char kWifiPhyMode[] PROGMEM = " bgnl"; // Wi-Fi Modes + #ifdef ESP8266 const uint8_t MAX_ADCS = 1; // Max number of ESP8266 ADC pins const uint8_t MAX_SWITCHES_TXT = 8; // Max number of switches user text From 946f6b3fe347d3fad825d097d27c8e429dd32035 Mon Sep 17 00:00:00 2001 From: Adrian Scillato <35405447+ascillato@users.noreply.github.com> Date: Fri, 4 Jun 2021 09:46:41 -0300 Subject: [PATCH 2/6] WiFi Command: Move wifi modes char to be global --- tasmota/support_wifi.ino | 2 -- 1 file changed, 2 deletions(-) diff --git a/tasmota/support_wifi.ino b/tasmota/support_wifi.ino index 3f4b96ef8..577377386 100644 --- a/tasmota/support_wifi.ino +++ b/tasmota/support_wifi.ino @@ -175,8 +175,6 @@ void WiFiSetSleepMode(void) void WifiBegin(uint8_t flag, uint8_t channel) { - const static char kWifiPhyMode[] PROGMEM = " bgnl"; - #ifdef USE_EMULATION UdpDisconnect(); #endif // USE_EMULATION From 13756def16b2270f1321f0672b2fc8da751b0322 Mon Sep 17 00:00:00 2001 From: Adrian Scillato <35405447+ascillato@users.noreply.github.com> Date: Fri, 4 Jun 2021 09:51:05 -0300 Subject: [PATCH 3/6] Add actual Wi-Fi mode (b/g/n) to STATUS 11 --- tasmota/support_tasmota.ino | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tasmota/support_tasmota.ino b/tasmota/support_tasmota.ino index d04073805..d439fe0a2 100644 --- a/tasmota/support_tasmota.ino +++ b/tasmota/support_tasmota.ino @@ -767,9 +767,10 @@ void MqttShowState(void) if (!TasmotaGlobal.global_state.wifi_down) { int32_t rssi = WiFi.RSSI(); - ResponseAppend_P(PSTR(",\"" D_JSON_WIFI "\":{\"" D_JSON_AP "\":%d,\"" D_JSON_SSID "\":\"%s\",\"" D_JSON_BSSID "\":\"%s\",\"" D_JSON_CHANNEL "\":%d,\"" D_JSON_RSSI "\":%d,\"" D_JSON_SIGNAL "\":%d,\"" D_JSON_LINK_COUNT "\":%d,\"" D_JSON_DOWNTIME "\":\"%s\"}"), + ResponseAppend_P(PSTR(",\"" D_JSON_WIFI "\":{\"" D_JSON_AP "\":%d,\"" D_JSON_SSID "\":\"%s\",\"" D_JSON_BSSID "\":\"%s\",\"" D_JSON_CHANNEL "\":%d,\"" D_JSON_WIFI_MODE "\":\"11%c\",\"" D_JSON_RSSI "\":%d,\"" D_JSON_SIGNAL "\":%d,\"" D_JSON_LINK_COUNT "\":%d,\"" D_JSON_DOWNTIME "\":\"%s\"}"), Settings.sta_active +1, EscapeJSONString(SettingsText(SET_STASSID1 + Settings.sta_active)).c_str(), WiFi.BSSIDstr().c_str(), WiFi.channel(), - WifiGetRssiAsQuality(rssi), rssi, WifiLinkCount(), WifiDowntime().c_str()); + pgm_read_byte(&kWifiPhyMode[WiFi.getPhyMode() & 0x3]), WifiGetRssiAsQuality(rssi), rssi, + WifiLinkCount(), WifiDowntime().c_str()); } ResponseJsonEnd(); From f0d9605b4b4a0ee5f21ed670d94c3c495a949252 Mon Sep 17 00:00:00 2001 From: Adrian Scillato <35405447+ascillato@users.noreply.github.com> Date: Fri, 4 Jun 2021 09:52:25 -0300 Subject: [PATCH 4/6] Add actual Wi-Fi mode (b/g/n) to STATUS 11 --- tasmota/i18n.h | 1 + 1 file changed, 1 insertion(+) diff --git a/tasmota/i18n.h b/tasmota/i18n.h index 09e4b84fa..f22aa1c4d 100644 --- a/tasmota/i18n.h +++ b/tasmota/i18n.h @@ -200,6 +200,7 @@ #define D_JSON_VOLUME "Volume" #define D_JSON_WEIGHT "Weight" #define D_JSON_WIFI "Wifi" +#define D_JSON_WIFI_MODE "Mode" #define D_JSON_WRONG "Wrong" #define D_JSON_WRONG_PARAMETERS "Wrong parameters" #define D_JSON_YESTERDAY "Yesterday" From ae133f193315c7e83a9d244c7b091ac83f2f902e Mon Sep 17 00:00:00 2001 From: Adrian Scillato <35405447+ascillato@users.noreply.github.com> Date: Fri, 4 Jun 2021 09:54:26 -0300 Subject: [PATCH 5/6] Add actual Wi-Fi mode (b/g/n) to INFORMATION MENU And some code cleaning --- tasmota/xdrv_01_webserver.ino | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/tasmota/xdrv_01_webserver.ino b/tasmota/xdrv_01_webserver.ino index b16d1b75e..a84eb5b16 100644 --- a/tasmota/xdrv_01_webserver.ino +++ b/tasmota/xdrv_01_webserver.ino @@ -1782,13 +1782,8 @@ void HandleWifiConfiguration(void) { TasmotaGlobal.save_data_counter = 0; // Stop auto saving data - Updating Settings Settings.save_data = 0; - if (MAX_WIFI_OPTION == Web.old_wificonfig) { - Web.old_wificonfig = Settings.sta_config; - //AddLog(LOG_LEVEL_INFO,PSTR("WFM: save wificonfig %d and set to 2 (settings=%d)"), Web.old_wificonfig, Settings.sta_config); - } else { - //AddLog(LOG_LEVEL_INFO,PSTR("WFM: wificonfig already saved %d, set to 2 (settings=%d)"), Web.old_wificonfig, Settings.sta_config); - } - TasmotaGlobal.wifi_state_flag = Settings.sta_config = WIFI_MANAGER;; + if (MAX_WIFI_OPTION == Web.old_wificonfig) { Web.old_wificonfig = Settings.sta_config; } + TasmotaGlobal.wifi_state_flag = Settings.sta_config = WIFI_MANAGER; TasmotaGlobal.sleep = 0; // Disable sleep TasmotaGlobal.restart_flag = 0; // No restart @@ -2271,7 +2266,7 @@ void HandleInformation(void) #endif if (Settings.flag4.network_wifi) { int32_t rssi = WiFi.RSSI(); - WSContentSend_P(PSTR("}1" D_AP "%d " D_SSID " (" D_RSSI ")}2%s (%d%%, %d dBm)"), Settings.sta_active +1, HtmlEscape(SettingsText(SET_STASSID1 + Settings.sta_active)).c_str(), WifiGetRssiAsQuality(rssi), rssi); + WSContentSend_P(PSTR("}1" D_AP "%d " D_SSID " (" D_RSSI ")}2%s (%d%%, %d dBm) 11%c"), Settings.sta_active +1, HtmlEscape(SettingsText(SET_STASSID1 + Settings.sta_active)).c_str(), WifiGetRssiAsQuality(rssi), rssi, pgm_read_byte(&kWifiPhyMode[WiFi.getPhyMode() & 0x3]) ); WSContentSend_P(PSTR("}1" D_HOSTNAME "}2%s%s"), TasmotaGlobal.hostname, (Mdns.begun) ? PSTR(".local") : ""); #if LWIP_IPV6 String ipv6_addr = WifiGetIPv6(); @@ -3268,9 +3263,6 @@ bool Xdrv01(uint8_t function) // TasmotaGlobal.blinks = 255; // Signal wifi connection with blinks if (MAX_WIFI_OPTION != Web.old_wificonfig) { TasmotaGlobal.wifi_state_flag = Settings.sta_config = Web.old_wificonfig; - //AddLog(LOG_LEVEL_INFO,PSTR("WFM: Restore wificonfig %d"), Web.old_wificonfig); - } else { - //AddLog(LOG_LEVEL_INFO,PSTR("WFM: Keep wificonfig %d"), Settings.sta_config); } TasmotaGlobal.save_data_counter = Web.save_data_counter; Settings.save_data = Web.save_data_counter; From 52060548862b95f5a919e9119077f82ac7d7ded1 Mon Sep 17 00:00:00 2001 From: Adrian Scillato <35405447+ascillato@users.noreply.github.com> Date: Fri, 4 Jun 2021 09:57:25 -0300 Subject: [PATCH 6/6] Add new options to WIFI command Actual Options: 0 - Turn Off Wi-Fi 1 - Turn On Wi-Fi New Options Added: 2 - Force the device to ONLY connects as a 11b device 3 - Force the device to ONLY connects as a 11b/g device 4 - Force the device to connects as a 11b/g/n device --- tasmota/support_command.ino | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tasmota/support_command.ino b/tasmota/support_command.ino index 7a7a00340..e8bca9f73 100644 --- a/tasmota/support_command.ino +++ b/tasmota/support_command.ino @@ -2142,8 +2142,12 @@ void CmndWifi(void) if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= 1)) { Settings.flag4.network_wifi = XdrvMailbox.payload; if (Settings.flag4.network_wifi) { WifiEnable(); } +#ifdef ESP8266 + } else if ((XdrvMailbox.payload >= 2) && (XdrvMailbox.payload <= 4)) { + WiFi.setPhyMode(WiFiPhyMode_t(XdrvMailbox.payload - 1)); // 1-B/2-BG/3-BGN +#endif } - ResponseCmndStateText(Settings.flag4.network_wifi); + Response_P(PSTR("{\"" D_JSON_WIFI "\":\"%s\",\"" D_JSON_WIFI_MODE "\":\"11%c\"}"), GetStateText(Settings.flag4.network_wifi), pgm_read_byte(&kWifiPhyMode[WiFi.getPhyMode() & 0x3]) ); } #ifdef USE_I2C