non working WIP changes to include more MQTT messages

This commit is contained in:
2025-04-23 13:23:07 +02:00
parent 686fd421a5
commit f74fde8d82
23 changed files with 45933 additions and 50 deletions
+26 -8
View File
@@ -1,6 +1,7 @@
#include "MQTT.h"
char MQTT::ntpServer[40] = "nas.local";
WebServer MQTT::server = WebServer(80);
@@ -11,6 +12,7 @@ WiFiManagerParameter custom_mqtt_port("port", "mqtt port", "",6);
WiFiManagerParameter custom_mqtt_topic("topic", "topic", "", 40);
WiFiManagerParameter custom_deftemp("deftemp", "Default Temperature", "", 6);
WiFiManagerParameter custom_enbuff("enBuff", "Enable heatBuffer", "", 6);
WiFiManagerParameter custom_ntpServer("ntpServer", "NTP Server", "", 40);
MQTT::MQTT(){
@@ -73,17 +75,28 @@ void MQTT::serveData(void){
void MQTT::sendStatus(void){
char buffer[10];
tm timeinfo;
char buffer[35];
publish_sub("hostname", hostname);
publish_sub("IP", myIP);
publish_sub("NTP-Server", ntpServer);
if(!getLocalTime(&timeinfo)){
strcpy(buffer, "00-00-0000T00:00:00+0000");
}else{
strftime(buffer, sizeof(buffer), "%FT%T%z", &timeinfo);
}
publish_sub("timestamp",buffer,true);
snprintf(buffer, sizeof buffer, "%0.1f", glblData.temp);
publish_sub("Temp[degC]",buffer);
publish_sub("Temp[degC]",buffer,true);
snprintf(buffer, sizeof buffer, "%0.0f", glblData.seaLevelPress);
publish_sub("pressure[hPa]",buffer);
publish_sub("pressure[hPa]",buffer,true);
snprintf(buffer, sizeof buffer, "%0.0f", glblData.hum);
publish_sub("rHum[%]",buffer);
publish_sub("rHum[%]",buffer,true);
snprintf(buffer, sizeof buffer, "%s", digitalRead(PIN_REL)?"true":"false");
publish_sub("Heating",buffer);
publish_sub("Heating",buffer,true);
snprintf(buffer, sizeof buffer, "%0.1f", glblData.settemp);
publish_sub("Set Temp[degC]",buffer);
publish_sub("Set Temp[degC]",buffer,true);
}
@@ -96,6 +109,7 @@ void MQTT::begin(){
prefs.getString("MQTT_TOPIC",mqtt_topic,40);
defTemp = prefs.getFloat("DEF_TMP",defTemp);
enBuff = prefs.getBool("EN_OVR",enBuff);
prefs.getString("NTP_SERVER",ntpServer,40);
glblData.enBuff = enBuff;
ui_settemp(defTemp);
prefs.end();
@@ -106,12 +120,14 @@ void MQTT::begin(){
custom_mqtt_topic.setValue(mqtt_topic,40);
custom_deftemp.setValue(String(defTemp).c_str(),6);
custom_enbuff.setValue(String(enBuff).c_str(),6);
custom_ntpServer.setValue(String(ntpServer).c_str(),40);
wm.addParameter(&custom_hostname);
wm.addParameter(&custom_mqtt_server);
wm.addParameter(&custom_mqtt_port);
wm.addParameter(&custom_mqtt_topic);
wm.addParameter(&custom_deftemp);
wm.addParameter(&custom_enbuff);
wm.addParameter(&custom_ntpServer);
psclient.setClient(client);
psclient.setServer(mqtt_server,mqtt_port);
WiFi.setHostname(custom_hostname.getValue()); //define hostname
@@ -183,6 +199,7 @@ void MQTT::saveConfigToFlash(void){
mqtt_port = atoi(custom_mqtt_port.getValue());
strcpy(hostname,custom_hostname.getValue());
strcpy(mqtt_topic,custom_mqtt_topic.getValue());
strcpy(ntpServer,custom_ntpServer.getValue());
defTemp = atof(custom_deftemp.getValue());
if(custom_enbuff.getValue() != "0"){
enBuff = true;
@@ -195,6 +212,7 @@ void MQTT::saveConfigToFlash(void){
prefs.putString("MQTT_TOPIC",mqtt_topic);
prefs.putFloat("DEF_TMP",defTemp);
prefs.putBool("EN_OVR",enBuff);
prefs.putString("NTP_SERVER",ntpServer);
prefs.end();
}
@@ -278,10 +296,10 @@ void MQTT::publish(const char* msg, unsigned int len){
void MQTT::publish(const char* msg, bool retained){
psclient.publish(mqtt_topic,msg,retained);
}
void MQTT::publish_sub(const char* subtopic, const char* msg){
void MQTT::publish_sub(const char* subtopic, const char* msg, bool retained){
char newtopic[60];
strcpy(newtopic,mqtt_topic);
strcat(newtopic,"/");
strcat(newtopic,subtopic);
psclient.publish(newtopic,msg);
psclient.publish(newtopic,msg, retained);
}
+2 -1
View File
@@ -40,7 +40,7 @@ public:
void publish(const char* msg, unsigned int len);
void publish(const char* msg, bool retained);
void publish(const char* msg, unsigned int len, bool retained);
void publish_sub(const char* subtopic, const char* msg);
void publish_sub(const char* subtopic, const char* msg, bool retained=false);
private:
static void serveData(void);
@@ -51,6 +51,7 @@ private:
int mqtt_port = 1883;
float defTemp = 0.0;
bool enBuff = false;
static char ntpServer[40];
char hostname[40] = "TMP_WoZi-EG";
char mqtt_topic[40] = "Raumtemp/EG/Wohnzimmer";
void saveConfigToFlash(void);
+2 -1
View File
@@ -100,9 +100,10 @@ void setup(void)
{
DisplayInit();
pinMode(PIN_REL,OUTPUT);
Serial.begin(115200);
lv_init();
WiFi.setSleep(WIFI_PS_MIN_MODEM);
//WiFi.setSleep(WIFI_PS_MIN_MODEM);
lv_log_register_print_cb(log_print);
TouchInit();
bme.begin();
+1 -1
View File
@@ -7,7 +7,7 @@
extern "C" {
#endif
#define PIN_REL 21
#define PIN_REL 20
typedef enum override_e{
OVR_NONE,
+1 -1
View File
@@ -2,7 +2,7 @@
#define EEZ_LVGL_UI_SCREENS_H
#include <lvgl.h>
#include <ui/symbols.h>
#ifdef __cplusplus
extern "C" {
#endif
+5 -4
View File
@@ -3,19 +3,20 @@
*
*/
#ifndef LV_SYMBOL_DEF_H
#define LV_SYMBOL_DEF_H
#ifndef SYMBOLS_H
#define SYMBOLS_H
#ifdef __cplusplus
extern "C" {
#endif
LV_FONT_DECLARE(Bootstrap_Icons_16);
LV_FONT_DECLARE(Bootstrap_Icons_18);
//included icons in bootstrap font
//use this list for font generator:
/*
0xF619-0xF61C,0xF7F6,0xF4FF,0xF185-0xF188,0xF30B-0xF30D,0xF493,0xF4F7,0xF5CD-0xF5D20xF100,
0xF619-0xF61C,0xF7F6,0xF4FF,0xF185-0xF188,0xF30B-0xF30D,0xF493,0xF4F7,
0xF5CD-0xF5D2,0xF100,0xF479,0xF5D4,0xF5D3,0xF116,0xF117,0xF3F2,0xF229,0xF22C,0xF235,0xF238,0xF22D,0xF230,0xF231,0xF234
*/
#define ICON_WIFI_LOW "\xEF\x98\x99" //F619
-24
View File
@@ -25,30 +25,6 @@
#define SCREEN_WIDTH 240
#define SCREEN_HEIGHT 240
LV_FONT_DECLARE(Bootstrap_Icons_18);
#define ICON_WIFI_LOW "\xEF\x98\x99" //F619
#define ICON_WIFI_MED "\xEF\x98\x9A" //F61A
#define ICON_WIFI_HIGH "\xEF\x98\x9C" //F61C
#define ICON_WIFI_OFF "\xEF\x98\x9B" //F61B
#define ICON_FIRE "\xEF\x9F\xB6" //F7F6
#define ICON_POWER "\xEF\x93\xBF" //F4FF
#define ICON_BATT_CHARG "\xEF\x86\x85" //F185
#define ICON_BATT_FULL "\xEF\x86\x86" //F186
#define ICON_BATT_HALF "\xEF\x86\x87" //F187
#define ICON_BATT "\xEF\x86\x88" //F188
#define ICON_DROPLET_FULL "\xEF\x8C\x8B" //F30B
#define ICON_DROPLET_HALF "\xEF\x8C\x8C" //F30C
#define ICON_DROPLET "\xEF\x8C\x8D" //F30D
#define ICON_MOISTURE "\xEF\x92\x93" //F493
#define ICON_PLUG "\xEF\x93\xB7" //F4F7
#define ICON_THERMOMETER_HALF "\xEF\x97\x8D" //F5CD
#define ICON_THERMOMETER_HIGH "\xEF\x97\x8E" //F5CE
#define ICON_THERMOMETER_LOW "\xEF\x97\x8F" //F5CF
#define ICON_THERMOMETER_SNOW "\xEF\x97\x90" //F5D0
#define ICON_THERMOMETER_SUN "\xEF\x97\x91" //F5D1
#define ICON_THERMOMETER "\xEF\x97\x92" //F5D2
#if defined(EEZ_FOR_LVGL)
#include <eez/flow/lvgl_api.h>
#endif