1313 **/
1414
1515#include < NTPSettingsService.h>
16+ #if FT_ENABLED(FT_ETHERNET)
17+ #include < ETH.h>
18+ #endif
1619
1720NTPSettingsService::NTPSettingsService (PsychicHttpServer *server,
1821 FS *fs,
@@ -29,11 +32,19 @@ NTPSettingsService::NTPSettingsService(PsychicHttpServer *server,
2932void NTPSettingsService::begin ()
3033{
3134 WiFi.onEvent (
32- std::bind (&NTPSettingsService::onStationModeDisconnected , this , std::placeholders::_1, std::placeholders::_2),
35+ std::bind (&NTPSettingsService::onNetworkDisconnected , this , std::placeholders::_1, std::placeholders::_2),
3336 WiFiEvent_t::ARDUINO_EVENT_WIFI_STA_DISCONNECTED);
34- WiFi.onEvent (std::bind (&NTPSettingsService::onStationModeGotIP , this , std::placeholders::_1, std::placeholders::_2),
37+ WiFi.onEvent (std::bind (&NTPSettingsService::onNetworkGotIP , this , std::placeholders::_1, std::placeholders::_2),
3538 WiFiEvent_t::ARDUINO_EVENT_WIFI_STA_GOT_IP);
3639
40+ #if FT_ENABLED(FT_ETHERNET)
41+ WiFi.onEvent (
42+ std::bind (&NTPSettingsService::onNetworkDisconnected, this , std::placeholders::_1, std::placeholders::_2),
43+ WiFiEvent_t::ARDUINO_EVENT_ETH_DISCONNECTED);
44+ WiFi.onEvent (std::bind (&NTPSettingsService::onNetworkGotIP, this , std::placeholders::_1, std::placeholders::_2),
45+ WiFiEvent_t::ARDUINO_EVENT_ETH_GOT_IP);
46+ #endif
47+
3748 _httpEndpoint.begin ();
3849 _server->on (TIME_PATH,
3950 HTTP_POST,
@@ -47,25 +58,29 @@ void NTPSettingsService::begin()
4758 configureNTP ();
4859}
4960
50- void NTPSettingsService::onStationModeGotIP (WiFiEvent_t event, WiFiEventInfo_t info)
61+ void NTPSettingsService::onNetworkGotIP (WiFiEvent_t event, WiFiEventInfo_t info)
5162{
5263#ifdef SERIAL_INFO
5364 Serial.println (F (" Got IP address, starting NTP Synchronization" ));
5465#endif
5566 configureNTP ();
5667}
5768
58- void NTPSettingsService::onStationModeDisconnected (WiFiEvent_t event, WiFiEventInfo_t info)
69+ void NTPSettingsService::onNetworkDisconnected (WiFiEvent_t event, WiFiEventInfo_t info)
5970{
6071#ifdef SERIAL_INFO
61- Serial.println (F (" WiFi connection dropped, stopping NTP." ));
72+ Serial.println (F (" Network connection dropped, stopping NTP." ));
6273#endif
6374 configureNTP ();
6475}
6576
6677void NTPSettingsService::configureNTP ()
6778{
68- if (WiFi.isConnected () && _state.enabled )
79+ bool networkConnected = WiFi.isConnected ();
80+ #if FT_ENABLED(FT_ETHERNET)
81+ networkConnected = networkConnected || ETH.connected ();
82+ #endif
83+ if (networkConnected && _state.enabled )
6984 {
7085#ifdef SERIAL_INFO
7186 Serial.println (F (" Starting NTP..." ));
0 commit comments