mirror of
https://github.com/Laxilef/OTGateway.git
synced 2025-12-14 04:04:28 +05:00
refactoring: arp gratuitous for esp8266
This commit is contained in:
@@ -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;
|
||||||
@@ -47,7 +51,7 @@ HeaderParameter* wmExtPumpHeader;
|
|||||||
|
|
||||||
extern EEManager eeSettings;
|
extern EEManager eeSettings;
|
||||||
#if USE_TELNET
|
#if USE_TELNET
|
||||||
extern ESPTelnetStream TelnetStream;
|
extern ESPTelnetStream TelnetStream;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
const char S_WIFI[] PROGMEM = "WIFI";
|
const char S_WIFI[] PROGMEM = "WIFI";
|
||||||
@@ -174,9 +178,9 @@ protected:
|
|||||||
}
|
}
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
#ifdef WOKWI
|
#ifdef WOKWI
|
||||||
WiFi.begin("Wokwi-GUEST", "", 6);
|
WiFi.begin("Wokwi-GUEST", "", 6);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
wm.setDebugOutput(settings.debug, (wm_debuglevel_t) WM_DEBUG_MODE);
|
wm.setDebugOutput(settings.debug, (wm_debuglevel_t) WM_DEBUG_MODE);
|
||||||
wm.setTitle(PROJECT_NAME);
|
wm.setTitle(PROJECT_NAME);
|
||||||
@@ -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);
|
||||||
@@ -232,9 +239,12 @@ protected:
|
|||||||
wm.startConfigPortal(AP_SSID, AP_PASSWORD);
|
wm.startConfigPortal(AP_SSID, AP_PASSWORD);
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
#if USE_TELNET
|
#if USE_TELNET
|
||||||
TelnetStream.stop();
|
TelnetStream.stop();
|
||||||
#endif
|
#ifdef ARDUINO_ARCH_ESP8266
|
||||||
|
::yield();
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
Log.sinfoln(FPSTR(S_WIFI), F("Disconnected"));
|
Log.sinfoln(FPSTR(S_WIFI), F("Disconnected"));
|
||||||
}
|
}
|
||||||
@@ -254,28 +264,37 @@ 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);
|
||||||
#endif
|
#ifdef ARDUINO_ARCH_ESP8266
|
||||||
|
::yield();
|
||||||
|
#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
|
||||||
};
|
};
|
||||||
Reference in New Issue
Block a user