Fixed som HTML and JS problems. Removed external NTP library and using espressif internal NTP client instead

This commit is contained in:
Gunnar Skjold
2020-05-10 12:29:00 +02:00
parent efa99f970c
commit 778daf8645
5 changed files with 17 additions and 20 deletions

View File

@@ -22,7 +22,7 @@
#include <ArduinoJson.h>
#include <MQTT.h>
#include <DNSServer.h>
#include <NTPClient.h>
#include <TZ.h>
#if defined(ESP8266)
ADC_MODE(ADC_VCC);
@@ -48,9 +48,6 @@ HwTools hw;
DNSServer dnsServer;
WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP, "pool.ntp.org", 3600, 60000);
AmsConfiguration config;
RemoteDebug Debug;
@@ -235,7 +232,8 @@ void setup() {
if(config.hasConfig()) {
if(Debug.isActive(RemoteDebug::INFO)) config.print(&Debug);
WiFi_connect();
timeClient.begin();
configTime(TZ_Europe_Oslo, "pool.ntp.org");
//sntp_servermode_dhcp(0); // 0: disable obtaining SNTP servers from DHCP (enabled by default)
} else {
if(Debug.isActive(RemoteDebug::INFO)) {
debugI("No configuration, booting AP");
@@ -327,8 +325,6 @@ void loop() {
errorBlink();
}
timeClient.update();
if (strlen(config.getMqttHost()) > 0) {
mqtt.loop();
delay(10); // Needed to preserve power. After adding this, the voltage is super smooth on a HAN powered device
@@ -840,8 +836,6 @@ void MQTT_connect() {
if(config.isMqttSsl()) {
debugI("MQTT SSL is configured");
if(!timeClient.update()) debugW("NTP time is not ready");
secureClient = new WiFiClientSecure();
#if defined(ESP8266)
secureClient->setBufferSizes(512, 512);
@@ -881,8 +875,9 @@ void MQTT_connect() {
#if defined(ESP8266)
if(secureClient) {
debugD("Setting NTP time for secure MQTT connection");
secureClient->setX509Time(timeClient.getEpochTime());
time_t epoch = time(nullptr);
debugD("Setting NTP time %i for secure MQTT connection", epoch);
secureClient->setX509Time(epoch);
}
#endif