diff --git a/tools/esp8266/app.cpp b/tools/esp8266/app.cpp index 7c4fa901..f8b99f7b 100644 --- a/tools/esp8266/app.cpp +++ b/tools/esp8266/app.cpp @@ -834,8 +834,10 @@ void app::setupMqtt(void) { if(mMqttActive) { mMqtt.sendMsg("version", mVersion); - if(mMqtt.isConnected()) + if(mMqtt.isConnected()) { mMqtt.sendMsg("device", mSysConfig.deviceName); + mMqtt.sendMsg("uptime", "0"); + } /*char topic[30]; for(uint8_t i = 0; i < MAX_NUM_INVERTERS; i ++) { diff --git a/tools/esp8266/mqtt.h b/tools/esp8266/mqtt.h index 28ca2c1c..1205d772 100644 --- a/tools/esp8266/mqtt.h +++ b/tools/esp8266/mqtt.h @@ -92,11 +92,15 @@ class mqtt { // da ein MQTT_CONNECTION_LOST -3 die Werte zerstört hat. mClient->setServer(mCfg->broker, mCfg->port); mClient->setBufferSize(MQTT_MAX_PACKET_SIZE); + + char lwt[MQTT_TOPIC_LEN + 7 ]; // "/uptime" --> + 7 byte + snprintf(lwt, MQTT_TOPIC_LEN + 7, "%s/uptime", mCfg->topic); + if((strlen(mCfg->user) > 0) && (strlen(mCfg->pwd) > 0)) - resub = mClient->connect(mDevName, mCfg->user, mCfg->pwd); + resub = mClient->connect(mDevName, mCfg->user, mCfg->pwd, lwt, 0, false, "offline"); else - resub = mClient->connect(mDevName); - // ein Subscribe ist nur nach einem connect notwendig + resub = mClient->connect(mDevName, lwt, 0, false, "offline"); + // ein Subscribe ist nur nach einem connect notwendig if(resub) { char topic[MQTT_TOPIC_LEN + 13 ]; // "/devcontrol/#" --> + 6 byte // ToDo: "/devcontrol/#" is hardcoded