V 1.6.0 MQTT identifizierung mit 'Bad'
- Datumstexte auf deutsch
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
|
||||
|
||||
27
src/main.cpp
27
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);
|
||||
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);
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
25
src/mqtt.cpp
25
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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user