This commit is contained in:
Michal Courson
2025-08-28 21:35:21 -04:00
commit 82dde89d80
23 changed files with 6801 additions and 0 deletions

37
main/TimeSync.hpp Normal file
View File

@ -0,0 +1,37 @@
#ifndef TIMESYNC_HPP
#define TIMESYNC_HPP
#include <sys/time.h>
#include "Arduino.h"
#include "WiFi.h"
#include "time.h"
class TimeSync {
public:
static void Sync() {
const char* ssid = "ConnectonRefused";
const char* password = "retryconnection";
const char* ntpServer = "pool.ntp.org";
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected.");
configTime(0, 0, ntpServer);
delay(2000);
WiFi.disconnect();
}
static uint64_t GetTime() {
struct timeval tv;
gettimeofday(&tv, NULL); // gets time in seconds and microseconds
uint64_t epochMillis = (uint64_t)tv.tv_sec * 1000 + (tv.tv_usec / 1000);
return epochMillis;
}
};
#endif