1
mirror of https://github.com/rvdbreemen/OTGW-firmware synced 2024-11-16 04:33:49 +01:00

using native configTime and some

This commit is contained in:
Robert van den Breemen 2021-10-19 20:52:13 +02:00
parent 99dd7178bc
commit 8170a7b4bc
4 changed files with 19 additions and 12 deletions

View File

@ -11,8 +11,10 @@
#include <Arduino.h>
//#include <ezTime.h> // https://github.com/ropg/ezTime
#include <AceTime.h>
#include <TimeLib.h>
#include <TelnetStream.h> // https://github.com/jandrassy/TelnetStream/commit/1294a9ee5cc9b1f7e51005091e351d60c8cddecf
#include <ArduinoJson.h> // https://arduinojson.org/
#include "Wire.h"

View File

@ -196,6 +196,7 @@ if (!settingNTPenable) return;
case TIME_NOTSET:
case TIME_NEEDSYNC:
NtpLastSync = time(nullptr); //remember last sync
DebugTln("Start time syncing");
startNTP();
NtpStatus = TIME_WAITFORSYNC;
break;
@ -203,21 +204,25 @@ if (!settingNTPenable) return;
if ((time(nullptr)>0) || (time(nullptr) >= NtpLastSync)) {
NtpLastSync = time(nullptr); //remember last sync
DebugTf("Timezone lookup for [%s]\r\n", CSTR(settingNTPtimezone));
auto myTz = manager.createForZoneName(CSTR(settingNTPtimezone));
if (myTz.isError()){
DebugTf("Error: Timezone Invalid/Not Found: [%s]", CSTR(settingNTPtimezone));
DebugTf("Error: Timezone Invalid/Not Found: [%s]\r\n", CSTR(settingNTPtimezone));
settingNTPtimezone = NTP_DEFAULT_TIMEZONE;
myTz = manager.createForZoneName(CSTR(settingNTPtimezone)); //try with default Timezone instead
}
} else DebugTln("Timezone lookup: successful");
auto myTime = ZonedDateTime::forUnixSeconds(NtpLastSync, myTz);
setTime(myTime.hour(), myTime.minute(), myTime.second(), myTime.day(), myTime.month(), myTime.year());
NtpStatus = TIME_SYNC;
DebugTln("Time synced!");
}
break;
case TIME_SYNC:
if ((time(nullptr)-NtpLastSync) > NTP_RESYNC_TIME){
//when xx seconds have passed, resync using NTP
DebugTln("Time resync needed");
NtpStatus = TIME_NEEDSYNC;
}
break;

View File

@ -207,7 +207,7 @@ void updateSetting(const char *field, const char *newValue)
if (stricmp(field, "NTPenable")==0) settingNTPenable = EVALBOOLEAN(newValue);
if (stricmp(field, "NTPhostname")==0) {
settingNTPhostname = String(newValue);
startNTP();
startNTP();
}
if (stricmp(field, "NTPtimezone")==0) {
settingNTPtimezone = String(newValue);

View File

@ -2,15 +2,15 @@
#define _VERSION_MAJOR 0
#define _VERSION_MINOR 8
#define _VERSION_PATCH 7
#define _VERSION_BUILD 1120
#define _VERSION_GITHASH "45b51f2"
#define _VERSION_BUILD 1127
#define _VERSION_GITHASH "99dd717"
#define _VERSION_PRERELEASE beta
#define _VERSION_DATE "16-10-2021"
#define _VERSION_TIME "21:12:55"
#define _VERSION_DATE "19-10-2021"
#define _VERSION_TIME "20:49:31"
#define _SEMVER_CORE "0.8.7"
#define _SEMVER_BUILD "0.8.7+1120"
#define _SEMVER_GITHASH "0.8.7+45b51f2"
#define _SEMVER_FULL "0.8.7-beta+45b51f2"
#define _SEMVER_NOBUILD "0.8.7-beta (16-10-2021)"
#define _VERSION "0.8.7-beta+45b51f2 (16-10-2021)"
#define _SEMVER_BUILD "0.8.7+1127"
#define _SEMVER_GITHASH "0.8.7+99dd717"
#define _SEMVER_FULL "0.8.7-beta+99dd717"
#define _SEMVER_NOBUILD "0.8.7-beta (19-10-2021)"
#define _VERSION "0.8.7-beta+99dd717 (19-10-2021)"
//The version information is created automatically, more information here: https://github.com/rvdbreemen/autoinc-semver