mirror of
https://github.com/letscontrolit/ESPEasy.git
synced 2026-07-28 04:07:47 +00:00
[Network] Fix ESP8266 build
This commit is contained in:
@@ -18,13 +18,11 @@ namespace net {
|
||||
|
||||
struct NWPluginData_static_runtime {
|
||||
#ifdef ESP32
|
||||
NWPluginData_static_runtime(NetworkInterface *netif, const String& eventInterfaceName = EMPTY_STRING)
|
||||
: _netif(netif), _eventInterfaceName(eventInterfaceName)
|
||||
{}
|
||||
|
||||
NWPluginData_static_runtime(NetworkInterface *netif,
|
||||
const String & eventInterfaceName = EMPTY_STRING);
|
||||
#else // ifdef ESP32
|
||||
NWPluginData_static_runtime(bool isSTA, String& eventInterfaceName)
|
||||
: _isSTA(isSTA), _eventInterfaceName(eventInterfaceName) {}
|
||||
NWPluginData_static_runtime(bool isSTA,
|
||||
const char * eventInterfaceName);
|
||||
|
||||
#endif // ifdef ESP32
|
||||
|
||||
|
||||
@@ -9,11 +9,15 @@
|
||||
# include <esp_netif.h>
|
||||
# include <esp_netif_types.h>
|
||||
|
||||
#define NW_PLUGIN_LOG_EVENTS false
|
||||
# define NW_PLUGIN_LOG_EVENTS false
|
||||
|
||||
namespace ESPEasy {
|
||||
namespace net {
|
||||
|
||||
NWPluginData_static_runtime::NWPluginData_static_runtime(NetworkInterface *netif, const String& eventInterfaceName)
|
||||
: _netif(netif), _eventInterfaceName(eventInterfaceName)
|
||||
{}
|
||||
|
||||
bool NWPluginData_static_runtime::started() const
|
||||
{
|
||||
if (!_netif) { return false; }
|
||||
@@ -59,25 +63,27 @@ void NWPluginData_static_runtime::mark_start()
|
||||
_netif->setRoutePrio(_route_prio);
|
||||
}
|
||||
# endif // if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 5, 0)
|
||||
#if NW_PLUGIN_LOG_EVENTS
|
||||
# if NW_PLUGIN_LOG_EVENTS
|
||||
|
||||
if (loglevelActiveFor(LOG_LEVEL_INFO)) {
|
||||
addLog(LOG_LEVEL_INFO, strformat(
|
||||
F("%s: Started"),
|
||||
_netif->desc()));
|
||||
}
|
||||
#endif
|
||||
# endif // if NW_PLUGIN_LOG_EVENTS
|
||||
}
|
||||
|
||||
void NWPluginData_static_runtime::mark_stop()
|
||||
{
|
||||
_startStopStats.setOff();
|
||||
#if NW_PLUGIN_LOG_EVENTS
|
||||
# if NW_PLUGIN_LOG_EVENTS
|
||||
|
||||
if (_netif && loglevelActiveFor(LOG_LEVEL_INFO)) {
|
||||
addLog(LOG_LEVEL_INFO, strformat(
|
||||
F("%s: Stopped"),
|
||||
_netif->desc()));
|
||||
}
|
||||
#endif
|
||||
# endif // if NW_PLUGIN_LOG_EVENTS
|
||||
}
|
||||
|
||||
void NWPluginData_static_runtime::mark_got_IP()
|
||||
@@ -95,7 +101,8 @@ void NWPluginData_static_runtime::mark_got_IP()
|
||||
auto tmp = _netif->dnsIP(i);
|
||||
|
||||
_dns_cache[i] = tmp; // Also set the 'empty' ones so we won't set left-over DNS server from when another interface was active.
|
||||
#if NW_PLUGIN_LOG_EVENTS
|
||||
# if NW_PLUGIN_LOG_EVENTS
|
||||
|
||||
if ((tmp != INADDR_NONE) && loglevelActiveFor(LOG_LEVEL_INFO)) {
|
||||
addLog(LOG_LEVEL_INFO, strformat(
|
||||
F("%s: DNS Cache %d set to %s"),
|
||||
@@ -103,9 +110,10 @@ void NWPluginData_static_runtime::mark_got_IP()
|
||||
i,
|
||||
tmp.toString(true).c_str()));
|
||||
}
|
||||
#endif
|
||||
# endif // if NW_PLUGIN_LOG_EVENTS
|
||||
}
|
||||
#if NW_PLUGIN_LOG_EVENTS
|
||||
# if NW_PLUGIN_LOG_EVENTS
|
||||
|
||||
if (loglevelActiveFor(LOG_LEVEL_INFO)) {
|
||||
addLog(LOG_LEVEL_INFO, strformat(
|
||||
F("%s: Got IP: %s"),
|
||||
@@ -113,7 +121,7 @@ void NWPluginData_static_runtime::mark_got_IP()
|
||||
_netif->localIP().toString().c_str()
|
||||
));
|
||||
}
|
||||
#endif
|
||||
# endif // if NW_PLUGIN_LOG_EVENTS
|
||||
|
||||
}
|
||||
|
||||
@@ -128,7 +136,8 @@ void NWPluginData_static_runtime::mark_got_IPv6(ip_event_got_ip6_t *event)
|
||||
if (!_netif->isDefault()) {
|
||||
nonDefaultNetworkInterface_gotIP = true;
|
||||
}
|
||||
#if NW_PLUGIN_LOG_EVENTS
|
||||
# if NW_PLUGIN_LOG_EVENTS
|
||||
|
||||
if (loglevelActiveFor(LOG_LEVEL_INFO)) {
|
||||
if (event) {
|
||||
esp_ip6_addr_type_t addr_type = esp_netif_ip6_get_addr_type(&event->ip6_info.ip);
|
||||
@@ -147,7 +156,7 @@ void NWPluginData_static_runtime::mark_got_IPv6(ip_event_got_ip6_t *event)
|
||||
_netif->desc()));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
# endif // if NW_PLUGIN_LOG_EVENTS
|
||||
}
|
||||
|
||||
# endif // if FEATURE_USE_IPV6
|
||||
@@ -158,13 +167,14 @@ void NWPluginData_static_runtime::mark_lost_IP()
|
||||
# if FEATURE_USE_IPV6
|
||||
_gotIP6Stats.setOff();
|
||||
# endif
|
||||
#if NW_PLUGIN_LOG_EVENTS
|
||||
# if NW_PLUGIN_LOG_EVENTS
|
||||
|
||||
if (_netif && loglevelActiveFor(LOG_LEVEL_INFO)) {
|
||||
addLog(LOG_LEVEL_INFO, strformat(
|
||||
F("%s: Lost IP"),
|
||||
_netif->desc()));
|
||||
}
|
||||
#endif
|
||||
# endif // if NW_PLUGIN_LOG_EVENTS
|
||||
}
|
||||
|
||||
void NWPluginData_static_runtime::mark_begin_establish_connection()
|
||||
@@ -187,20 +197,19 @@ void NWPluginData_static_runtime::log_connected()
|
||||
if (_establishConnectStats.getCycleCount()) {
|
||||
// Log duration
|
||||
addLog(LOG_LEVEL_INFO, strformat(
|
||||
F("%s: Connected, took: %s in %d attempts"),
|
||||
_netif->desc(),
|
||||
format_msec_duration_HMS(
|
||||
_establishConnectStats.getLastOnDuration_ms()).c_str(),
|
||||
_establishConnectStats.getCycleCount()));
|
||||
F("%s: Connected, took: %s in %d attempts"),
|
||||
_netif->desc(),
|
||||
format_msec_duration_HMS(
|
||||
_establishConnectStats.getLastOnDuration_ms()).c_str(),
|
||||
_establishConnectStats.getCycleCount()));
|
||||
} else {
|
||||
addLog(LOG_LEVEL_INFO, strformat(
|
||||
F("%s: Connected"),
|
||||
_netif->desc()));
|
||||
F("%s: Connected"),
|
||||
_netif->desc()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void NWPluginData_static_runtime::mark_disconnected()
|
||||
{
|
||||
_connectedStats.setOff();
|
||||
@@ -219,7 +228,6 @@ void NWPluginData_static_runtime::log_disconnected()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} // namespace net
|
||||
} // namespace ESPEasy
|
||||
|
||||
|
||||
@@ -7,6 +7,9 @@
|
||||
namespace ESPEasy {
|
||||
namespace net {
|
||||
|
||||
NWPluginData_static_runtime::NWPluginData_static_runtime(bool isSTA, const char * eventInterfaceName)
|
||||
: _isSTA(isSTA), _eventInterfaceName(eventInterfaceName) {}
|
||||
|
||||
bool NWPluginData_static_runtime::started() const
|
||||
{
|
||||
// FIXME TD-er: Does this work reliable on ESP8266?
|
||||
@@ -33,34 +36,34 @@ bool NWPluginData_static_runtime::hasIP() const
|
||||
void NWPluginData_static_runtime::mark_start()
|
||||
{
|
||||
_startStopStats.setOn();
|
||||
#ifndef BUILD_NO_DEBUG
|
||||
# ifndef BUILD_NO_DEBUG
|
||||
addLog(LOG_LEVEL_INFO, _isSTA ? F("STA: Started") : F("AP: Started"));
|
||||
#endif
|
||||
# endif
|
||||
}
|
||||
|
||||
void NWPluginData_static_runtime::mark_stop()
|
||||
{
|
||||
_startStopStats.setOff();
|
||||
#ifndef BUILD_NO_DEBUG
|
||||
# ifndef BUILD_NO_DEBUG
|
||||
addLog(LOG_LEVEL_INFO, _isSTA ? F("STA: Stopped") : F("AP: Stopped"));
|
||||
#endif
|
||||
# endif
|
||||
}
|
||||
|
||||
void NWPluginData_static_runtime::mark_got_IP()
|
||||
{
|
||||
// Set OnOffTimer to off so we can also count how often we het new IP
|
||||
_gotIPStats.forceSet(true);
|
||||
#ifndef BUILD_NO_DEBUG
|
||||
# ifndef BUILD_NO_DEBUG
|
||||
addLog(LOG_LEVEL_INFO, _isSTA ? F("STA: Got IP") : F("AP: Got IP"));
|
||||
#endif
|
||||
# endif
|
||||
}
|
||||
|
||||
void NWPluginData_static_runtime::mark_lost_IP()
|
||||
{
|
||||
_gotIPStats.setOff();
|
||||
#ifndef BUILD_NO_DEBUG
|
||||
# ifndef BUILD_NO_DEBUG
|
||||
addLog(LOG_LEVEL_INFO, _isSTA ? F("STA: Lost IP") : F("AP: Lost IP"));
|
||||
#endif
|
||||
# endif
|
||||
}
|
||||
|
||||
void NWPluginData_static_runtime::mark_begin_establish_connection()
|
||||
@@ -71,45 +74,47 @@ void NWPluginData_static_runtime::mark_begin_establish_connection()
|
||||
|
||||
void NWPluginData_static_runtime::mark_connected()
|
||||
{
|
||||
#ifndef BUILD_NO_DEBUG
|
||||
# ifndef BUILD_NO_DEBUG
|
||||
const bool logDuration = _establishConnectStats.isOn();
|
||||
#endif
|
||||
# endif
|
||||
_establishConnectStats.setOff();
|
||||
_connectedStats.setOn();
|
||||
}
|
||||
|
||||
void NWPluginData_static_runtime::log_connected()
|
||||
{
|
||||
#ifndef BUILD_NO_DEBUG
|
||||
# ifndef BUILD_NO_DEBUG
|
||||
|
||||
if (loglevelActiveFor(LOG_LEVEL_INFO)) {
|
||||
if (_establishConnectStats.getCycleCount()) {
|
||||
addLog(LOG_LEVEL_INFO, concat(
|
||||
F("STA: Connected, took: "),
|
||||
format_msec_duration_HMS(
|
||||
_establishConnectStats.getLastOnDuration_ms())));
|
||||
F("STA: Connected, took: "),
|
||||
format_msec_duration_HMS(
|
||||
_establishConnectStats.getLastOnDuration_ms())));
|
||||
} else {
|
||||
addLog(LOG_LEVEL_INFO, F("STA: Connected"));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
# endif // ifndef BUILD_NO_DEBUG
|
||||
}
|
||||
|
||||
void NWPluginData_static_runtime::mark_disconnected()
|
||||
{
|
||||
_connectedStats.setOff();
|
||||
#ifndef BUILD_NO_DEBUG
|
||||
#endif
|
||||
# ifndef BUILD_NO_DEBUG
|
||||
# endif
|
||||
}
|
||||
|
||||
void NWPluginData_static_runtime::log_disconnected()
|
||||
{
|
||||
#ifndef BUILD_NO_DEBUG
|
||||
# ifndef BUILD_NO_DEBUG
|
||||
|
||||
if (_isSTA && loglevelActiveFor(LOG_LEVEL_INFO)) {
|
||||
addLog(LOG_LEVEL_INFO, concat(
|
||||
F("STA: Disconnected. Connected for: "),
|
||||
format_msec_duration_HMS(_connectedStats.getLastOnDuration_ms())));
|
||||
}
|
||||
#endif
|
||||
# endif // ifndef BUILD_NO_DEBUG
|
||||
}
|
||||
|
||||
} // namespace net
|
||||
|
||||
@@ -29,7 +29,7 @@ namespace wifi {
|
||||
# ifdef ESP32
|
||||
static NWPluginData_static_runtime stats_and_cache(&NW_PLUGIN_INTERFACE);
|
||||
# else
|
||||
static NWPluginData_static_runtime stats_and_cache(false, F("AP"));
|
||||
static NWPluginData_static_runtime stats_and_cache(false, "AP"); // Cannot use flash strings during init of static objects
|
||||
# endif // ifdef ESP32
|
||||
static bool nw002_initialized{};
|
||||
# ifdef ESP32
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace ESPEasy {
|
||||
namespace net {
|
||||
namespace wifi {
|
||||
|
||||
static NWPluginData_static_runtime stats_and_cache(true, F("WiFi"));
|
||||
static NWPluginData_static_runtime stats_and_cache(true, "WiFi"); // Cannot use flash strings during init of static objects
|
||||
static WiFiDisconnectReason _wifi_disconnect_reason = WiFiDisconnectReason::WIFI_DISCONNECT_REASON_UNSPECIFIED;
|
||||
|
||||
static uint8_t _authmode{};
|
||||
|
||||
Reference in New Issue
Block a user