Berry `tasmota.wifi()` would wrongly report wifi as up (#18687)

* Berry `tasmota.wifi()` would wrongly report wifi as up

* Fix ESP8266 compile

* Fix display of IP in wifiman

* Improve wifiman IP handling for IPv6
This commit is contained in:
s-hadinger 2023-05-18 11:23:09 +02:00 committed by GitHub
parent 2d8ea8f51c
commit 043ea2986b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 5 deletions

View File

@ -16,6 +16,7 @@ All notable changes to this project will be documented in this file.
### Fixed
- Shutter bootloop using more than 4 shutters (#18673)
- AIThinker webcam issues (#18652)
- Berry `tasmota.wifi()` would wrongly report wifi as up
### Removed

View File

@ -503,6 +503,7 @@ void WifiSetState(uint8_t state)
* - DNS reporting actual values used (not the Settings):
* `DNSGetIP(n)`, `DNSGetIPStr(n)` with n=`0`/`1` (same dns for Wifi and Eth)
\*****************************************************************************************************/
bool WifiGetIP(IPAddress *ip, bool exclude_ap = false);
// IPv4 for Wifi
// Returns only IPv6 global address (no loopback and no link-local)
bool WifiGetIPv4(IPAddress *ip)
@ -755,15 +756,29 @@ String IPForUrl(const IPAddress & ip)
// Check to see if we have any routable IP address
// IPv4 has always priority
// Copy the value of the IP if pointer provided (optional)
bool WifiGetIP(IPAddress *ip) {
if ((uint32_t)WiFi.localIP() != 0) {
// `exclude_ap` allows to exlude AP IP address and focus only on local STA
bool WifiGetIP(IPAddress *ip, bool exclude_ap) {
#ifdef ESP32
wifi_mode_t mode = WiFi.getMode();
if ((mode == WIFI_MODE_STA || mode == WIFI_MODE_APSTA) && (uint32_t)WiFi.localIP() != 0) {
if (ip != nullptr) { *ip = WiFi.localIP(); }
return true;
}
if ((uint32_t)WiFi.softAPIP() != 0) {
if (!exclude_ap && (mode == WIFI_MODE_AP || mode == WIFI_MODE_APSTA) && (uint32_t)WiFi.softAPIP() != 0) {
if (ip != nullptr) { *ip = WiFi.softAPIP(); }
return true;
}
#else
WiFiMode_t mode = WiFi.getMode();
if ((mode == WIFI_STA || mode == WIFI_AP_STA) && (uint32_t)WiFi.localIP() != 0) {
if (ip != nullptr) { *ip = WiFi.localIP(); }
return true;
}
if (!exclude_ap && (mode == WIFI_AP || mode == WIFI_AP_STA) && (uint32_t)WiFi.softAPIP() != 0) {
if (ip != nullptr) { *ip = WiFi.softAPIP(); }
return true;
}
#endif
#ifdef USE_IPV6
IPAddress lip;
if (WifiGetIPv6(&lip)) {

View File

@ -3701,11 +3701,12 @@ bool Xdrv01(uint32_t function)
if (Wifi.wifi_test_counter) {
Wifi.wifi_test_counter--;
AddLog(LOG_LEVEL_DEBUG, PSTR(D_LOG_WIFI D_TRYING_TO_CONNECT " %s"), SettingsText(SET_STASSID1));
if (WifiHasIP()) { // Got IP - Connection Established
IPAddress local_ip;
if (WifiGetIP(&local_ip, true)) { // Got IP - Connection Established (exclude AP address)
Wifi.wifi_test_AP_TIMEOUT = false;
Wifi.wifi_test_counter = 0;
Wifi.wifiTest = WIFI_TEST_FINISHED;
AddLog(LOG_LEVEL_INFO, PSTR(D_LOG_WIFI D_CMND_SSID " %s: " D_CONNECTED " - " D_IP_ADDRESS " %s"), SettingsText(Wifi.wifi_Test_Save_SSID2 ? SET_STASSID2 : SET_STASSID1), WiFi.localIP().toString().c_str());
AddLog(LOG_LEVEL_INFO, PSTR(D_LOG_WIFI D_CMND_SSID " %s: " D_CONNECTED " - " D_IP_ADDRESS " %s"), SettingsText(Wifi.wifi_Test_Save_SSID2 ? SET_STASSID2 : SET_STASSID1), local_ip.toString().c_str());
// TasmotaGlobal.blinks = 255; // Signal wifi connection with blinks
if (MAX_WIFI_OPTION != Wifi.old_wificonfig) {
TasmotaGlobal.wifi_state_flag = Settings->sta_config = Wifi.old_wificonfig;