move code to handle network events from anonymous to class method
This commit is contained in:
@@ -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"
|
||||
|
||||
@@ -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"));
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -143,56 +143,7 @@ void EthernetDevice::initialize()
|
||||
|
||||
Network.onEvent([&](arduino_event_id_t event, arduino_event_info_t info)
|
||||
{
|
||||
switch (event) {
|
||||
case ARDUINO_EVENT_ETH_START:
|
||||
Log->println("ETH Started");
|
||||
ETH.setHostname(_hostname.c_str());
|
||||
break;
|
||||
case ARDUINO_EVENT_ETH_CONNECTED:
|
||||
Log->println("ETH Connected");
|
||||
if(!localIP().equals("0.0.0.0"))
|
||||
{
|
||||
_connected = true;
|
||||
}
|
||||
break;
|
||||
case ARDUINO_EVENT_ETH_GOT_IP:
|
||||
Log->printf("ETH Got IP: '%s'\n", esp_netif_get_desc(info.got_ip.esp_netif));
|
||||
Log->println(ETH);
|
||||
|
||||
// For RMII devices, this check is handled in the update() method.
|
||||
if(_useSpi && !_ipConfiguration->dhcpEnabled() && _ipConfiguration->ipAddress() != ETH.localIP())
|
||||
{
|
||||
Log->printf("Static IP not used, retrying to set static IP");
|
||||
ETH.config(_ipConfiguration->ipAddress(), _ipConfiguration->defaultGateway(), _ipConfiguration->subnet(), _ipConfiguration->dnsServer());
|
||||
ETH.begin(_type, _phy_addr, _cs, _irq, _rst, SPI);
|
||||
}
|
||||
|
||||
_connected = true;
|
||||
if(_preferences->getBool(preference_ntw_reconfigure, false))
|
||||
{
|
||||
_preferences->putBool(preference_ntw_reconfigure, false);
|
||||
}
|
||||
break;
|
||||
case ARDUINO_EVENT_ETH_LOST_IP:
|
||||
Log->println("ETH Lost IP");
|
||||
_connected = false;
|
||||
onDisconnected();
|
||||
break;
|
||||
case ARDUINO_EVENT_ETH_DISCONNECTED:
|
||||
Log->println("ETH Disconnected");
|
||||
_connected = false;
|
||||
onDisconnected();
|
||||
break;
|
||||
case ARDUINO_EVENT_ETH_STOP:
|
||||
Log->println("ETH Stopped");
|
||||
_connected = false;
|
||||
onDisconnected();
|
||||
break;
|
||||
default:
|
||||
Log->print("ETH Event: ");
|
||||
Log->println(event);
|
||||
break;
|
||||
}
|
||||
onNetworkEvent(event, info);
|
||||
});
|
||||
}
|
||||
else
|
||||
@@ -221,6 +172,62 @@ void EthernetDevice::update()
|
||||
}
|
||||
|
||||
|
||||
void EthernetDevice::onNetworkEvent(arduino_event_id_t event, arduino_event_info_t info)
|
||||
{
|
||||
switch (event) {
|
||||
case ARDUINO_EVENT_ETH_START:
|
||||
Log->println("ETH Started");
|
||||
ETH.setHostname(_hostname.c_str());
|
||||
break;
|
||||
case ARDUINO_EVENT_ETH_CONNECTED:
|
||||
Log->println("ETH Connected");
|
||||
if(!localIP().equals("0.0.0.0"))
|
||||
{
|
||||
_connected = true;
|
||||
}
|
||||
break;
|
||||
case ARDUINO_EVENT_ETH_GOT_IP:
|
||||
Log->printf("ETH Got IP: '%s'\n", esp_netif_get_desc(info.got_ip.esp_netif));
|
||||
Log->println(ETH);
|
||||
|
||||
// For RMII devices, this check is handled in the update() method.
|
||||
if(_useSpi && !_ipConfiguration->dhcpEnabled() && _ipConfiguration->ipAddress() != ETH.localIP())
|
||||
{
|
||||
Log->printf("Static IP not used, retrying to set static IP");
|
||||
ETH.config(_ipConfiguration->ipAddress(), _ipConfiguration->defaultGateway(), _ipConfiguration->subnet(), _ipConfiguration->dnsServer());
|
||||
ETH.begin(_type, _phy_addr, _cs, _irq, _rst, SPI);
|
||||
}
|
||||
|
||||
_connected = true;
|
||||
if(_preferences->getBool(preference_ntw_reconfigure, false))
|
||||
{
|
||||
_preferences->putBool(preference_ntw_reconfigure, false);
|
||||
}
|
||||
break;
|
||||
case ARDUINO_EVENT_ETH_LOST_IP:
|
||||
Log->println("ETH Lost IP");
|
||||
_connected = false;
|
||||
onDisconnected();
|
||||
break;
|
||||
case ARDUINO_EVENT_ETH_DISCONNECTED:
|
||||
Log->println("ETH Disconnected");
|
||||
_connected = false;
|
||||
onDisconnected();
|
||||
break;
|
||||
case ARDUINO_EVENT_ETH_STOP:
|
||||
Log->println("ETH Stopped");
|
||||
_connected = false;
|
||||
onDisconnected();
|
||||
break;
|
||||
default:
|
||||
Log->print("ETH Event: ");
|
||||
Log->println(event);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void EthernetDevice::reconfigure()
|
||||
{
|
||||
delay(200);
|
||||
@@ -266,4 +273,4 @@ String EthernetDevice::localIP()
|
||||
String EthernetDevice::BSSIDstr()
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user