Merge branch 'main' of https://git.reptilfpv.de/reptil1990/AquaMasterMQTT
This commit is contained in:
7
.github/workflows/build.yml
vendored
7
.github/workflows/build.yml
vendored
@@ -12,9 +12,10 @@ jobs:
|
|||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
- name: Build with sglahn/platformio-core
|
- name: Build with PlatformIO (Docker)
|
||||||
run: |
|
run: |
|
||||||
docker run --rm \
|
docker run --rm \
|
||||||
--mount type=bind,source="$(pwd)",target=/workspace \
|
-v "${{ github.workspace }}:/workspace/reptil1990/AquaMasterMQTT" \
|
||||||
-w /workspace \
|
-w /workspace/reptil1990/AquaMasterMQTT \
|
||||||
|
-u root \
|
||||||
sglahn/platformio-core:latest run
|
sglahn/platformio-core:latest run
|
||||||
|
|||||||
BIN
data/ota/firmware.bin
Normal file
BIN
data/ota/firmware.bin
Normal file
Binary file not shown.
@@ -31,6 +31,7 @@ lib_deps =
|
|||||||
esp32async/AsyncTCP@^3.4.2
|
esp32async/AsyncTCP@^3.4.2
|
||||||
mlesniew/PicoMQTT@^1.3.0
|
mlesniew/PicoMQTT@^1.3.0
|
||||||
miguelbalboa/MFRC522@^1.4.12
|
miguelbalboa/MFRC522@^1.4.12
|
||||||
|
adafruit/RTClib@^2.1.4
|
||||||
|
|
||||||
[env:wemos_d1_mini32_OTA]
|
[env:wemos_d1_mini32_OTA]
|
||||||
board = wemos_d1_mini32
|
board = wemos_d1_mini32
|
||||||
@@ -42,6 +43,7 @@ lib_deps =
|
|||||||
esp32async/AsyncTCP@^3.4.2
|
esp32async/AsyncTCP@^3.4.2
|
||||||
mlesniew/PicoMQTT@^1.3.0
|
mlesniew/PicoMQTT@^1.3.0
|
||||||
miguelbalboa/MFRC522@^1.4.12
|
miguelbalboa/MFRC522@^1.4.12
|
||||||
|
adafruit/RTClib@^2.1.4
|
||||||
upload_protocol = espota
|
upload_protocol = espota
|
||||||
upload_port = 192.168.1.94
|
upload_port = 192.168.1.94
|
||||||
|
|
||||||
@@ -60,6 +62,7 @@ lib_deps =
|
|||||||
esp32async/AsyncTCP@^3.4.2
|
esp32async/AsyncTCP@^3.4.2
|
||||||
mlesniew/PicoMQTT@^1.3.0
|
mlesniew/PicoMQTT@^1.3.0
|
||||||
miguelbalboa/MFRC522@^1.4.12
|
miguelbalboa/MFRC522@^1.4.12
|
||||||
|
adafruit/RTClib@^2.1.4
|
||||||
|
|
||||||
[env:esp32thing]
|
[env:esp32thing]
|
||||||
board = esp32thing
|
board = esp32thing
|
||||||
@@ -67,6 +70,8 @@ monitor_speed = 115200
|
|||||||
build_flags =
|
build_flags =
|
||||||
-DBOARD_HAS_PSRAM
|
-DBOARD_HAS_PSRAM
|
||||||
-mfix-esp32-psram-cache-issue
|
-mfix-esp32-psram-cache-issue
|
||||||
|
board_upload.flash_size = 16MB
|
||||||
|
board_build.partitions = default_16MB.csv
|
||||||
targets = uploadfs
|
targets = uploadfs
|
||||||
board_build.psram = disabled
|
board_build.psram = disabled
|
||||||
lib_deps =
|
lib_deps =
|
||||||
@@ -76,6 +81,4 @@ lib_deps =
|
|||||||
esp32async/AsyncTCP@^3.4.2
|
esp32async/AsyncTCP@^3.4.2
|
||||||
mlesniew/PicoMQTT@^1.3.0
|
mlesniew/PicoMQTT@^1.3.0
|
||||||
miguelbalboa/MFRC522@^1.4.12
|
miguelbalboa/MFRC522@^1.4.12
|
||||||
|
adafruit/RTClib@^2.1.4
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -54,14 +54,12 @@ void readButtonJSON(const char * topic, const char * payload) {
|
|||||||
// Extract values from JSON
|
// Extract values from JSON
|
||||||
int pressType = doc["type"] | 0;
|
int pressType = doc["type"] | 0;
|
||||||
const char* buttonId = doc["buttonmac"] | "unknown";
|
const char* buttonId = doc["buttonmac"] | "unknown";
|
||||||
const char* messageId = doc["messageId"] | "unknown";
|
|
||||||
uint64_t timestamp = doc["timestamp"] | 0;
|
uint64_t timestamp = doc["timestamp"] | 0;
|
||||||
|
|
||||||
// Print received data
|
// Print received data
|
||||||
Serial.printf("Button Press Received:\n");
|
Serial.printf("Button Press Received:\n");
|
||||||
Serial.printf(" Type: %d\n", pressType);
|
Serial.printf(" Type: %d\n", pressType);
|
||||||
Serial.printf(" Button MAC: %s\n", buttonId);
|
Serial.printf(" Button MAC: %s\n", buttonId);
|
||||||
Serial.printf(" Message ID: %s\n", messageId);
|
|
||||||
Serial.printf(" Timestamp: %llu\n", timestamp);
|
Serial.printf(" Timestamp: %llu\n", timestamp);
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,10 @@
|
|||||||
#include <ArduinoJson.h>
|
#include <ArduinoJson.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
|
#include <Wire.h>
|
||||||
|
#include "RTClib.h"
|
||||||
|
|
||||||
|
RTC_PCF8523 rtc;
|
||||||
|
|
||||||
// Globale Zeitvariablen
|
// Globale Zeitvariablen
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
@@ -12,6 +16,9 @@ struct timezone tz;
|
|||||||
time_t now;
|
time_t now;
|
||||||
struct tm timeinfo;
|
struct tm timeinfo;
|
||||||
|
|
||||||
|
//Prototypen für Zeit-Management-Funktionen
|
||||||
|
void setupRTC();
|
||||||
|
void setRTC(DateTime dt);
|
||||||
void setupTimeAPI(AsyncWebServer& server);
|
void setupTimeAPI(AsyncWebServer& server);
|
||||||
String getCurrentTimeJSON();
|
String getCurrentTimeJSON();
|
||||||
bool setSystemTime(long timestamp);
|
bool setSystemTime(long timestamp);
|
||||||
@@ -49,6 +56,7 @@ bool setSystemTime(long timestamp) {
|
|||||||
|
|
||||||
if (settimeofday(&tv, NULL) == 0) {
|
if (settimeofday(&tv, NULL) == 0) {
|
||||||
Serial.println("Zeit erfolgreich gesetzt: " + String(timestamp));
|
Serial.println("Zeit erfolgreich gesetzt: " + String(timestamp));
|
||||||
|
setRTC(DateTime(timestamp));
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
Serial.println("Fehler beim Setzen der Zeit");
|
Serial.println("Fehler beim Setzen der Zeit");
|
||||||
@@ -58,6 +66,8 @@ bool setSystemTime(long timestamp) {
|
|||||||
|
|
||||||
void setupTimeAPI(AsyncWebServer& server) {
|
void setupTimeAPI(AsyncWebServer& server) {
|
||||||
|
|
||||||
|
setupRTC();
|
||||||
|
|
||||||
// API-Endpunkt: Aktuelle Zeit abrufen
|
// API-Endpunkt: Aktuelle Zeit abrufen
|
||||||
server.on("/api/time", HTTP_GET, [](AsyncWebServerRequest *request){
|
server.on("/api/time", HTTP_GET, [](AsyncWebServerRequest *request){
|
||||||
String response = getCurrentTimeJSON();
|
String response = getCurrentTimeJSON();
|
||||||
@@ -202,3 +212,37 @@ uint64_t getCurrentTimestampMs() {
|
|||||||
gettimeofday(&tv, NULL);
|
gettimeofday(&tv, NULL);
|
||||||
return (uint64_t)tv.tv_sec * 1000LL + (uint64_t)tv.tv_usec / 1000LL;
|
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());
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user