move code to handle network events from anonymous to class method

This commit is contained in:
technyon
2024-08-18 06:40:27 +02:00
parent b346977022
commit f26f9f6753
5 changed files with 76 additions and 56 deletions

View File

@@ -4,7 +4,7 @@
#define NUKI_HUB_VERSION "9.01"
#define NUKI_HUB_BUILD "unknownbuildnr"
#define NUKI_HUB_DATE "2024-08-17"
#define NUKI_HUB_DATE "2024-08-18"
#define GITHUB_LATEST_RELEASE_URL (char*)"https://github.com/technyon/nuki_hub/releases/latest"
#define GITHUB_OTA_MANIFEST_URL (char*)"https://raw.githubusercontent.com/technyon/nuki_hub/binary/ota/manifest.json"

View File

@@ -161,7 +161,10 @@ void NukiNetwork::setupDevice()
break;
case 11:
Log->println(F("Custom LAN Module"));
if(_preferences->getInt(preference_network_custom_phy, 0) > 0) _networkDeviceType = NetworkDeviceType::CUSTOM;
if(_preferences->getInt(preference_network_custom_phy, 0) > 0)
{
_networkDeviceType = NetworkDeviceType::CUSTOM;
}
else
{
Log->println(F("Custom LAN Module not setup correctly, falling back to Wi-Fi"));

View File

@@ -2593,9 +2593,18 @@ void WebCfgServer::buildHtml(AsyncWebServerRequest *request)
buildNavigationMenuEntry(response, "GPIO Configuration", "/gpiocfg");
buildNavigationMenuEntry(response, "Firmware update", "/ota");
buildNavigationMenuEntry(response, "Import/Export Configuration", "/impexpcfg");
if(_preferences->getInt(preference_network_hardware, 0) == 11) buildNavigationMenuEntry(response, "Custom Ethernet Configuration", "/custntw");
if(_preferences->getBool(preference_publish_debug_info, false)) buildNavigationMenuEntry(response, "Advanced Configuration", "/advanced");
if(_preferences->getBool(preference_webserial_enabled, false)) buildNavigationMenuEntry(response, "Open Webserial", "/webserial");
if(_preferences->getInt(preference_network_hardware, 0) == 11)
{
buildNavigationMenuEntry(response, "Custom Ethernet Configuration", "/custntw");
}
if (_preferences->getBool(preference_publish_debug_info, false))
{
buildNavigationMenuEntry(response, "Advanced Configuration", "/advanced");
}
if(_preferences->getBool(preference_webserial_enabled, false))
{
buildNavigationMenuEntry(response, "Open Webserial", "/webserial");
}
#ifndef CONFIG_IDF_TARGET_ESP32H2
if(_allowRestartToPortal) buildNavigationMenuEntry(response, "Configure Wi-Fi", "/wifi");
#endif

View File

@@ -142,6 +142,37 @@ void EthernetDevice::initialize()
}
Network.onEvent([&](arduino_event_id_t event, arduino_event_info_t info)
{
onNetworkEvent(event, info);
});
}
else
{
Log->println(F("Failed to initialize ethernet hardware"));
}
}
void EthernetDevice::update()
{
NetworkDevice::update();
if(_checkIpTs != -1)
{
if(_ipConfiguration->ipAddress() != ETH.localIP())
{
Log->println(F("ETH Set static IP"));
ETH.config(_ipConfiguration->ipAddress(), _ipConfiguration->defaultGateway(), _ipConfiguration->subnet(), _ipConfiguration->dnsServer());
_checkIpTs = (esp_timer_get_time() / 1000) + 2000;
}
else
{
_checkIpTs = -1;
}
}
}
void EthernetDevice::onNetworkEvent(arduino_event_id_t event, arduino_event_info_t info)
{
switch (event) {
case ARDUINO_EVENT_ETH_START:
@@ -193,32 +224,8 @@ void EthernetDevice::initialize()
Log->println(event);
break;
}
});
}
else
{
Log->println(F("Failed to initialize ethernet hardware"));
}
}
void EthernetDevice::update()
{
NetworkDevice::update();
if(_checkIpTs != -1)
{
if(_ipConfiguration->ipAddress() != ETH.localIP())
{
Log->println(F("ETH Set static IP"));
ETH.config(_ipConfiguration->ipAddress(), _ipConfiguration->defaultGateway(), _ipConfiguration->subnet(), _ipConfiguration->dnsServer());
_checkIpTs = (esp_timer_get_time() / 1000) + 2000;
}
else
{
_checkIpTs = -1;
}
}
}
void EthernetDevice::reconfigure()

View File

@@ -67,6 +67,7 @@ private:
void init();
void onDisconnected();
void waitForIpAddressWithTimeout();
void onNetworkEvent(arduino_event_id_t event, arduino_event_info_t info);
bool _connected = false;
bool _restartOnDisconnect = false;