mirror of
https://github.com/meshtastic/firmware.git
synced 2025-06-09 06:32:06 +00:00
Partial work for NTP client
This commit is contained in:
parent
f3427084c2
commit
654558abcd
@ -9,10 +9,10 @@
|
|||||||
; https://docs.platformio.org/page/projectconf.html
|
; https://docs.platformio.org/page/projectconf.html
|
||||||
|
|
||||||
[platformio]
|
[platformio]
|
||||||
default_envs = tbeam
|
;default_envs = tbeam
|
||||||
;default_envs = tbeam0.7
|
;default_envs = tbeam0.7
|
||||||
;default_envs = heltec-v2.0
|
;default_envs = heltec-v2.0
|
||||||
;default_envs = tlora-v1
|
default_envs = tlora-v1
|
||||||
;default_envs = tlora_v1_3
|
;default_envs = tlora_v1_3
|
||||||
;default_envs = tlora-v2
|
;default_envs = tlora-v2
|
||||||
;default_envs = lora-relay-v1 # nrf board
|
;default_envs = lora-relay-v1 # nrf board
|
||||||
@ -114,6 +114,7 @@ lib_deps =
|
|||||||
paulstoffregen/OneWire@^2.3.5
|
paulstoffregen/OneWire@^2.3.5
|
||||||
robtillaart/DS18B20@^0.1.11
|
robtillaart/DS18B20@^0.1.11
|
||||||
h2zero/NimBLE-Arduino@1.3.1
|
h2zero/NimBLE-Arduino@1.3.1
|
||||||
|
arduino-libraries/NTPClient#531eff39d9fbc831f3d03f706a161739203fbe2a
|
||||||
# Hmm - this doesn't work yet
|
# Hmm - this doesn't work yet
|
||||||
# board_build.ldscript = linker/esp32.extram.bss.ld
|
# board_build.ldscript = linker/esp32.extram.bss.ld
|
||||||
lib_ignore =
|
lib_ignore =
|
||||||
@ -127,8 +128,8 @@ platform_packages =
|
|||||||
;upload_port = /dev/ttyUSB0
|
;upload_port = /dev/ttyUSB0
|
||||||
;monitor_port = /dev/ttyUSB0
|
;monitor_port = /dev/ttyUSB0
|
||||||
|
|
||||||
;upload_port = /dev/cu.SLAB_USBtoUART
|
upload_port = /dev/cu.SLAB_USBtoUART
|
||||||
;monitor_port = /dev/cu.SLAB_USBtoUART
|
monitor_port = /dev/cu.SLAB_USBtoUART
|
||||||
|
|
||||||
; customize the partition table
|
; customize the partition table
|
||||||
; http://docs.platformio.org/en/latest/platforms/espressif32.html#partition-tables
|
; http://docs.platformio.org/en/latest/platforms/espressif32.html#partition-tables
|
||||||
|
@ -11,8 +11,11 @@ enum RTCQuality {
|
|||||||
/// Some other node gave us a time we can use
|
/// Some other node gave us a time we can use
|
||||||
RTCQualityFromNet = 1,
|
RTCQualityFromNet = 1,
|
||||||
|
|
||||||
|
/// Our time is based on NTP
|
||||||
|
RTCQualityNTP= 2,
|
||||||
|
|
||||||
/// Our time is based on our own GPS
|
/// Our time is based on our own GPS
|
||||||
RTCQualityGPS = 2
|
RTCQualityGPS = 3
|
||||||
};
|
};
|
||||||
|
|
||||||
RTCQuality getRTCQuality();
|
RTCQuality getRTCQuality();
|
||||||
|
@ -3,13 +3,15 @@
|
|||||||
#include "concurrency/Periodic.h"
|
#include "concurrency/Periodic.h"
|
||||||
#include "configuration.h"
|
#include "configuration.h"
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include "mqtt/MQTT.h"
|
|
||||||
#include "mesh/http/WebServer.h"
|
#include "mesh/http/WebServer.h"
|
||||||
#include "mesh/wifi/WiFiServerAPI.h"
|
#include "mesh/wifi/WiFiServerAPI.h"
|
||||||
|
#include "mqtt/MQTT.h"
|
||||||
#include "target_specific.h"
|
#include "target_specific.h"
|
||||||
#include <DNSServer.h>
|
#include <DNSServer.h>
|
||||||
#include <ESPmDNS.h>
|
#include <ESPmDNS.h>
|
||||||
#include <WiFi.h>
|
#include <WiFi.h>
|
||||||
|
#include <WiFiUdp.h>
|
||||||
|
#include <NTPClient.h>
|
||||||
|
|
||||||
using namespace concurrency;
|
using namespace concurrency;
|
||||||
|
|
||||||
@ -18,6 +20,10 @@ static void WiFiEvent(WiFiEvent_t event);
|
|||||||
// DNS Server for the Captive Portal
|
// DNS Server for the Captive Portal
|
||||||
DNSServer dnsServer;
|
DNSServer dnsServer;
|
||||||
|
|
||||||
|
// NTP
|
||||||
|
WiFiUDP ntpUDP;
|
||||||
|
NTPClient timeClient(ntpUDP, "0.pool.ntp.org");
|
||||||
|
|
||||||
uint8_t wifiDisconnectReason = 0;
|
uint8_t wifiDisconnectReason = 0;
|
||||||
|
|
||||||
// Stores our hostname
|
// Stores our hostname
|
||||||
@ -46,10 +52,11 @@ static WifiSleepObserver wifiSleepObserver;
|
|||||||
|
|
||||||
static int32_t reconnectWiFi()
|
static int32_t reconnectWiFi()
|
||||||
{
|
{
|
||||||
|
const char *wifiName = radioConfig.preferences.wifi_ssid;
|
||||||
|
const char *wifiPsw = radioConfig.preferences.wifi_password;
|
||||||
|
|
||||||
if (radioConfig.has_preferences && needReconnect) {
|
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
|
if (!*wifiPsw) // Treat empty password as no password
|
||||||
wifiPsw = NULL;
|
wifiPsw = NULL;
|
||||||
@ -60,9 +67,21 @@ static int32_t reconnectWiFi()
|
|||||||
DEBUG_MSG("... Reconnecting to WiFi access point\n");
|
DEBUG_MSG("... Reconnecting to WiFi access point\n");
|
||||||
WiFi.mode(WIFI_MODE_STA);
|
WiFi.mode(WIFI_MODE_STA);
|
||||||
WiFi.begin(wifiName, wifiPsw);
|
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
|
return 30 * 1000; // every 30 seconds
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -128,6 +147,9 @@ static void onNetworkConnected()
|
|||||||
MDNS.addService("https", "tcp", 443);
|
MDNS.addService("https", "tcp", 443);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DEBUG_MSG("Starting NTP time client\n");
|
||||||
|
timeClient.begin();
|
||||||
|
|
||||||
initWebServer();
|
initWebServer();
|
||||||
initApiServer();
|
initApiServer();
|
||||||
|
|
||||||
@ -135,7 +157,7 @@ static void onNetworkConnected()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// FIXME this is kinda yucky, instead we should just have an observable for 'wifireconnected'
|
// FIXME this is kinda yucky, instead we should just have an observable for 'wifireconnected'
|
||||||
if(mqtt)
|
if (mqtt)
|
||||||
mqtt->reconnect();
|
mqtt->reconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -176,7 +198,6 @@ bool initWifi(bool forceSoftAP)
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
DEBUG_MSG("Starting WIFI AP: ssid=%s, ok=%d\n", wifiName, WiFi.softAP(wifiName, wifiPsw));
|
DEBUG_MSG("Starting WIFI AP: ssid=%s, ok=%d\n", wifiName, WiFi.softAP(wifiName, wifiPsw));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
WiFi.softAPConfig(apIP, apIP, IPAddress(255, 255, 255, 0));
|
WiFi.softAPConfig(apIP, apIP, IPAddress(255, 255, 255, 0));
|
||||||
|
Loading…
Reference in New Issue
Block a user