refactoring: arp gratuitous for esp8266

This commit is contained in:
Yurii
2023-12-20 08:12:39 +03:00
parent 4e980b6e5b
commit f4fe8c7366

View File

@@ -4,7 +4,11 @@
#include <UnsignedShortParameter.h> #include <UnsignedShortParameter.h>
#include <CheckboxParameter.h> #include <CheckboxParameter.h>
#include <HeaderParameter.h> #include <HeaderParameter.h>
#include <netif/etharp.h> #ifdef ARDUINO_ARCH_ESP8266
extern "C" {
#include "lwip/etharp.h"
}
#endif
WiFiManager wm; WiFiManager wm;
WiFiManagerParameter* wmHostname; WiFiManagerParameter* wmHostname;
@@ -210,7 +214,6 @@ protected:
task->disable(); task->disable();
} }
} }
//this->delay(10);
}); });
wm.setConfigPortalTimeout(wm.getWiFiIsSaved() ? 180 : 0); wm.setConfigPortalTimeout(wm.getWiFiIsSaved() ? 180 : 0);
wm.setDisableConfigPortal(false); wm.setDisableConfigPortal(false);
@@ -224,6 +227,10 @@ protected:
if (wm.getWebPortalActive()) { if (wm.getWebPortalActive()) {
wm.stopWebPortal(); wm.stopWebPortal();
#ifdef ARDUINO_ARCH_ESP8266
::yield();
#endif
} }
/*wm.setCaptivePortalEnable(true); /*wm.setCaptivePortalEnable(true);
@@ -234,6 +241,9 @@ protected:
#if USE_TELNET #if USE_TELNET
TelnetStream.stop(); TelnetStream.stop();
#ifdef ARDUINO_ARCH_ESP8266
::yield();
#endif
#endif #endif
Log.sinfoln(FPSTR(S_WIFI), F("Disconnected")); Log.sinfoln(FPSTR(S_WIFI), F("Disconnected"));
@@ -254,27 +264,36 @@ protected:
wm.setConfigPortalTimeout(180); wm.setConfigPortalTimeout(180);
if (wm.getConfigPortalActive()) { if (wm.getConfigPortalActive()) {
wm.stopConfigPortal(); wm.stopConfigPortal();
#ifdef ARDUINO_ARCH_ESP8266
::yield();
#endif
} }
wm.setCaptivePortalEnable(false); wm.setCaptivePortalEnable(false);
if (!wm.getWebPortalActive()) { if (!wm.getWebPortalActive()) {
wm.startWebPortal(); wm.startWebPortal();
#ifdef ARDUINO_ARCH_ESP8266
::yield();
#endif
} }
#if USE_TELNET #if USE_TELNET
TelnetStream.begin(23, false); TelnetStream.begin(23, false);
#ifdef ARDUINO_ARCH_ESP8266
::yield();
#endif
#endif #endif
Log.sinfoln(FPSTR(S_WIFI), F("Connected. IP: %s, RSSI: %hhd"), WiFi.localIP().toString().c_str(), WiFi.RSSI()); Log.sinfoln(FPSTR(S_WIFI), F("Connected. IP: %s, RSSI: %hhd"), WiFi.localIP().toString().c_str(), WiFi.RSSI());
} }
#if defined(ARDUINO_ARCH_ESP8266) #ifdef ARDUINO_ARCH_ESP8266
if (connected && millis() - lastArpGratuitous > 60000) { if (connected && millis() - lastArpGratuitous > 60000) {
arpGratuitous(); stationKeepAliveNow();
lastArpGratuitous = millis(); lastArpGratuitous = millis();
}
::yield(); ::yield();
}
#endif #endif
wm.process(); wm.process();
@@ -518,11 +537,23 @@ protected:
eeSettings.update(); eeSettings.update();
} }
static void arpGratuitous() { #ifdef ARDUINO_ARCH_ESP8266
struct netif* netif = netif_list; /**
while (netif) { * @brief
etharp_gratuitous(netif); * https://github.com/arendst/Tasmota/blob/e6515883f0ee5451931b6280ff847b117de5a231/tasmota/tasmota_support/support_wifi.ino#L1196
netif = netif->next; */
static void stationKeepAliveNow(void) {
for (netif* interface = netif_list; interface != nullptr; interface = interface->next) {
if (
(interface->flags & NETIF_FLAG_LINK_UP)
&& (interface->flags & NETIF_FLAG_UP)
&& interface->num == STATION_IF
&& (!ip4_addr_isany_val(*netif_ip4_addr(interface)))
) {
etharp_gratuitous(interface);
break;
} }
} }
}
#endif
}; };