remove about edit spiffs try rtc
This commit is contained in:
@@ -54,14 +54,12 @@ void readButtonJSON(const char * topic, const char * payload) {
|
||||
// Extract values from JSON
|
||||
int pressType = doc["type"] | 0;
|
||||
const char* buttonId = doc["buttonmac"] | "unknown";
|
||||
const char* messageId = doc["messageId"] | "unknown";
|
||||
uint64_t timestamp = doc["timestamp"] | 0;
|
||||
|
||||
// Print received data
|
||||
Serial.printf("Button Press Received:\n");
|
||||
Serial.printf(" Type: %d\n", pressType);
|
||||
Serial.printf(" Button MAC: %s\n", buttonId);
|
||||
Serial.printf(" Message ID: %s\n", messageId);
|
||||
Serial.printf(" Timestamp: %llu\n", timestamp);
|
||||
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
|
||||
#define LED_PIN 13
|
||||
|
||||
|
||||
// Status LED
|
||||
unsigned long lastLedBlink = 0;
|
||||
bool ledState = false;
|
||||
|
||||
@@ -5,6 +5,10 @@
|
||||
#include <ArduinoJson.h>
|
||||
#include <time.h>
|
||||
#include <sys/time.h>
|
||||
#include <Wire.h>
|
||||
#include "RTClib.h"
|
||||
|
||||
RTC_PCF8523 rtc;
|
||||
|
||||
// Globale Zeitvariablen
|
||||
struct timeval tv;
|
||||
@@ -12,6 +16,9 @@ struct timezone tz;
|
||||
time_t now;
|
||||
struct tm timeinfo;
|
||||
|
||||
//Prototypen für Zeit-Management-Funktionen
|
||||
void setupRTC();
|
||||
void setRTC(DateTime dt);
|
||||
void setupTimeAPI(AsyncWebServer& server);
|
||||
String getCurrentTimeJSON();
|
||||
bool setSystemTime(long timestamp);
|
||||
@@ -49,6 +56,7 @@ bool setSystemTime(long timestamp) {
|
||||
|
||||
if (settimeofday(&tv, NULL) == 0) {
|
||||
Serial.println("Zeit erfolgreich gesetzt: " + String(timestamp));
|
||||
setRTC(DateTime(timestamp));
|
||||
return true;
|
||||
} else {
|
||||
Serial.println("Fehler beim Setzen der Zeit");
|
||||
@@ -58,6 +66,8 @@ bool setSystemTime(long timestamp) {
|
||||
|
||||
void setupTimeAPI(AsyncWebServer& server) {
|
||||
|
||||
setupRTC();
|
||||
|
||||
// API-Endpunkt: Aktuelle Zeit abrufen
|
||||
server.on("/api/time", HTTP_GET, [](AsyncWebServerRequest *request){
|
||||
String response = getCurrentTimeJSON();
|
||||
@@ -202,3 +212,37 @@ uint64_t getCurrentTimestampMs() {
|
||||
gettimeofday(&tv, NULL);
|
||||
return (uint64_t)tv.tv_sec * 1000LL + (uint64_t)tv.tv_usec / 1000LL;
|
||||
}
|
||||
|
||||
void setupRTC() {
|
||||
|
||||
Wire.begin();
|
||||
|
||||
Serial.println("Initialisiere RTC...");
|
||||
// Versuche RTC mit Wire zu initialisieren
|
||||
if (!rtc.begin()) { // Versuche RTC zu initialisieren, Timeout nach 10 Sekunden
|
||||
Serial.println("RTC nicht gefunden! Versuche erneut...");
|
||||
}
|
||||
|
||||
if (!rtc.initialized()) {
|
||||
Serial.println("RTC nicht initialisiert, versuche Initialisierung...");
|
||||
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
|
||||
} else {
|
||||
Serial.println("RTC bereits initialisiert.");
|
||||
}
|
||||
|
||||
rtc.adjust(DateTime(F(__DATE__), F(__TIME__))); // Setze die RTC auf die Kompilierungszeit
|
||||
Serial.println("RTC initialisiert.");
|
||||
// Aktuelle Zeit vom RTC abrufen
|
||||
DateTime now = rtc.now();
|
||||
Serial.printf("Aktuelle RTC-Zeit: %04d-%02d-%02d %02d:%02d:%02d\n",
|
||||
now.year(), now.month(), now.day(), now.hour(), now.minute(), now.second());
|
||||
rtc.start(); // RTC starten, falls gestoppt
|
||||
}
|
||||
|
||||
// Funktion zum Setzen der RTC-Zeit
|
||||
void setRTC(DateTime dt) {
|
||||
rtc.adjust(dt);
|
||||
DateTime newtime = rtc.now();
|
||||
Serial.printf("RTC-Zeit gesetzt: %04d-%02d-%02d %02d:%02d:%02d\n",
|
||||
newtime.year(), newtime.month(), newtime.day(), newtime.hour(), newtime.minute(), newtime.second());
|
||||
}
|
||||
@@ -19,11 +19,7 @@ void setupWifi() {
|
||||
|
||||
uniqueSSID = getUniqueSSID();
|
||||
ssidAP = uniqueSSID.c_str();
|
||||
//print station SSID
|
||||
Serial.println("Access Point SSID: " + String(ssidSTA));
|
||||
Serial.println("Access Point PW: " + String(passwordSTA));
|
||||
|
||||
if (ssidSTA == nullptr || passwordSTA == nullptr || String(ssidSTA).isEmpty() || String(passwordSTA).isEmpty() ) {
|
||||
if (ssidSTA == nullptr || passwordSTA == nullptr || String(ssidSTA).isEmpty() || String(passwordSTA).isEmpty() ) {
|
||||
Serial.println("Fehler: ssidSTA oder passwordSTA ist null!");
|
||||
WiFi.mode(WIFI_MODE_AP);
|
||||
WiFi.softAP(ssidAP, passwordAP);
|
||||
|
||||
Reference in New Issue
Block a user