diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f1fabea..9975602 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -12,9 +12,10 @@ jobs: - name: Checkout code uses: actions/checkout@v3 - - name: Build with sglahn/platformio-core + - name: Build with PlatformIO (Docker) run: | docker run --rm \ - --mount type=bind,source="$(pwd)",target=/workspace \ - -w /workspace \ + -v "${{ github.workspace }}:/workspace/reptil1990/AquaMasterMQTT" \ + -w /workspace/reptil1990/AquaMasterMQTT \ + -u root \ sglahn/platformio-core:latest run diff --git a/data/ota/firmware.bin b/data/ota/firmware.bin new file mode 100644 index 0000000..ab53524 Binary files /dev/null and b/data/ota/firmware.bin differ diff --git a/platformio.ini b/platformio.ini index f52a88d..514cdc5 100644 --- a/platformio.ini +++ b/platformio.ini @@ -31,6 +31,7 @@ lib_deps = esp32async/AsyncTCP@^3.4.2 mlesniew/PicoMQTT@^1.3.0 miguelbalboa/MFRC522@^1.4.12 + adafruit/RTClib@^2.1.4 [env:wemos_d1_mini32_OTA] board = wemos_d1_mini32 @@ -42,6 +43,7 @@ lib_deps = esp32async/AsyncTCP@^3.4.2 mlesniew/PicoMQTT@^1.3.0 miguelbalboa/MFRC522@^1.4.12 + adafruit/RTClib@^2.1.4 upload_protocol = espota upload_port = 192.168.1.94 @@ -60,6 +62,7 @@ lib_deps = esp32async/AsyncTCP@^3.4.2 mlesniew/PicoMQTT@^1.3.0 miguelbalboa/MFRC522@^1.4.12 + adafruit/RTClib@^2.1.4 [env:esp32thing] board = esp32thing @@ -67,6 +70,8 @@ monitor_speed = 115200 build_flags = -DBOARD_HAS_PSRAM -mfix-esp32-psram-cache-issue +board_upload.flash_size = 16MB +board_build.partitions = default_16MB.csv targets = uploadfs board_build.psram = disabled lib_deps = @@ -76,6 +81,4 @@ lib_deps = esp32async/AsyncTCP@^3.4.2 mlesniew/PicoMQTT@^1.3.0 miguelbalboa/MFRC522@^1.4.12 - - - + adafruit/RTClib@^2.1.4 diff --git a/src/communication.h b/src/communication.h index 76058b0..5b477e4 100644 --- a/src/communication.h +++ b/src/communication.h @@ -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); diff --git a/src/timesync.h b/src/timesync.h index 0e6ab2e..81414fc 100644 --- a/src/timesync.h +++ b/src/timesync.h @@ -5,6 +5,10 @@ #include #include #include +#include +#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()); +} \ No newline at end of file