Merge branch 'meshtastic:master' into SPIFFS_UPDATE

This commit is contained in:
Jm Casler
2022-01-05 20:52:39 -08:00
committed by GitHub
3 changed files with 46 additions and 5 deletions

View File

@@ -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();

View File

@@ -1,5 +1,6 @@
#include "mesh/http/WiFiAPClient.h"
#include "NodeDB.h"
#include "RTC.h"
#include "concurrency/Periodic.h"
#include "configuration.h"
#include "main.h"
@@ -9,7 +10,9 @@
#include "target_specific.h"
#include <DNSServer.h>
#include <ESPmDNS.h>
#include <NTPClient.h>
#include <WiFi.h>
#include <WiFiUdp.h>
using namespace concurrency;
@@ -18,6 +21,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 +53,10 @@ static WifiSleepObserver wifiSleepObserver;
static int32_t reconnectWiFi()
{
if (radioConfig.has_preferences && needReconnect) {
const char *wifiName = radioConfig.preferences.wifi_ssid;
const char *wifiPsw = radioConfig.preferences.wifi_password;
const char *wifiName = radioConfig.preferences.wifi_ssid;
const char *wifiPsw = radioConfig.preferences.wifi_password;
if (radioConfig.has_preferences && needReconnect && !WiFi.isConnected()) {
if (!*wifiPsw) // Treat empty password as no password
wifiPsw = NULL;
@@ -60,6 +67,26 @@ 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) {
if (WiFi.isConnected()) {
DEBUG_MSG("Updating NTP time\n");
if (timeClient.update()) {
DEBUG_MSG("NTP Request Success - Setting RTCQualityNTP if needed\n");
struct timeval tv;
tv.tv_sec = timeClient.getEpochTime();
tv.tv_usec = 0;
perhapsSetRTC(RTCQualityNTP, &tv);
} else {
DEBUG_MSG("NTP Update failed\n");
}
}
@@ -128,6 +155,10 @@ static void onNetworkConnected()
MDNS.addService("https", "tcp", 443);
}
DEBUG_MSG("Starting NTP time client\n");
timeClient.begin();
timeClient.setUpdateInterval(60*60); // Update once an hour
initWebServer();
initApiServer();