diff --git a/CYD_Bad.tgz b/CYD_Bad.tgz new file mode 100644 index 0000000..a0db5dc Binary files /dev/null and b/CYD_Bad.tgz differ diff --git a/platformio.ini b/platformio.ini index daf1577..7ac175b 100644 --- a/platformio.ini +++ b/platformio.ini @@ -12,12 +12,12 @@ platform = espressif32 board = esp32dev framework = arduino +lib_compat_mode = strict lib_deps = - https://github.com/me-no-dev/AsyncTCP/archive/refs/heads/master.zip - https://github.com/marvinroger/async-mqtt-client/archive/refs/heads/develop.zip bblanchon/ArduinoJson@^7.1.0 adafruit/Adafruit BME280 Library@^2.2.4 lvgl/lvgl@^9.1.0 bodmer/TFT_eSPI@^2.5.43 knolleary/PubSubClient@^2.8 + ayushsharma82/ElegantOTA@^3.1.5 monitor_speed = 115200 diff --git a/src/main.cpp b/src/main.cpp index aeee265..7976621 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -22,7 +22,7 @@ #include -#include "Weifi.h" +#include "weifi.h" #include "mqtt.h" #include "handlebme280.h" #include "grafik.h" @@ -49,6 +49,13 @@ 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(); @@ -107,7 +114,7 @@ void loop() { if (millis() - bmeReadtimer > bmeReadTime) { bmeReadtimer = millis(); bmedata = readBME280(); - doPublish(bmedata.temp+arcTemp.value_offset, bmedata.hum+arcHum.value_offset); + doPublish(bmedata.temp+arcTemp.value_offset, bmedata.hum+arcHum.value_offset, bmedata.temp, bmedata.hum); } if (millis() - updatetimer > updateTime) { updatetimer = millis(); @@ -122,6 +129,10 @@ void loop() { } client.loop(); + + server.handleClient(); + ElegantOTA.loop(); + lv_task_handler(); // let the GUI do its work lv_tick_inc(5); // tell LVGL how much time has passed delay(5); // let this time pass diff --git a/src/main.h b/src/main.h index 19aeceb..9fc69c2 100644 --- a/src/main.h +++ b/src/main.h @@ -27,6 +27,7 @@ extern struct tm timeinfo; #endif void setBMEreadtime(int time); +char * getChipID(void); #endif diff --git a/src/mqtt.cpp b/src/mqtt.cpp index 7a78954..ee94ab8 100644 --- a/src/mqtt.cpp +++ b/src/mqtt.cpp @@ -75,11 +75,13 @@ void reconnect(void) client.subscribe(MQTT_TOPIC "#"); } -void doPublish(float temp, float hum) { +void doPublish(float temp, float hum, float tm, float hm) { char payload[50]; - sprintf(payload, "{\"temperature\":%.1f,\"humidity\":%.1f}", temp, hum); - - client.publish(MQTT_PUB_TEMP, payload); + sprintf(payload, "{\"temperature\":%.1f,\"tempmess\":%.1f,\"humidity\":%.1f,\"hummess\":%.1f}", temp, hum, tm, hm); + char * chipID = getChipID(); + char topic[50]; + sprintf(topic, "CYD/get/%s/bme280", chipID); + client.publish(topic, payload); Serial.printf("Published: %s %s\n", MQTT_PUB_TEMP, payload); } diff --git a/src/mqtt.h b/src/mqtt.h index c986658..1c63abc 100644 --- a/src/mqtt.h +++ b/src/mqtt.h @@ -26,6 +26,6 @@ extern PubSubClient client; void reconnect(void); -void doPublish(float temp, float hum); +void doPublish(float temp, float hum, float tm, float hm); void checkMQTT(void); void setup_mqtt(void); \ No newline at end of file diff --git a/src/weifi.cpp b/src/weifi.cpp index a37b192..0d8cdea 100644 --- a/src/weifi.cpp +++ b/src/weifi.cpp @@ -4,6 +4,7 @@ #include "mqtt.h" #include "main.h" + struct tm gettheTime(int repeat) { if(!getLocalTime(&timeinfo)){ Serial.println("Failed to obtain time"); @@ -56,9 +57,19 @@ void connectToWifi() { configTime(gmtOffset_sec, daylightOffset_sec, ntpServer); printLocalTime(); + + server.on("/", []() { + server.send(200, "text/plain", "Hi! This is ElegantOTA Demo."); + }); + + ElegantOTA.begin(&server); // Start ElegantOTA + server.begin(); + Serial.println("HTTP server started"); } + + /* void WiFiEvent(WiFiEvent_t event) { Serial.printf("[WiFi-event] event: %d\n", event); diff --git a/src/weifi.h b/src/weifi.h index c65eb12..0ef611c 100644 --- a/src/weifi.h +++ b/src/weifi.h @@ -2,6 +2,11 @@ #define WEIFI_H #include +#include +#include + +#include + #include "time.h" #include "config.h" @@ -14,6 +19,11 @@ const char *ntpServer = "pool.ntp.org"; const long gmtOffset_sec = 3600; const int daylightOffset_sec = 3600; +WebServer server(80); + +#else +extern WebServer server; + #endif