V 1.6.0 MQTT identifizierung mit 'Bad'

- Datumstexte auf deutsch
This commit is contained in:
rxf
2024-08-23 09:53:56 +02:00
parent c57572262f
commit 251c73b517
7 changed files with 47 additions and 35 deletions

View File

@@ -429,3 +429,9 @@ void showResetTime(struct tm tinfo) {
lv_obj_add_style(resdate_label, &style_info_label, LV_PART_MAIN); 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);
}

View File

@@ -68,6 +68,7 @@ void setAussenDataValues(float val, bool what, struct tm t);
void showRate(int r); void showRate(int r);
void show2lines(); void show2lines();
void showResetTime(struct tm tinfo); void showResetTime(struct tm tinfo);
void setDateTime(char *time, char *date);

View File

@@ -40,7 +40,7 @@ BME280Data bmedata;
int currentSecond = -1; int currentSecond = -1;
void showDateTime(struct tm tinfo); void updateDateTime(struct tm tinfo);
void setBMEreadtime(int time) { void setBMEreadtime(int time) {
bmeReadTime = time * 1000; bmeReadTime = time * 1000;
@@ -50,13 +50,6 @@ void setUpdatetime(int time) {
updateTime = time * 1000; 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() { void setup() {
setlocale(LC_ALL, "de_DE"); setlocale(LC_ALL, "de_DE");
String LVGL_Arduino = String("LVGL Library Version: ") + lv_version_major() + "." + lv_version_minor() + "." + lv_version_patch(); String LVGL_Arduino = String("LVGL Library Version: ") + lv_version_major() + "." + lv_version_minor() + "." + lv_version_patch();
@@ -87,8 +80,9 @@ void setup() {
// Start MQTT // Start MQTT
setup_mqtt(); setup_mqtt();
// Get the time
timeinfo = gettheTime(NTPREADTIME); timeinfo = gettheTime(NTPREADTIME);
showDateTime(timeinfo); updateDateTime(timeinfo);
bmeReadtimer = millis(); bmeReadtimer = millis();
@@ -122,7 +116,7 @@ void setup() {
void loop() { void loop() {
timeinfo = gettheTime(NTPREADTIME); timeinfo = gettheTime(NTPREADTIME);
if (timeinfo.tm_sec == 0) { // minute over if (timeinfo.tm_sec == 0) { // minute over
showDateTime(timeinfo); updateDateTime(timeinfo);
} }
if (millis() - bmeReadtimer > bmeReadTime) { if (millis() - bmeReadtimer > bmeReadTime) {
bmeReadtimer = millis(); bmeReadtimer = millis();
@@ -156,11 +150,14 @@ void loop() {
delay(5); // let this time pass delay(5); // let this time pass
} }
void showDateTime(struct tm tinfo) { void updateDateTime(struct tm tinfo) {
char time[6]; char time[6];
char date[50]; static char date[50];
strftime(time, 6, "%H:%M", &tinfo); strftime(time, 6, "%H:%M", &tinfo);
strftime(date, 50, "%A, %d %B %Y", &tinfo); int wd = tinfo.tm_wday;
lv_label_set_text(time_label, time); int mo = tinfo.tm_mon;
lv_label_set_text(date_label, date); 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);
} }

View File

@@ -13,12 +13,16 @@ extern "C" {
#define MAXREADINGS 200 #define MAXREADINGS 200
#ifdef MAIN #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 mqttReconnectTimer;
TimerHandle_t wifiReconnectTimer; TimerHandle_t wifiReconnectTimer;
int bmeReadTime = 10000; int bmeReadTime = 10000;
int updateTime = 30000; int updateTime = 30000;
struct tm timeinfo; struct tm timeinfo;
#else #else
extern const char* wday[7];
extern const char* month[12];
extern TimerHandle_t mqttReconnectTimer; extern TimerHandle_t mqttReconnectTimer;
extern TimerHandle_t wifiReconnectTimer; extern TimerHandle_t wifiReconnectTimer;
extern int bmeReadTime; extern int bmeReadTime;

View File

@@ -26,17 +26,17 @@ void onmessage(char *tp, byte *msg, unsigned int length)
bool istemp = true; bool istemp = true;
float val = 0.0; float val = 0.0;
if (topic == "CYD/set/hm/aussen") { if (topic.startsWith("hm/status/Aussen_Temp:1/")) {
if(doc.containsKey("temperature")) { struct tm timeinfo = gettheTime(1);
if (topic.endsWith("TEMPERATURE")) {
istemp = true; istemp = true;
val = doc["temperature"];
} }
if(doc.containsKey("humidity")) { if (topic.endsWith("HUMIDITY")) {
istemp = false; istemp = false;
val = doc["humidity"];
} }
val = doc["val"];
setAussenDataValues(val, istemp, timeinfo); setAussenDataValues(val, istemp, timeinfo);
} else if (topic == "CYD/set/parameter") { } else if (topic == MQTT_TOPIC "set/parameter") {
if(doc.containsKey("bmerate")) { if(doc.containsKey("bmerate")) {
setBMEreadtime(doc["bmerate"]); setBMEreadtime(doc["bmerate"]);
// showRate(doc["bmerate"]); // showRate(doc["bmerate"]);
@@ -61,11 +61,10 @@ void reconnect(void)
while (!client.connected()) while (!client.connected())
{ {
Serial.print("Reconnecting..."); Serial.print("Reconnecting...");
char * chipID = getChipID(); bool erg = client.connect(CLIENT_ID, MQTT_USER, MQTT_PASSWD);
bool erg = client.connect(chipID, MQTT_USER, MQTT_PASSWD);
Serial.println(erg); 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("failed, rc=");
Serial.print(client.state()); Serial.print(client.state());
@@ -74,16 +73,14 @@ void reconnect(void)
} }
} }
Serial.println("Connected"); 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) { void doPublish(float temp, float hum, float tm, float hm) {
char payload[80]; char payload[80];
sprintf(payload, "{\"temperature\":%.1f,\"tempmess\":%.1f,\"humidity\":%.1f,\"hummess\":%.1f}", temp, tm, hum, hm); sprintf(payload, "{\"temperature\":%.1f,\"tempmess\":%.1f,\"humidity\":%.1f,\"hummess\":%.1f}", temp, tm, hum, hm);
char * chipID = getChipID(); client.publish(MQTT_PUB_TEMP, payload);
char topic[50];
sprintf(topic, "CYD/get/%s/bme280", chipID);
client.publish(topic, payload);
Serial.printf("Published: %s %s\n", MQTT_PUB_TEMP, payload); Serial.printf("Published: %s %s\n", MQTT_PUB_TEMP, payload);
} }

View File

@@ -12,8 +12,9 @@
#define MQTT_USER "rxf" #define MQTT_USER "rxf"
#define MQTT_PASSWD "Tux4S!ech" #define MQTT_PASSWD "Tux4S!ech"
#define MQTT_TOPIC "CYD/set/" #define CLIENT_ID "Bad"
#define MQTT_PUB_TEMP "CYD/get/bme280" #define MQTT_TOPIC "CYD/Bad/"
#define MQTT_PUB_TEMP "CYD/Bad/put/bme280"
#ifdef MQTT #ifdef MQTT
WiFiClient espClient; WiFiClient espClient;

View File

@@ -1,11 +1,17 @@
// Versionsgeschichte // Versionsgeschichte
#define VERSION "1.5.2" #define VERSION "1.6.0"
#define VDATE "2024-08-21" #define VDATE "2024-08-23"
#define VTIME "12:15 UTC" #define VTIME "07:45 UTC"
/* /*
Version Date Author 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 1.5.2 2024-08-21 rxf
- Payloadbuffer für MQTT auf 80 Byte vergrößert - Payloadbuffer für MQTT auf 80 Byte vergrößert
- Version-Time zu version.h hinzugefügt und zur Anzeige - Version-Time zu version.h hinzugefügt und zur Anzeige