mirror of
https://github.com/UtilitechAS/amsreader-firmware.git
synced 2026-03-03 02:09:00 +00:00
Fixed NTP
This commit is contained in:
@@ -32,7 +32,7 @@ lib_ignore = ${common.lib_ignore}
|
||||
extra_scripts = ${common.extra_scripts}
|
||||
|
||||
[env:esp32]
|
||||
platform = https://github.com/tasmota/platform-espressif32/releases/download/2023.02.00/platform-espressif32.zip
|
||||
platform = https://github.com/tasmota/platform-espressif32/releases/download/2023.04.02/platform-espressif32.zip
|
||||
framework = arduino
|
||||
board = esp32dev
|
||||
board_build.f_cpu = 160000000L
|
||||
@@ -47,7 +47,7 @@ extra_scripts = ${common.extra_scripts}
|
||||
# https://github.com/Jason2866/esp32-arduino-lib-builder
|
||||
|
||||
[env:esp32s2]
|
||||
platform = https://github.com/tasmota/platform-espressif32/releases/download/2023.02.00/platform-espressif32.zip
|
||||
platform = https://github.com/tasmota/platform-espressif32/releases/download/2023.04.02/platform-espressif32.zip
|
||||
framework = arduino
|
||||
board = esp32-s2-saola-1
|
||||
board_build.mcu = esp32s2
|
||||
@@ -63,7 +63,7 @@ lib_ignore = ${common.lib_ignore}
|
||||
extra_scripts = ${common.extra_scripts}
|
||||
|
||||
[env:esp32solo]
|
||||
platform = https://github.com/tasmota/platform-espressif32/releases/download/2023.02.00/platform-espressif32.zip
|
||||
platform = https://github.com/tasmota/platform-espressif32/releases/download/2023.04.02/platform-espressif32.zip
|
||||
framework = arduino
|
||||
board = esp32-solo1
|
||||
board_build.f_cpu = 160000000L
|
||||
@@ -75,7 +75,7 @@ lib_ignore = ${common.lib_ignore}
|
||||
extra_scripts = ${common.extra_scripts}
|
||||
|
||||
[env:esp32c3]
|
||||
platform = https://github.com/tasmota/platform-espressif32/releases/download/2023.02.00/platform-espressif32.zip
|
||||
platform = https://github.com/tasmota/platform-espressif32/releases/download/2023.04.02/platform-espressif32.zip
|
||||
framework = arduino
|
||||
board = esp32-c3-devkitm-1
|
||||
board_build.mcu = esp32c3
|
||||
|
||||
@@ -341,9 +341,6 @@ void setup() {
|
||||
NtpConfig ntp;
|
||||
if(config.getNtpConfig(ntp)) {
|
||||
tz = resolveTimezone(ntp.timezone);
|
||||
configTime(tz->toLocal(0), tz->toLocal(JULY1970)-JULY1970, ntp.enable ? strlen(ntp.server) > 0 ? ntp.server : (char*) F("pool.ntp.org") : (char*) F("")); // Add NTP server by default if none is configured
|
||||
sntp_servermode_dhcp(ntp.enable && ntp.dhcp ? 1 : 0);
|
||||
ntpEnabled = ntp.enable;
|
||||
ws.setTimezone(tz);
|
||||
ds.setTimezone(tz);
|
||||
ea.setTimezone(tz);
|
||||
@@ -560,12 +557,21 @@ void handleEnergyAccountingChanged() {
|
||||
config.ackEnergyAccountingChange();
|
||||
}
|
||||
|
||||
char ntpServerName[64] = "";
|
||||
|
||||
void handleNtpChange() {
|
||||
NtpConfig ntp;
|
||||
if(config.getNtpConfig(ntp)) {
|
||||
tz = resolveTimezone(ntp.timezone);
|
||||
configTime(tz->toLocal(0), tz->toLocal(JULY1970)-JULY1970, ntp.enable ? strlen(ntp.server) > 0 ? ntp.server : (char*) F("pool.ntp.org") : (char*) F("")); // Add NTP server by default if none is configured
|
||||
sntp_servermode_dhcp(ntp.enable && ntp.dhcp ? 1 : 0);
|
||||
if(ntp.enable && strlen(ntp.server) > 0) {
|
||||
strcpy(ntpServerName, ntp.server);
|
||||
} else if(ntp.enable) {
|
||||
strcpy(ntpServerName, "pool.ntp.org");
|
||||
} else {
|
||||
memset(ntpServerName, 0, 64);
|
||||
}
|
||||
configTime(tz->toLocal(0), tz->toLocal(JULY1970)-JULY1970, ntpServerName, "", "");
|
||||
sntp_servermode_dhcp(ntp.enable && ntp.dhcp ? 1 : 0); // Not implemented on ESP32?
|
||||
ntpEnabled = ntp.enable;
|
||||
|
||||
ws.setTimezone(tz);
|
||||
@@ -704,8 +710,8 @@ void rxerr(int err) {
|
||||
if(err == 0) return;
|
||||
switch(err) {
|
||||
case 1:
|
||||
debugE_P(PSTR("Serial break error"));
|
||||
break;
|
||||
debugD_P(PSTR("Serial break"));
|
||||
return;
|
||||
case 2:
|
||||
debugE_P(PSTR("Serial buffer overflow"));
|
||||
rxBufferErrors++;
|
||||
@@ -720,10 +726,10 @@ void rxerr(int err) {
|
||||
debugE_P(PSTR("Serial FIFO overflow"));
|
||||
break;
|
||||
case 4:
|
||||
debugE_P(PSTR("Serial frame error"));
|
||||
debugW_P(PSTR("Serial frame error"));
|
||||
break;
|
||||
case 5:
|
||||
debugE_P(PSTR("Serial parity error"));
|
||||
debugW_P(PSTR("Serial parity error"));
|
||||
break;
|
||||
}
|
||||
meterState.setLastError(90+err);
|
||||
|
||||
Reference in New Issue
Block a user