mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-26 22:22:16 +03:00
time
This commit is contained in:
@@ -3,7 +3,7 @@
|
|||||||
#include "Utils/TimeUtils.h"
|
#include "Utils/TimeUtils.h"
|
||||||
#include "Utils/PrintMessage.h"
|
#include "Utils/PrintMessage.h"
|
||||||
|
|
||||||
#include "time.h"
|
#include "TZ.h"
|
||||||
|
|
||||||
class Clock {
|
class Clock {
|
||||||
const char* MODULE = "Clock";
|
const char* MODULE = "Clock";
|
||||||
@@ -19,9 +19,7 @@ class Clock {
|
|||||||
return _hasSynced;
|
return _hasSynced;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void setNtpPool(String ntp) {
|
||||||
|
|
||||||
setNtpPool(String ntp) {
|
|
||||||
_ntp = ntp;
|
_ntp = ntp;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -29,15 +27,6 @@ class Clock {
|
|||||||
_timezone = timezone;
|
_timezone = timezone;
|
||||||
}
|
}
|
||||||
|
|
||||||
time_t getSystemTime() {
|
|
||||||
timeval tv{0, 0};
|
|
||||||
timezone tz = getTimeZone(getBiasInMinutes());
|
|
||||||
time_t epoch = 0;
|
|
||||||
if (gettimeofday(&tv, &tz) != -1)
|
|
||||||
epoch = tv.tv_sec;
|
|
||||||
return epoch;
|
|
||||||
}
|
|
||||||
|
|
||||||
void startSync() {
|
void startSync() {
|
||||||
if (!_configured) {
|
if (!_configured) {
|
||||||
pm.info("sync to: " + _ntp + " time zone: " + String(_timezone));
|
pm.info("sync to: " + _ntp + " time zone: " + String(_timezone));
|
||||||
@@ -73,10 +62,20 @@ class Clock {
|
|||||||
// delay(1000);
|
// delay(1000);
|
||||||
// }
|
// }
|
||||||
// #endif
|
// #endif
|
||||||
private:
|
|
||||||
bool hasTimeSynced() {
|
bool hasTimeSynced() {
|
||||||
unsigned long now = time(nullptr);
|
int uptime = millis() / 1000;
|
||||||
return now > millis();
|
return getSystemTime() > uptime;
|
||||||
|
}
|
||||||
|
|
||||||
|
time_t getSystemTime() {
|
||||||
|
timeval tv{0, 0};
|
||||||
|
timezone tz = getTimeZone(getBiasInMinutes());
|
||||||
|
time_t epoch = 0;
|
||||||
|
if (gettimeofday(&tv, &tz) != -1) {
|
||||||
|
epoch = tv.tv_sec;
|
||||||
|
}
|
||||||
|
return epoch + getBiasInSeconds();
|
||||||
}
|
}
|
||||||
|
|
||||||
int getBiasInSeconds() {
|
int getBiasInSeconds() {
|
||||||
|
|||||||
Reference in New Issue
Block a user