From fbb5fe3385938c0a43cfa2737d03d96c57a35fc4 Mon Sep 17 00:00:00 2001 From: ohAnd <15704728+ohAnd@users.noreply.github.com> Date: Wed, 9 Oct 2024 09:26:53 +0200 Subject: [PATCH] imrpovements for monitor mode + implementing Im Status "try reconnect" wird die "cloud pause" nicht eingehalten (v1.9.0049) #54 --- include/Config.h | 4 +- include/dtuInterface.h | 7 +- include/mqttHandler.h | 1 + include/version.h | 6 +- include/version.json | 8 +- readme.md | 21 ++-- src/Config.cpp | 4 + src/displayTFT.cpp | 46 ++++++--- src/dtuGateway.ino | 10 +- src/dtuInterface.cpp | 213 ++++++++++++++++++++++++----------------- src/mqttHandler.cpp | 9 ++ 11 files changed, 202 insertions(+), 127 deletions(-) diff --git a/include/Config.h b/include/Config.h index 4874e87..90266da 100644 --- a/include/Config.h +++ b/include/Config.h @@ -41,13 +41,11 @@ struct UserConfig uint8_t displayBrightnessDay = 100; uint8_t displayBrightnessNight = 10; boolean displayNightClock = false; // in night mode: true - display clock/ false - display dark screen - boolean displayNightMode = false; // night mode enabled + boolean displayNightModeOfflineTrigger = false; // night mode triggered by offline state uint16_t displayNightmodeStart = 1320; // 22:00 = 22 * 60 = 1320 uint16_t displayNightmodeEnd = 360; // 06:00 = 6 * 60 = 360 - - boolean wifiAPstart = true; int selectedUpdateChannel = 0; // 0 - release 1 - snapshot int timezoneOffest = 7200; // default CEST diff --git a/include/dtuInterface.h b/include/dtuInterface.h index c520ce4..3c8c769 100644 --- a/include/dtuInterface.h +++ b/include/dtuInterface.h @@ -57,6 +57,7 @@ struct connectionControl { boolean preventCloudErrors = true; boolean dtuActiveOffToCloudUpdate = false; + boolean dtuConnectionOnline = true; // true if connection is online as valued a summary uint8_t dtuConnectState = DTU_STATE_OFFLINE; uint8_t dtuErrorState = DTU_ERROR_NO_ERROR; uint8_t dtuTxRxState = DTU_TXRX_STATE_IDLE; @@ -142,12 +143,14 @@ class DTUInterface { void initializeCRC(); static void txrxStateObserver(); - + boolean lastOnlineOfflineState = false; + unsigned long lastOnlineOfflineChange = 0; + void dtuConnectionObserver(); void checkingDataUpdate(); void checkingForLastDataReceived(); boolean cloudPauseActiveControl(); - + // Protobuf functions void writeReqAppGetHistPower(); void readRespAppGetHistPower(pb_istream_t istream); diff --git a/include/mqttHandler.h b/include/mqttHandler.h index 8970d4a..6626a28 100644 --- a/include/mqttHandler.h +++ b/include/mqttHandler.h @@ -44,6 +44,7 @@ struct RemoteInverterData uint32_t dtuRssi = 0; uint32_t wifi_rssi_gateway = 0; boolean cloudPause = false; + boolean dtuConnectionOnline = false; uint8_t dtuConnectState = 0; uint32_t respTimestamp = 1704063600; // init with start time stamp > 0 boolean updateReceived = false; diff --git a/include/version.h b/include/version.h index 9081893..e14f627 100644 --- a/include/version.h +++ b/include/version.h @@ -1,3 +1,3 @@ -#define VERSION "2.0.117_localDev" -#define BUILDTIME "13.09.2024 - 21:47:24" -#define BUILDTIMESTAMP "1726256844" \ No newline at end of file +#define VERSION "2.0.150_localDev" +#define BUILDTIME "09.10.2024 - 09:02:52" +#define BUILDTIMESTAMP "1728457372" \ No newline at end of file diff --git a/include/version.json b/include/version.json index c7878a3..6e71557 100644 --- a/include/version.json +++ b/include/version.json @@ -1,6 +1,6 @@ { - "version": "2.0.117_localDev", - "versiondate": "13.09.2024 - 21:47:24", - "linksnapshot": "https://github.com/ohAnd/dtuGateway/releases/download/snapshot/dtuGateway_snapshot_2.0.117_localDev.bin", - "link": "https://github.com/ohAnd/dtuGateway/releases/latest/download/dtuGateway_release_2.0.117_localDev.bin" + "version": "2.0.150_localDev", + "versiondate": "09.10.2024 - 09:02:52", + "linksnapshot": "https://github.com/ohAnd/dtuGateway/releases/download/snapshot/dtuGateway_snapshot_2.0.150_localDev.bin", + "link": "https://github.com/ohAnd/dtuGateway/releases/latest/download/dtuGateway_release_2.0.150_localDev.bin" } \ No newline at end of file diff --git a/readme.md b/readme.md index 18d0753..bd52231 100644 --- a/readme.md +++ b/readme.md @@ -109,20 +109,23 @@ So I decided to put this abstraction in an **ESP8266** to have a stable abstract - brightness day [0...255] - will also be used without night mode enabled for standard brightness (falling back to this after power value changed) - brightness night [0...255] - note: 0 = backlight off - (to disable PWM control for TFT without backlight control set both brightness values to zero) + - night clock - on/off - if enabled the clock will be shown at night, otherwise blank or dark screen at night - night mode enabled on/ off + - night mode OfflineTrigger on/off - the night mode will be additionally to the schedule triggered, if dtu is offline - night mode start in minutes to start of the day - e.g. 1320 for 22:00 - night mode stop in minutes to start of the day - e.g. 360 for 6:00 - night clock enabled on/ off - on = clock will be displayed instead of dark screen - example settings: - | setting | value | comment | - |-----------------|-------|--------- - | brightnessDay | 150 | note: 255 - ~150 only difficult to perceive - | brightnessNight | 30 | - | nightClock | true | show the clock instead of black screen during night time - | nightMode | true | night mode is enabled - | nightmodeStart | 1320 | night time will start at 22 o'clock - | nightmodeEnd | 390 | night time will end at 6:30 + | setting | value | comment | + |-------------------------|-------|--------- + | brightnessDay | 150 | note: 255 - ~150 only difficult to perceive + | brightnessNight | 30 | + | nightClock | true | show the clock instead of black screen during night (and/ or offline) + | nightMode | true | night mode is enabled + | nightModeOfflineTrigger | true | night mode will be also triggered if dtu is offline + | nightmodeStart | 1320 | night time will start at 22 o'clock + | nightmodeEnd | 390 | night time will end at 6:30 - display hardware types @@ -392,7 +395,7 @@ So I decided to put this abstraction in an **ESP8266** to have a stable abstract | ESP-WROOM-32 NodeMCU-32S | ESP32 | 3.3V | GND | D22/GPIO22/SCL | D21/GPIO21/SDA | OK | - optional display GC9A01 round TFT 1,28" 240x240 (e.g. [link](https://de.aliexpress.com/i/1005006190625792.html)): - - connect SSH1106 driven round TFT display (240x240) with your ESP8266/ ESP32 board (VCC, GND, SCL, SDA, DC, CS, RST) + - connect GC9A01 driven round TFT display (240x240) with your ESP8266/ ESP32 board (VCC, GND, SCL, SDA, DC, CS, RST, BLK) - pinning for different boards (display connector to ESPxx board pins) - BLK = backlight control - will be served with PWM via GPIO 4 diff --git a/src/Config.cpp b/src/Config.cpp index c414141..189f3f7 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -173,6 +173,8 @@ void UserConfigManager::printConfigdata() Serial.println(userConfig.displayNightClock); Serial.print(F("display night mode: \t\t")); Serial.println(userConfig.displayNightMode); + Serial.print(F("display night mode offline trigger: \t")); + Serial.println(userConfig.displayNightModeOfflineTrigger); Serial.print(F("display nightmode start: \t")); Serial.println(userConfig.displayNightmodeStart); Serial.print(F("display nightmode end: \t\t")); @@ -216,6 +218,7 @@ JsonDocument UserConfigManager::mappingStructToJson(const UserConfig &config) doc["display"]["brightnessNight"] = config.displayBrightnessNight; doc["display"]["nightClock"] = config.displayNightClock; doc["display"]["nightMode"] = config.displayNightMode; + doc["display"]["nightModeOfflineTrigger"] = config.displayNightModeOfflineTrigger; doc["display"]["nightmodeStart"] = config.displayNightmodeStart; doc["display"]["nightmodeEnd"] = config.displayNightmodeEnd; @@ -259,6 +262,7 @@ void UserConfigManager::mappingJsonToStruct(JsonDocument doc) userConfig.displayBrightnessNight = doc["display"]["brightnessNight"]; userConfig.displayNightClock = doc["display"]["nightClock"]; userConfig.displayNightMode = doc["display"]["nightMode"]; + userConfig.displayNightModeOfflineTrigger = doc["display"]["nightModeOfflineTrigger"].as(); userConfig.displayNightmodeStart = doc["display"]["nightmodeStart"]; userConfig.displayNightmodeEnd = doc["display"]["nightmodeEnd"]; diff --git a/src/displayTFT.cpp b/src/displayTFT.cpp index 312517f..8a65dba 100644 --- a/src/displayTFT.cpp +++ b/src/displayTFT.cpp @@ -110,12 +110,7 @@ void DisplayTFT::drawScreen(String version, String time) drawMainDTUOnline(true); displayState = 0; } - // else if (lastDisplayData.remoteDisplayActive) - // { - // drawMainDTUOnline(); - // displayState = 2; - // } - else if (dtuConnection.dtuConnectState == DTU_STATE_OFFLINE || dtuConnection.dtuConnectState == DTU_STATE_TRY_RECONNECT || dtuConnection.dtuConnectState == DTU_STATE_CONNECT_ERROR || dtuConnection.dtuConnectState == DTU_STATE_STOPPED) + else if (dtuConnection.dtuConnectionOnline == false) { drawMainDTUOffline(); displayState = 3; @@ -376,30 +371,59 @@ void DisplayTFT::setBrightnessAuto() void DisplayTFT::checkNightMode() { + boolean isNightBySchedule = false; + boolean isNightByOffline = false; // get currentTime in minutes to 00:00 of current day from current time in minutes to 1.1.1970 00:00 uint16_t currentTime = (platformData.currentNTPtime / 60) % 1440; // Serial.println("current time in minutes today: " + String(currentTime) + " - start: " + String(userConfig.displayNightmodeStart) + " - end: " + String(userConfig.displayNightmodeEnd) + " - current brightness: " + String(brightness) + " - dtuState: " + String(dtuConnection.dtuConnectState) + " night: " + String(isNight)); if (userConfig.displayNightMode) { + // schedule trigger // check if night mode can be activated - start time is smaller than end time if ( (userConfig.displayNightmodeStart < userConfig.displayNightmodeEnd && currentTime >= userConfig.displayNightmodeStart && currentTime < userConfig.displayNightmodeEnd) || (userConfig.displayNightmodeStart > userConfig.displayNightmodeEnd && (currentTime >= userConfig.displayNightmodeStart || currentTime < userConfig.displayNightmodeEnd))) { - // Serial.println(" >> night mode active"); + isNightBySchedule = true; + // Serial.println("DisplayTFT:\t >> night mode activated by schedule"); + } + else + { + isNightBySchedule = false; + // Serial.println("DisplayTFT:\t >> day mode activated by schedule"); + } + + // offline trigger + if (dtuConnection.dtuConnectionOnline == true) + { + isNightByOffline = false; + // Serial.println("DisplayTFT:\t >> night mode activated by offline trigger"); + } + else if (dtuConnection.dtuConnectionOnline == false) + { + isNightByOffline = true; + // Serial.println("DisplayTFT:\t >> day mode activated by offline trigger"); + } + + // summary + // start night mode if schedule or offline trigger (when enabled) is active + if (isNightBySchedule || (userConfig.displayNightModeOfflineTrigger && isNightByOffline)) + { if (!isNight) { isNight = true; - Serial.println("DisplayTFT:\t >> night mode activated"); + Serial.println("DisplayTFT:\t >> night mode activated - schedule: " + String(isNightBySchedule) + " - offline: " + String(isNightByOffline)); } } - else + // start day mode if + // offline trigger is enabled and schedule is not active and offline is not active OR + // offline trigger is dsiabled and schedule is not active + else if ((userConfig.displayNightModeOfflineTrigger && !isNightBySchedule && !isNightByOffline) || (!userConfig.displayNightModeOfflineTrigger && !isNightBySchedule)) { - // Serial.println(" >> day mode active"); if (isNight) { isNight = false; - Serial.println("DisplayTFT:\t >> day mode activated"); + Serial.println("DisplayTFT:\t >> day mode activated - schedule: " + String(isNightBySchedule) + " - offline: " + String(isNightByOffline)); } } } diff --git a/src/dtuGateway.ino b/src/dtuGateway.ino index af6b282..78d8261 100644 --- a/src/dtuGateway.ino +++ b/src/dtuGateway.ino @@ -658,6 +658,7 @@ void updateValuesToMqtt(boolean haAutoDiscovery = false) keyValueStore["inverter_PowerLimit"] = String(dtuGlobalData.powerLimit).c_str(); keyValueStore["inverter_WifiRSSI"] = String(dtuGlobalData.dtuRssi).c_str(); keyValueStore["inverter_cloudPause"] = String(dtuConnection.dtuActiveOffToCloudUpdate).c_str(); + keyValueStore["inverter_dtuConnectionOnline"] = String(dtuConnection.dtuConnectionOnline).c_str(); keyValueStore["inverter_dtuConnectState"] = String(dtuConnection.dtuConnectState).c_str(); // copy for (const auto &pair : keyValueStore) @@ -1205,10 +1206,9 @@ void loop() dtuGlobalData.powerLimit = remoteData.powerLimit; dtuGlobalData.dtuRssi = remoteData.dtuRssi; - if (remoteData.cloudPause) - dtuConnection.dtuActiveOffToCloudUpdate = true; - else - dtuConnection.dtuActiveOffToCloudUpdate = false; + dtuConnection.dtuActiveOffToCloudUpdate = remoteData.cloudPause; + dtuConnection.dtuConnectionOnline = remoteData.dtuConnectionOnline; + dtuConnection.dtuConnectState = remoteData.dtuConnectState; dtuGlobalData.lastRespTimestamp = remoteData.respTimestamp; dtuGlobalData.currentTimestamp = remoteData.respTimestamp; // setting the local counter @@ -1264,7 +1264,7 @@ void loop() if (dtuConnection.dtuActiveOffToCloudUpdate) blinkCode = BLINK_PAUSE_CLOUD_UPDATE; - if (userConfig.openhabActive) // && dtuConnection.dtuConnectState == DTU_STATE_CONNECTED) + if (userConfig.openhabActive && !userConfig.remoteDisplayActive) getPowerSetDataFromOpenHab(); // direct request of new powerLimit diff --git a/src/dtuInterface.cpp b/src/dtuInterface.cpp index f0cb248..6f91fef 100644 --- a/src/dtuInterface.cpp +++ b/src/dtuInterface.cpp @@ -38,12 +38,6 @@ void DTUInterface::setup(const char *server) } } -void DTUInterface::setServer(const char *server) -{ - serverIP = server; - disconnect(DTU_STATE_OFFLINE); -} - void DTUInterface::connect() { if (client && !client->connected() && !dtuConnection.dtuActiveOffToCloudUpdate) @@ -96,6 +90,12 @@ void DTUInterface::getDataUpdate() } } +void DTUInterface::setServer(const char *server) +{ + serverIP = server; + disconnect(DTU_STATE_OFFLINE); +} + void DTUInterface::setPowerLimit(int limit) { dtuGlobalData.powerLimitSet = limit; @@ -128,6 +128,7 @@ void DTUInterface::requestRestartDevice() void DTUInterface::dtuLoop() { txrxStateObserver(); + dtuConnectionObserver(); // check if cloud pause is active to prevent cloud errors if (dtuConnection.preventCloudErrors) @@ -199,6 +200,38 @@ void DTUInterface::txrxStateObserver() } } +void DTUInterface::dtuConnectionObserver() +{ + boolean currentOnlineOfflineState = false; + if (dtuConnection.dtuConnectState == DTU_STATE_CONNECTED || dtuConnection.dtuConnectState == DTU_STATE_CLOUD_PAUSE) + { + currentOnlineOfflineState = true; + } + else if (dtuConnection.dtuConnectState == DTU_STATE_OFFLINE || dtuConnection.dtuConnectState == DTU_STATE_TRY_RECONNECT || dtuConnection.dtuConnectState == DTU_STATE_STOPPED || dtuConnection.dtuConnectState == DTU_STATE_CONNECT_ERROR || dtuConnection.dtuConnectState == DTU_STATE_DTU_REBOOT) + { + currentOnlineOfflineState = false; + } + + if (currentOnlineOfflineState != lastOnlineOfflineState) + { + Serial.println("DTUinterface:\t setOverallOnlineOfflineState - change from " + String(lastOnlineOfflineState) + " to " + String(dtuConnection.dtuConnectionOnline)); + lastOnlineOfflineChange = millis(); + lastOnlineOfflineState = currentOnlineOfflineState; + } + + // summary of connection state + if (currentOnlineOfflineState) + { + dtuConnection.dtuConnectionOnline = true; + } + else if (millis() - lastOnlineOfflineChange > 90000 && currentOnlineOfflineState == false) + { + Serial.print(F("DTUinterface:\t setOverallOnlineOfflineState - timeout - reset online offline state")); + Serial.println(" - difference: " + String((millis() - lastOnlineOfflineChange)/1000,3) + " ms - current conn state: " + String(dtuConnection.dtuConnectState)); + dtuConnection.dtuConnectionOnline = false; + } +} + void DTUInterface::dtuLoopStatic(DTUInterface *dtuInterface) { if (dtuInterface) @@ -441,7 +474,89 @@ void DTUInterface::initializeCRC() // Serial.println(F("DTUinterface:\t CRC initialized")); } -// // protocol buffer methods +void DTUInterface::checkingForLastDataReceived() +{ + // check if last data received - currentTimestamp + 5 sec (to debounce async current timestamp) - lastRespTimestamp > 3 min + if (((dtuGlobalData.currentTimestamp + 5) - dtuGlobalData.lastRespTimestamp) > (3 * 60) && dtuGlobalData.grid.voltage > 0 && dtuConnection.dtuErrorState != DTU_ERROR_LAST_SEND) // dtuGlobalData.grid.voltage > 0 indicates dtu/ inverter was working + { + dtuGlobalData.grid.power = 0; + dtuGlobalData.grid.current = 0; + dtuGlobalData.grid.voltage = 0; + + dtuGlobalData.pv0.power = 0; + dtuGlobalData.pv0.current = 0; + dtuGlobalData.pv0.voltage = 0; + + dtuGlobalData.pv1.power = 0; + dtuGlobalData.pv1.current = 0; + dtuGlobalData.pv1.voltage = 0; + + dtuConnection.dtuErrorState = DTU_ERROR_LAST_SEND; + dtuConnection.dtuActiveOffToCloudUpdate = false; + dtuConnection.dtuConnectState = DTU_STATE_OFFLINE; + dtuGlobalData.updateReceived = true; + Serial.println("DTUinterface:\t checkingForLastDataReceived >>>>> TIMEOUT 5 min for DTU -> NIGHT - send zero values +++ currentTimestamp: " + String(dtuGlobalData.currentTimestamp) + " - lastRespTimestamp: " + String(dtuGlobalData.lastRespTimestamp)); + } +} + +/** + * @brief Checks for data updates and performs necessary actions. + * + * This function checks for hanging values on the DTU side and updates the grid voltage history. + * It also checks if the response timestamp has changed and updates the local time if necessary. + * If there is a response time error, it stops the connection to the DTU. + */ +void DTUInterface::checkingDataUpdate() +{ + // checking for hanging values on DTU side + // fill grid voltage history + gridVoltHist[gridVoltCnt++] = dtuGlobalData.grid.voltage; + if (gridVoltCnt > 9) + gridVoltCnt = 0; + + bool gridVoltValueHanging = true; + // Serial.println(F("DTUinterface:\t GridV check")); + // compare all values in history with the first value - if all are equal, then the value is hanging + for (uint8_t i = 1; i < 10; i++) + { + // Serial.println("DTUinterface:\t --> " + String(i) + " compare : " + String(gridVoltHist[i]) + " V - with: " + String(gridVoltHist[0]) + " V"); + if (gridVoltHist[i] != gridVoltHist[0]) + { + gridVoltValueHanging = false; + break; + } + } + // Serial.println("DTUinterface:\t GridV check result: " + String(gridVoltValueHanging)); + if (gridVoltValueHanging) + { + Serial.println(F("DTUinterface:\t checkingDataUpdate -> grid voltage observer found hanging value (DTU_ERROR_DATA_NO_CHANGE) - try to reboot DTU")); + handleError(DTU_ERROR_DATA_NO_CHANGE); + dtuGlobalData.uptodate = false; + } + + // check for up-to-date - last response timestamp have to not equal the current response timestamp + if ((dtuGlobalData.lastRespTimestamp != dtuGlobalData.respTimestamp) && (dtuGlobalData.respTimestamp != 0)) + { + dtuGlobalData.uptodate = true; + dtuConnection.dtuErrorState = DTU_ERROR_NO_ERROR; + // sync local time (in seconds) to DTU time, only if abbrevation about 3 seconds + if (abs((int(dtuGlobalData.respTimestamp) - int(dtuGlobalData.currentTimestamp))) > 3) + { + dtuGlobalData.currentTimestamp = dtuGlobalData.respTimestamp; + Serial.print(F("DTUinterface:\t checkingDataUpdate ---> synced local time with DTU time\n")); + } + } + else + { + dtuGlobalData.uptodate = false; + Serial.println(F("DTUinterface:\t checkingDataUpdate -> (DTU_ERROR_NO_TIME) - try to reboot DTU")); + // stopping connection to DTU when response time error - try with reconnec + handleError(DTU_ERROR_NO_TIME); + } + dtuGlobalData.lastRespTimestamp = dtuGlobalData.respTimestamp; +} + +// protocol buffer methods void DTUInterface::writeReqRealDataNew() { @@ -589,93 +704,11 @@ void DTUInterface::readRespRealDataNew(pb_istream_t istream) } else { + Serial.println(F("DTUinterface:\t readRespRealDataNew -> got timestamp == 0 (DTU_ERROR_NO_TIME) - try to reboot DTU")); handleError(DTU_ERROR_NO_TIME); } } -/** - * @brief Checks for data updates and performs necessary actions. - * - * This function checks for hanging values on the DTU side and updates the grid voltage history. - * It also checks if the response timestamp has changed and updates the local time if necessary. - * If there is a response time error, it stops the connection to the DTU. - */ -void DTUInterface::checkingDataUpdate() -{ - // checking for hanging values on DTU side - // fill grid voltage history - gridVoltHist[gridVoltCnt++] = dtuGlobalData.grid.voltage; - if (gridVoltCnt > 9) - gridVoltCnt = 0; - - bool gridVoltValueHanging = true; - // Serial.println(F("DTUinterface:\t GridV check")); - // compare all values in history with the first value - if all are equal, then the value is hanging - for (uint8_t i = 1; i < 10; i++) - { - // Serial.println("DTUinterface:\t --> " + String(i) + " compare : " + String(gridVoltHist[i]) + " V - with: " + String(gridVoltHist[0]) + " V"); - if (gridVoltHist[i] != gridVoltHist[0]) - { - gridVoltValueHanging = false; - break; - } - } - // Serial.println("DTUinterface:\t GridV check result: " + String(gridVoltValueHanging)); - if (gridVoltValueHanging) - { - Serial.println(F("DTUinterface:\t checkingDataUpdate -> grid voltage observer found hanging value - try to reboot DTU")); - handleError(DTU_ERROR_DATA_NO_CHANGE); - dtuGlobalData.uptodate = false; - } - - // check for up-to-date - last response timestamp have to not equal the current response timestamp - if ((dtuGlobalData.lastRespTimestamp != dtuGlobalData.respTimestamp) && (dtuGlobalData.respTimestamp != 0)) - { - dtuGlobalData.uptodate = true; - dtuConnection.dtuErrorState = DTU_ERROR_NO_ERROR; - // sync local time (in seconds) to DTU time, only if abbrevation about 3 seconds - if (abs((int(dtuGlobalData.respTimestamp) - int(dtuGlobalData.currentTimestamp))) > 3) - { - dtuGlobalData.currentTimestamp = dtuGlobalData.respTimestamp; - Serial.print(F("DTUinterface:\t checkingDataUpdate ---> synced local time with DTU time\n")); - } - } - else - { - dtuGlobalData.uptodate = false; - Serial.print(F("DTUinterface:\t checkingDataUpdate -> DTU_ERROR_NO_TIME\n")); - // stopping connection to DTU when response time error - try with reconnec - handleError(DTU_ERROR_NO_TIME); - } - dtuGlobalData.lastRespTimestamp = dtuGlobalData.respTimestamp; -} - -void DTUInterface::checkingForLastDataReceived() -{ - // check if last data received - currentTimestamp + 5 sec (to debounce async current timestamp) - lastRespTimestamp > 3 min - if (((dtuGlobalData.currentTimestamp + 5) - dtuGlobalData.lastRespTimestamp) > (3 * 60) && dtuGlobalData.grid.voltage > 0 && dtuConnection.dtuErrorState != DTU_ERROR_LAST_SEND) // dtuGlobalData.grid.voltage > 0 indicates dtu/ inverter was working - { - dtuGlobalData.grid.power = 0; - dtuGlobalData.grid.current = 0; - dtuGlobalData.grid.voltage = 0; - - dtuGlobalData.pv0.power = 0; - dtuGlobalData.pv0.current = 0; - dtuGlobalData.pv0.voltage = 0; - - dtuGlobalData.pv1.power = 0; - dtuGlobalData.pv1.current = 0; - dtuGlobalData.pv1.voltage = 0; - - - dtuConnection.dtuErrorState = DTU_ERROR_LAST_SEND; - dtuConnection.dtuActiveOffToCloudUpdate = false; - dtuConnection.dtuConnectState = DTU_STATE_OFFLINE; - dtuGlobalData.updateReceived = true; - Serial.println("DTUinterface:\t checkingForLastDataReceived >>>>> TIMEOUT 5 min for DTU -> NIGHT - send zero values +++ currentTimestamp: " + String(dtuGlobalData.currentTimestamp) + " - lastRespTimestamp: " + String(dtuGlobalData.lastRespTimestamp)); - } -} - void DTUInterface::writeReqAppGetHistPower() { uint8_t buffer[200]; diff --git a/src/mqttHandler.cpp b/src/mqttHandler.cpp index e127638..462d5f7 100644 --- a/src/mqttHandler.cpp +++ b/src/mqttHandler.cpp @@ -92,6 +92,13 @@ void MQTTHandler::subscribedMessageArrived(char *topic, byte *payload, unsigned else instance->lastRemoteInverterData.cloudPause = false; } + else if (String(topic) == instance->mqttMainTopicPath + "/inverter/dtuConnectionOnline") + { + if (incommingMessage == "1") + instance->lastRemoteInverterData.dtuConnectionOnline = true; + else + instance->lastRemoteInverterData.dtuConnectionOnline = false; + } else if (String(topic) == instance->mqttMainTopicPath + "/inverter/dtuConnectState") instance->lastRemoteInverterData.dtuConnectState = incommingMessage.toInt(); else if (String(topic) == instance->mqttMainTopicPath + "/time/stamp") @@ -323,6 +330,8 @@ void MQTTHandler::reconnect() Serial.println("MQTT:\t\t subscribe to: " + (mqttMainTopicPath + "/inverter/WifiRSSI")); client.subscribe((mqttMainTopicPath + "/inverter/cloudPause").c_str()); Serial.println("MQTT:\t\t subscribe to: " + (mqttMainTopicPath + "/inverter/dtuConnectState")); + client.subscribe((mqttMainTopicPath + "/inverter/dtuConnectionOnline").c_str()); + Serial.println("MQTT:\t\t subscribe to: " + (mqttMainTopicPath + "/inverter/dtuConnectionOnline")); client.subscribe((mqttMainTopicPath + "/inverter/dtuConnectState").c_str()); Serial.println("MQTT:\t\t subscribe to: " + (mqttMainTopicPath + "/inverter/cloudPause")); client.subscribe((mqttMainTopicPath + "/time/stamp").c_str());