diff --git a/platformio.ini b/platformio.ini index 155460b1c..fa1e8f622 100644 --- a/platformio.ini +++ b/platformio.ini @@ -14,6 +14,7 @@ default_envs = tbeam ;default_envs = heltec-v2.0 ;default_envs = heltec-v1 ;default_envs = tlora-v1 +;default_envs = tlora-v1 ;default_envs = tlora_v1_3 ;default_envs = tlora-v2 ;default_envs = lora-relay-v1 # nrf board @@ -116,6 +117,8 @@ lib_deps = robtillaart/DS18B20@^0.1.11 h2zero/NimBLE-Arduino@1.3.1 tobozo/ESP32-targz@^1.1.4 + arduino-libraries/NTPClient#531eff39d9fbc831f3d03f706a161739203fbe2a + # Hmm - this doesn't work yet # board_build.ldscript = linker/esp32.extram.bss.ld lib_ignore = diff --git a/src/gps/RTC.h b/src/gps/RTC.h index 3a89d9810..730d1914e 100644 --- a/src/gps/RTC.h +++ b/src/gps/RTC.h @@ -11,8 +11,11 @@ enum RTCQuality { /// Some other node gave us a time we can use RTCQualityFromNet = 1, + /// Our time is based on NTP + RTCQualityNTP= 2, + /// Our time is based on our own GPS - RTCQualityGPS = 2 + RTCQualityGPS = 3 }; RTCQuality getRTCQuality(); diff --git a/src/mesh/http/WiFiAPClient.cpp b/src/mesh/http/WiFiAPClient.cpp index c5cbe9c93..2037d06eb 100644 --- a/src/mesh/http/WiFiAPClient.cpp +++ b/src/mesh/http/WiFiAPClient.cpp @@ -10,6 +10,8 @@ #include #include #include +#include +#include using namespace concurrency; @@ -18,6 +20,10 @@ static void WiFiEvent(WiFiEvent_t event); // DNS Server for the Captive Portal DNSServer dnsServer; +// NTP +WiFiUDP ntpUDP; +NTPClient timeClient(ntpUDP, "0.pool.ntp.org"); + uint8_t wifiDisconnectReason = 0; // Stores our hostname @@ -46,10 +52,11 @@ static WifiSleepObserver wifiSleepObserver; static int32_t reconnectWiFi() { + const char *wifiName = radioConfig.preferences.wifi_ssid; + const char *wifiPsw = radioConfig.preferences.wifi_password; + if (radioConfig.has_preferences && needReconnect) { - const char *wifiName = radioConfig.preferences.wifi_ssid; - const char *wifiPsw = radioConfig.preferences.wifi_password; if (!*wifiPsw) // Treat empty password as no password wifiPsw = NULL; @@ -60,9 +67,21 @@ static int32_t reconnectWiFi() DEBUG_MSG("... Reconnecting to WiFi access point\n"); WiFi.mode(WIFI_MODE_STA); WiFi.begin(wifiName, wifiPsw); + + // Starting timeClient; + + } } + if (*wifiName) { + DEBUG_MSG("Updating NTP time\n"); + timeClient.update(); + + Serial.println(timeClient.getFormattedTime()); + Serial.println(timeClient.getEpochTime()); + } + return 30 * 1000; // every 30 seconds } @@ -128,6 +147,9 @@ static void onNetworkConnected() MDNS.addService("https", "tcp", 443); } + DEBUG_MSG("Starting NTP time client\n"); + timeClient.begin(); + initWebServer(); initApiServer();