From 251c73b517c93bde771b4404a58749fe249c0bed Mon Sep 17 00:00:00 2001 From: rxf Date: Fri, 23 Aug 2024 09:53:56 +0200 Subject: [PATCH] V 1.6.0 MQTT identifizierung mit 'Bad' - Datumstexte auf deutsch --- src/grafik.cpp | 6 ++++++ src/grafik.h | 1 + src/main.cpp | 29 +++++++++++++---------------- src/main.h | 4 ++++ src/mqtt.cpp | 25 +++++++++++-------------- src/mqtt.h | 5 +++-- src/version.h | 12 +++++++++--- 7 files changed, 47 insertions(+), 35 deletions(-) diff --git a/src/grafik.cpp b/src/grafik.cpp index 55194ea..5ea6625 100644 --- a/src/grafik.cpp +++ b/src/grafik.cpp @@ -429,3 +429,9 @@ void showResetTime(struct tm tinfo) { lv_obj_add_style(resdate_label, &style_info_label, LV_PART_MAIN); } +void setDateTime(char *time, char *date) +{ + lv_label_set_text(time_label, time); + lv_label_set_text(date_label, date); +} + diff --git a/src/grafik.h b/src/grafik.h index 1bdbedc..2b3c6fc 100644 --- a/src/grafik.h +++ b/src/grafik.h @@ -68,6 +68,7 @@ void setAussenDataValues(float val, bool what, struct tm t); void showRate(int r); void show2lines(); void showResetTime(struct tm tinfo); +void setDateTime(char *time, char *date); diff --git a/src/main.cpp b/src/main.cpp index 8423f74..f374460 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -40,7 +40,7 @@ BME280Data bmedata; int currentSecond = -1; -void showDateTime(struct tm tinfo); +void updateDateTime(struct tm tinfo); void setBMEreadtime(int time) { bmeReadTime = time * 1000; @@ -50,13 +50,6 @@ void setUpdatetime(int time) { updateTime = time * 1000; } -char * getChipID(void) { - static char chipid[20]; - uint64_t chipid64 = ESP.getEfuseMac(); - sprintf(chipid, "%04X%08X", (uint16_t)(chipid64 >> 32), (uint32_t)chipid64); - return chipid; -} - void setup() { setlocale(LC_ALL, "de_DE"); String LVGL_Arduino = String("LVGL Library Version: ") + lv_version_major() + "." + lv_version_minor() + "." + lv_version_patch(); @@ -87,8 +80,9 @@ void setup() { // Start MQTT setup_mqtt(); + // Get the time timeinfo = gettheTime(NTPREADTIME); - showDateTime(timeinfo); + updateDateTime(timeinfo); bmeReadtimer = millis(); @@ -122,7 +116,7 @@ void setup() { void loop() { timeinfo = gettheTime(NTPREADTIME); if (timeinfo.tm_sec == 0) { // minute over - showDateTime(timeinfo); + updateDateTime(timeinfo); } if (millis() - bmeReadtimer > bmeReadTime) { bmeReadtimer = millis(); @@ -156,11 +150,14 @@ void loop() { delay(5); // let this time pass } -void showDateTime(struct tm tinfo) { +void updateDateTime(struct tm tinfo) { char time[6]; - char date[50]; + static char date[50]; strftime(time, 6, "%H:%M", &tinfo); - strftime(date, 50, "%A, %d %B %Y", &tinfo); - lv_label_set_text(time_label, time); - lv_label_set_text(date_label, date); -} \ No newline at end of file + int wd = tinfo.tm_wday; + int mo = tinfo.tm_mon; + int day = tinfo.tm_mday; + int year = tinfo.tm_year + 1900; + sprintf(date, "%s, %d. %s %d", wday[wd], day, month[mo], year); + setDateTime(time, date); +} diff --git a/src/main.h b/src/main.h index d18ef9a..9b684b2 100644 --- a/src/main.h +++ b/src/main.h @@ -13,12 +13,16 @@ extern "C" { #define MAXREADINGS 200 #ifdef MAIN +const char* wday[] = {"Sonntag", "Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag"}; +const char* month[] = {"Januar", "Februar", "März", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember"}; TimerHandle_t mqttReconnectTimer; TimerHandle_t wifiReconnectTimer; int bmeReadTime = 10000; int updateTime = 30000; struct tm timeinfo; #else +extern const char* wday[7]; +extern const char* month[12]; extern TimerHandle_t mqttReconnectTimer; extern TimerHandle_t wifiReconnectTimer; extern int bmeReadTime; diff --git a/src/mqtt.cpp b/src/mqtt.cpp index 911013d..eb74e20 100644 --- a/src/mqtt.cpp +++ b/src/mqtt.cpp @@ -26,17 +26,17 @@ void onmessage(char *tp, byte *msg, unsigned int length) bool istemp = true; float val = 0.0; - if (topic == "CYD/set/hm/aussen") { - if(doc.containsKey("temperature")) { + if (topic.startsWith("hm/status/Aussen_Temp:1/")) { + struct tm timeinfo = gettheTime(1); + if (topic.endsWith("TEMPERATURE")) { istemp = true; - val = doc["temperature"]; } - if(doc.containsKey("humidity")) { + if (topic.endsWith("HUMIDITY")) { istemp = false; - val = doc["humidity"]; } + val = doc["val"]; setAussenDataValues(val, istemp, timeinfo); - } else if (topic == "CYD/set/parameter") { + } else if (topic == MQTT_TOPIC "set/parameter") { if(doc.containsKey("bmerate")) { setBMEreadtime(doc["bmerate"]); // showRate(doc["bmerate"]); @@ -61,11 +61,10 @@ void reconnect(void) while (!client.connected()) { Serial.print("Reconnecting..."); - char * chipID = getChipID(); - bool erg = client.connect(chipID, MQTT_USER, MQTT_PASSWD); + bool erg = client.connect(CLIENT_ID, MQTT_USER, MQTT_PASSWD); Serial.println(erg); - if (!client.connect(chipID, MQTT_USER, MQTT_PASSWD)) + if (!client.connect(CLIENT_ID, MQTT_USER, MQTT_PASSWD)) { Serial.print("failed, rc="); Serial.print(client.state()); @@ -74,16 +73,14 @@ void reconnect(void) } } Serial.println("Connected"); - client.subscribe(MQTT_TOPIC "#"); + client.subscribe(MQTT_TOPIC "set/parameter"); + client.subscribe("hm/status/Aussen_Temp:1/#"); } void doPublish(float temp, float hum, float tm, float hm) { char payload[80]; sprintf(payload, "{\"temperature\":%.1f,\"tempmess\":%.1f,\"humidity\":%.1f,\"hummess\":%.1f}", temp, tm, hum, hm); - char * chipID = getChipID(); - char topic[50]; - sprintf(topic, "CYD/get/%s/bme280", chipID); - client.publish(topic, payload); + client.publish(MQTT_PUB_TEMP, payload); Serial.printf("Published: %s %s\n", MQTT_PUB_TEMP, payload); } diff --git a/src/mqtt.h b/src/mqtt.h index f5d9e9e..778b6b1 100644 --- a/src/mqtt.h +++ b/src/mqtt.h @@ -12,8 +12,9 @@ #define MQTT_USER "rxf" #define MQTT_PASSWD "Tux4S!ech" -#define MQTT_TOPIC "CYD/set/" -#define MQTT_PUB_TEMP "CYD/get/bme280" +#define CLIENT_ID "Bad" +#define MQTT_TOPIC "CYD/Bad/" +#define MQTT_PUB_TEMP "CYD/Bad/put/bme280" #ifdef MQTT WiFiClient espClient; diff --git a/src/version.h b/src/version.h index 2861140..adde941 100644 --- a/src/version.h +++ b/src/version.h @@ -1,11 +1,17 @@ // Versionsgeschichte -#define VERSION "1.5.2" -#define VDATE "2024-08-21" -#define VTIME "12:15 UTC" +#define VERSION "1.6.0" +#define VDATE "2024-08-23" +#define VTIME "07:45 UTC" /* Version Date Author +1.6.0 2024-08-23 rxf + - MQTT CLINT_ID auf 'Bad' + - MQTT_TOPIC auf 'CYD/Bad/' + - Subcriben von hm/... direkt (nicht mehr über CYD-Topic) + - Datum-Texte auf deutsch + 1.5.2 2024-08-21 rxf - Payloadbuffer für MQTT auf 80 Byte vergrößert - Version-Time zu version.h hinzugefügt und zur Anzeige