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/displayTFT.h b/include/displayTFT.h index 742437a..a1f56eb 100644 --- a/include/displayTFT.h +++ b/include/displayTFT.h @@ -49,8 +49,6 @@ class DisplayTFT { void checkChangedValues(); - void drawIcon(const uint16_t *icon, int16_t x, int16_t y, int16_t w, int16_t h); - void checkNightMode(); void setBrightnessAuto(); @@ -70,4 +68,64 @@ class DisplayTFT { int8_t getPinName(int8_t pin); }; +// Icon width and height +const uint16_t cloudWidth = 32; +const uint16_t cloudHeight = 26; + +const unsigned short cloud[0x340] PROGMEM ={ +0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x00E3, // 0x0010 (16) +0x00A1, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0020 (32) +0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x02EA, 0x0532, 0x0635, 0x0696, // 0x0030 (48) +0x0676, 0x0655, 0x0510, 0x0206, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0040 (64) +0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x02AA, 0x06B9, 0x06FA, 0x06F9, 0x06F8, 0x06F8, // 0x0050 (80) +0x06F8, 0x0738, 0x0799, 0x07D9, 0x06B5, 0x0123, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0060 (96) +0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x03F0, 0x06DB, 0x0699, 0x0638, 0x0657, 0x0677, 0x0697, // 0x0070 (112) +0x0697, 0x06B7, 0x06D7, 0x06F7, 0x07B9, 0x07D9, 0x0206, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0080 (128) +0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x036E, 0x067B, 0x0618, 0x05F8, 0x0618, 0x0638, 0x0658, 0x0677, // 0x0090 (144) +0x0677, 0x0697, 0x06B7, 0x06D7, 0x06D7, 0x0778, 0x0799, 0x0144, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x00A0 (160) +0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0125, 0x063B, 0x05D9, 0x05D8, 0x05F8, 0x05F8, 0x0618, 0x0638, 0x0658, // 0x00B0 (176) +0x0657, 0x0677, 0x0697, 0x06B7, 0x06B7, 0x06D7, 0x0799, 0x06B6, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x00C0 (192) +0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0495, 0x05FB, 0x0598, 0x05B8, 0x05B8, 0x05D8, 0x05F8, 0x0618, 0x0638, // 0x00D0 (208) +0x0699, 0x0658, 0x0677, 0x0677, 0x0697, 0x06B7, 0x06D7, 0x0799, 0x02C9, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x00E0 (224) +0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0082, 0x05BA, 0x0579, 0x0579, 0x0598, 0x0598, 0x05B8, 0x05D8, 0x0639, 0x05F7, // 0x00F0 (240) +0x04F3, 0x0658, 0x0678, 0x0657, 0x0677, 0x0697, 0x06B7, 0x0759, 0x05D4, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0100 (256) +0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x020A, 0x059B, 0x0539, 0x0559, 0x0579, 0x0578, 0x0598, 0x05F9, 0x05B8, 0x0166, // 0x0110 (272) +0x0000, 0x028A, 0x0679, 0x0678, 0x0657, 0x0677, 0x0697, 0x06D8, 0x06F8, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0120 (288) +0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x028D, 0x055B, 0x0519, 0x0539, 0x0539, 0x0558, 0x05BA, 0x0578, 0x0145, 0x0000, // 0x0130 (304) +0x0000, 0x0000, 0x0269, 0x0679, 0x0658, 0x0657, 0x0677, 0x0698, 0x06D8, 0x0490, 0x01C5, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0140 (320) +0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x02AE, 0x053B, 0x04F9, 0x0519, 0x0519, 0x0559, 0x0518, 0x0125, 0x0000, 0x0000, // 0x0150 (336) +0x0000, 0x0000, 0x0000, 0x0249, 0x0638, 0x0638, 0x0638, 0x0657, 0x0677, 0x0719, 0x075A, 0x0635, 0x0185, 0x0000, 0x0000, 0x0000, // 0x0160 (352) +0x0000, 0x0000, 0x0000, 0x0000, 0x00C5, 0x0374, 0x04BA, 0x04DA, 0x04D9, 0x04F9, 0x04F9, 0x059B, 0x030E, 0x0000, 0x0000, 0x0041, // 0x0170 (368) +0x0000, 0x0041, 0x0000, 0x0000, 0x04D3, 0x0659, 0x0618, 0x0638, 0x0658, 0x0677, 0x0698, 0x0739, 0x077A, 0x02CA, 0x0000, 0x0000, // 0x0180 (384) +0x0000, 0x0000, 0x0000, 0x022E, 0x04BC, 0x04DC, 0x049A, 0x0499, 0x04B9, 0x04D9, 0x04D9, 0x051A, 0x0497, 0x0209, 0x03F3, 0x01A8, // 0x0190 (400) +0x0000, 0x024A, 0x038F, 0x026A, 0x05B8, 0x05F8, 0x05F8, 0x0618, 0x0638, 0x0658, 0x0657, 0x0677, 0x06D8, 0x075A, 0x0207, 0x0000, // 0x01A0 (416) +0x0000, 0x0000, 0x022E, 0x049D, 0x045B, 0x043A, 0x045A, 0x047A, 0x049A, 0x0499, 0x04B9, 0x04D9, 0x051A, 0x057B, 0x05BC, 0x0146, // 0x01B0 (432) +0x0000, 0x024A, 0x063C, 0x05FA, 0x05B9, 0x05B8, 0x05D8, 0x05F8, 0x0618, 0x0638, 0x0638, 0x0658, 0x0677, 0x06F9, 0x06D8, 0x0020, // 0x01C0 (448) +0x0000, 0x00A4, 0x043D, 0x041B, 0x041A, 0x041A, 0x043A, 0x045A, 0x047A, 0x047A, 0x0499, 0x04B9, 0x04D9, 0x04F9, 0x055B, 0x0146, // 0x01D0 (464) +0x0000, 0x022A, 0x05DA, 0x0579, 0x0598, 0x0598, 0x05B8, 0x05D8, 0x05F8, 0x05F8, 0x0618, 0x0638, 0x0658, 0x0657, 0x0719, 0x02EA, // 0x01E0 (480) +0x0000, 0x02D4, 0x041D, 0x03DA, 0x03FA, 0x03FA, 0x041A, 0x043A, 0x045A, 0x045A, 0x047A, 0x0499, 0x04B9, 0x04D9, 0x053B, 0x0146, // 0x01F0 (496) +0x0000, 0x020A, 0x059B, 0x0559, 0x0579, 0x0578, 0x0598, 0x05B8, 0x05D8, 0x05D8, 0x05F8, 0x0618, 0x0638, 0x0638, 0x06D9, 0x0553, // 0x0200 (512) +0x0043, 0x035A, 0x03BC, 0x03BA, 0x03DA, 0x03DA, 0x03FA, 0x041A, 0x043A, 0x043A, 0x045A, 0x047A, 0x049A, 0x049A, 0x051B, 0x0146, // 0x0210 (528) +0x0000, 0x020A, 0x057B, 0x0539, 0x0559, 0x0559, 0x0578, 0x0598, 0x05B8, 0x05B8, 0x05D8, 0x05F8, 0x0618, 0x0618, 0x0679, 0x05F6, // 0x0220 (544) +0x01D0, 0x035B, 0x037B, 0x039B, 0x039B, 0x03BA, 0x03DA, 0x03FA, 0x03FA, 0x041A, 0x043A, 0x045A, 0x045A, 0x047A, 0x04DB, 0x0126, // 0x0230 (560) +0x0000, 0x020A, 0x055B, 0x0519, 0x0539, 0x0539, 0x0559, 0x0579, 0x0598, 0x0598, 0x05B8, 0x05D8, 0x05F8, 0x05F8, 0x0659, 0x05F7, // 0x0240 (576) +0x0253, 0x033B, 0x035B, 0x037B, 0x037B, 0x039B, 0x03BA, 0x03DA, 0x03DA, 0x03FA, 0x041A, 0x043A, 0x043A, 0x045A, 0x04BB, 0x0126, // 0x0250 (592) +0x0000, 0x01EA, 0x053B, 0x04F9, 0x04F9, 0x0519, 0x0539, 0x0559, 0x0559, 0x0578, 0x0598, 0x05B8, 0x05B8, 0x05D8, 0x0639, 0x05B7, // 0x0260 (608) +0x014B, 0x031B, 0x033C, 0x035B, 0x035B, 0x037B, 0x039B, 0x03BB, 0x03BA, 0x03DA, 0x03FA, 0x041A, 0x041A, 0x043A, 0x049B, 0x0106, // 0x0270 (624) +0x0000, 0x01CA, 0x051B, 0x04D9, 0x04D9, 0x04F9, 0x0519, 0x0539, 0x0539, 0x0559, 0x0579, 0x0598, 0x0598, 0x05B8, 0x063A, 0x0514, // 0x0280 (640) +0x0000, 0x02B9, 0x033D, 0x031B, 0x033B, 0x035B, 0x037B, 0x037B, 0x039B, 0x03BA, 0x03DA, 0x03FA, 0x03FA, 0x041A, 0x047C, 0x0127, // 0x0290 (656) +0x0000, 0x020B, 0x04DC, 0x04B9, 0x04B9, 0x04D9, 0x04F9, 0x0519, 0x0519, 0x0539, 0x0559, 0x0579, 0x0578, 0x0598, 0x063A, 0x02EC, // 0x02A0 (672) +0x0000, 0x018F, 0x033E, 0x02FB, 0x031B, 0x033B, 0x035B, 0x035B, 0x037B, 0x039B, 0x03BA, 0x03BA, 0x03DA, 0x03FA, 0x043B, 0x0355, // 0x02B0 (688) +0x020C, 0x03D7, 0x049A, 0x047A, 0x0499, 0x04B9, 0x04D9, 0x04D9, 0x04F9, 0x0519, 0x0539, 0x0559, 0x0559, 0x05DA, 0x05FA, 0x0020, // 0x02C0 (704) +0x0000, 0x0000, 0x02FD, 0x031E, 0x02FB, 0x031B, 0x033B, 0x033B, 0x035B, 0x037B, 0x039B, 0x039B, 0x03BA, 0x03DA, 0x03DA, 0x043B, // 0x02D0 (720) +0x047C, 0x045B, 0x043A, 0x045A, 0x047A, 0x0499, 0x04B9, 0x04B9, 0x04D9, 0x04F9, 0x0519, 0x0519, 0x057A, 0x05FB, 0x0229, 0x0000, // 0x02E0 (736) +0x0000, 0x0000, 0x0064, 0x02FE, 0x031E, 0x02FC, 0x02FB, 0x031B, 0x033B, 0x035B, 0x037B, 0x037B, 0x039B, 0x03BA, 0x03DA, 0x03DA, // 0x02F0 (752) +0x03FA, 0x041A, 0x043A, 0x043A, 0x045A, 0x047A, 0x049A, 0x0499, 0x04B9, 0x04D9, 0x04F9, 0x055B, 0x05BC, 0x02CD, 0x0000, 0x0000, // 0x0300 (768) +0x0000, 0x0000, 0x0000, 0x0022, 0x029A, 0x031F, 0x031E, 0x033D, 0x033D, 0x035D, 0x037D, 0x039D, 0x03BC, 0x03BC, 0x03DC, 0x03FC, // 0x0310 (784) +0x041C, 0x043C, 0x043C, 0x045C, 0x047B, 0x049B, 0x04BB, 0x04BB, 0x04DB, 0x051C, 0x055C, 0x051A, 0x01A8, 0x0000, 0x0000, 0x0000, // 0x0320 (800) +0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x00A7, 0x01D2, 0x0256, 0x0297, 0x0297, 0x0297, 0x02B7, 0x02D7, 0x02D7, 0x02F7, 0x0317, // 0x0330 (816) +0x0316, 0x0336, 0x0356, 0x0356, 0x0376, 0x0396, 0x0396, 0x03B6, 0x03B5, 0x0311, 0x0168, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0340 (832) +}; + + #endif // DISPLAYTFT_H \ No newline at end of file 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 35374c8..6626a28 100644 --- a/include/mqttHandler.h +++ b/include/mqttHandler.h @@ -43,6 +43,9 @@ struct RemoteInverterData uint8_t powerLimit = 254; 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; boolean remoteDisplayActive = false; diff --git a/include/version.h b/include/version.h index 80ee52a..e14f627 100644 --- a/include/version.h +++ b/include/version.h @@ -1,3 +1,3 @@ -#define VERSION "2.0.55_localDev" -#define BUILDTIME "11.09.2024 - 21:58:24" -#define BUILDTIMESTAMP "1726084704" +#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 db02380..6e71557 100644 --- a/include/version.json +++ b/include/version.json @@ -1,6 +1,6 @@ { - "version": "2.0.55_localDev", - "versiondate": "11.09.2024 - 21:58:24", - "linksnapshot": "https://github.com/ohAnd/dtuGateway/releases/download/snapshot/dtuGateway_snapshot_2.0.55_localDev.bin", - "link": "https://github.com/ohAnd/dtuGateway/releases/latest/download/dtuGateway_release_2.0.55_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/platformio.ini b/platformio.ini index e3adb05..9ea92c1 100644 --- a/platformio.ini +++ b/platformio.ini @@ -13,8 +13,8 @@ platform = espressif32 board = esp32dev framework = arduino monitor_speed = 115200 -monitor_port = COM6 -upload_port = COM6 +monitor_port = COM3 +upload_port = COM3 upload_speed = 921600 lib_deps = arduino-libraries/NTPClient @ ^3.2.1 @@ -64,8 +64,8 @@ platform = espressif8266 board = esp07s framework = arduino monitor_speed = 115200 -monitor_port = COM3 -upload_port = COM3 +monitor_port = COM5 +upload_port = COM5 upload_speed = 921600 lib_deps = arduino-libraries/NTPClient @ ^3.2.1 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/display.cpp b/src/display.cpp index eabebfa..efdc5bc 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -88,8 +88,8 @@ void Display::drawScreen() drawMainDTUOnline(); else if (dtuConnection.dtuConnectState == DTU_STATE_CLOUD_PAUSE) drawMainDTUOnline(true); - else if (lastDisplayData.remoteDisplayActive) - drawMainDTUOnline(); + // else if (lastDisplayData.remoteDisplayActive) + // drawMainDTUOnline(); else drawMainDTUOffline(); diff --git a/src/displayTFT.cpp b/src/displayTFT.cpp index b93c278..8a65dba 100644 --- a/src/displayTFT.cpp +++ b/src/displayTFT.cpp @@ -25,6 +25,9 @@ void DisplayTFT::setup() orientation = 3; tft.setRotation(orientation); tft.fillScreen(TFT_BLACK); + // Swap the colour byte order when rendering + tft.setSwapBytes(true); + pinMode(BACKLIIGHT_PIN, OUTPUT); brightness = userConfig.displayBrightnessDay; // set brightness to max - workaround for unconfigured brightness and no backlight control @@ -105,19 +108,16 @@ void DisplayTFT::drawScreen(String version, String time) else if (dtuConnection.dtuConnectState == DTU_STATE_CLOUD_PAUSE) { drawMainDTUOnline(true); - displayState = 1; - } - else if (lastDisplayData.remoteDisplayActive) - { - drawMainDTUOnline(); - displayState = 2; + displayState = 0; } - 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; } - } else { + } + else + { displayState = 4; } @@ -134,55 +134,51 @@ void DisplayTFT::drawScreen(String version, String time) void DisplayTFT::drawMainDTUOnline(bool pause) { - // state dependend screen change + // show a cloud upload symbol if cloud pause active if (pause) - { - tft.setTextColor(TFT_VIOLET, TFT_NAVY); - tft.drawCentreString("cloud pause", 120, 110, 4); - } + tft.pushImage(195, 70, cloudWidth, cloudHeight, cloud); + else + tft.fillRect(195, 70, 32, 26, TFT_BLACK); // clear icon - if (!pause) - { - // main screen - // --- base window for wattage ---------------------------------- - uint32_t wattRingColor = TFT_CYAN; - if (lastDisplayData.remoteDisplayActive) - wattRingColor = TFT_DARKGREEN; - tft.drawSmoothArc(119, 119, 75, 75 - 1, 47, 313, wattRingColor, TFT_BLACK); - tft.drawWideLine(64, 169, 64 + 109, 169, 2, wattRingColor, TFT_BLACK); - - // ---------------------------------------------- - // tft.pushImage(70, 200, 16, 16, wifiIcon); - // ---------------------------------------------- - // current power - tft.setTextColor(TFT_DARKCYAN, TFT_BLACK); - tft.drawCentreString("W", 120, 57, 4); + // main screen + // --- base window for wattage ---------------------------------- + uint32_t wattRingColor = TFT_CYAN; + if (lastDisplayData.remoteDisplayActive) + wattRingColor = TFT_DARKGREEN; + tft.drawSmoothArc(119, 119, 75, 75 - 1, 47, 313, wattRingColor, TFT_BLACK); + tft.drawWideLine(64, 169, 64 + 109, 169, 2, wattRingColor, TFT_BLACK); + + // ---------------------------------------------- + // tft.pushImage(70, 200, 16, 16, wifiIcon); + // ---------------------------------------------- + // current power + tft.setTextColor(TFT_DARKCYAN, TFT_BLACK); + tft.drawCentreString("W", 120, 57, 4); - tft.setTextColor(TFT_WHITE, TFT_BLACK); - // tft.drawCentreString(String(lastDisplayData.totalPower), 120, 84, 6); + tft.setTextColor(TFT_WHITE, TFT_BLACK); + // tft.drawCentreString(String(lastDisplayData.totalPower), 120, 84, 6); - tft.setTextDatum(TC_DATUM); // centered datum - int padding = tft.textWidth("999.9", 6); - tft.setTextPadding(padding); - tft.drawNumber(lastDisplayData.totalPower, 120, 84, 6); + tft.setTextDatum(TC_DATUM); // centered datum + int padding = tft.textWidth("999.9", 6); + tft.setTextPadding(padding); + tft.drawNumber(lastDisplayData.totalPower, 120, 84, 6); - // power limit - tft.setTextColor(TFT_GREENYELLOW, TFT_BLACK); + // power limit + tft.setTextColor(TFT_GREENYELLOW, TFT_BLACK); - tft.setTextDatum(TC_DATUM); // centered datum - padding = tft.textWidth("999", 6); - tft.setTextPadding(padding); - // tft.drawCentreString(String(lastDisplayData.powerLimit) + " %", 120, 130, 4); - tft.drawNumber(lastDisplayData.powerLimit, 120, 130, 4); - tft.setTextPadding(0); // reset padding + tft.setTextDatum(TC_DATUM); // centered datum + padding = tft.textWidth("999", 6); + tft.setTextPadding(padding); + // tft.drawCentreString(String(lastDisplayData.powerLimit) + " %", 120, 130, 4); + tft.drawNumber(lastDisplayData.powerLimit, 120, 130, 4); + tft.setTextPadding(0); // reset padding - tft.drawString("%", 148, 135, 2); + tft.drawString("%", 148, 135, 2); - tft.setTextColor(TFT_DARKCYAN, TFT_BLACK); - tft.drawCentreString("Power Limit", 120, 150, 2); + tft.setTextColor(TFT_DARKCYAN, TFT_BLACK); + tft.drawCentreString("Power Limit", 120, 150, 2); - // tft.fillRoundRect(80, 120, 100, 26, 1, TFT_BLACK); - } + // tft.fillRoundRect(80, 120, 100, 26, 1, TFT_BLACK); } void DisplayTFT::drawMainDTUOffline() @@ -294,7 +290,9 @@ void DisplayTFT::drawFooter(String time) { tft.setTextColor(SPECIAL_BLUE, TFT_BLACK); tft.drawCentreString(" " + String(lastDisplayData.totalPower) + " W ", 120, 174, 4); - } else { + } + else + { tft.fillRect(60, 170, 120, 37, TFT_BLACK); // clear power display } @@ -371,39 +369,61 @@ void DisplayTFT::setBrightnessAuto() } } -void DisplayTFT::drawIcon(const uint16_t *icon, int16_t x, int16_t y, int16_t w, int16_t h) -{ - // tft.drawBitmap(x, y, icon, w, h, TFT_WHITE); - - tft.pushImage(10, 10, 16, 16, icon); -} - 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 de0bdfb..78d8261 100644 --- a/src/dtuGateway.ino +++ b/src/dtuGateway.ino @@ -657,6 +657,9 @@ void updateValuesToMqtt(boolean haAutoDiscovery = false) keyValueStore["inverter_Temp"] = String(dtuGlobalData.inverterTemp).c_str(); 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) { @@ -668,28 +671,28 @@ void updateValuesToMqtt(boolean haAutoDiscovery = false) // update all apis according to current states and settings void updateDataToApis() { - if (!dtuConnection.dtuActiveOffToCloudUpdate) // normal update + // if (!dtuConnection.dtuActiveOffToCloudUpdate) // normal update + // { + if (((globalControls.getDataAuto || globalControls.getDataOnce) && dtuGlobalData.uptodate) || dtuConnection.dtuErrorState == DTU_ERROR_LAST_SEND) { - if (((globalControls.getDataAuto || globalControls.getDataOnce) && dtuGlobalData.uptodate) || dtuConnection.dtuErrorState == DTU_ERROR_LAST_SEND) - { - if (userConfig.openhabActive) - updateValueToOpenhab(); - if (userConfig.mqttActive) - updateValuesToMqtt(userConfig.mqttHAautoDiscoveryON); + if (userConfig.openhabActive) + updateValueToOpenhab(); + if (userConfig.mqttActive) + updateValuesToMqtt(userConfig.mqttHAautoDiscoveryON); - if (globalControls.dataFormatJSON) - { - dtuInterface.printDataAsJsonToSerial(); - } - else - { - dtuInterface.printDataAsTextToSerial(); - } - if (globalControls.getDataOnce) - globalControls.getDataOnce = false; + if (globalControls.dataFormatJSON) + { + dtuInterface.printDataAsJsonToSerial(); + } + else + { + dtuInterface.printDataAsTextToSerial(); } + if (globalControls.getDataOnce) + globalControls.getDataOnce = false; } } +// } // **** @@ -1203,6 +1206,10 @@ void loop() dtuGlobalData.powerLimit = remoteData.powerLimit; dtuGlobalData.dtuRssi = remoteData.dtuRssi; + dtuConnection.dtuActiveOffToCloudUpdate = remoteData.cloudPause; + dtuConnection.dtuConnectionOnline = remoteData.dtuConnectionOnline; + + dtuConnection.dtuConnectState = remoteData.dtuConnectState; dtuGlobalData.lastRespTimestamp = remoteData.respTimestamp; dtuGlobalData.currentTimestamp = remoteData.respTimestamp; // setting the local counter Serial.println("\nMQTT: changed remote inverter data"); @@ -1257,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 @@ -1289,7 +1296,7 @@ void loop() { Serial.printf(">>>>> %02is task - state --> ", int(interval5000ms)); Serial.print("local: " + dtuInterface.getTimeStringByTimestamp(dtuGlobalData.currentTimestamp)); - Serial.println(" --- NTP: " + timeClient.getFormattedTime()); + Serial.println(" --- NTP: " + timeClient.getFormattedTime() + " ---> dtuConnState: " + String(dtuConnection.dtuConnectState)); previousMillis5000ms = currentMillis; // --------> diff --git a/src/dtuInterface.cpp b/src/dtuInterface.cpp index ebf2699..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,91 +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; - 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]; @@ -1071,6 +1106,7 @@ boolean DTUInterface::cloudPauseActiveControl() Serial.print(F("----> switch ''OFF'' DTU server connection to upload data from DTU to Cloud\n\n")); lastSwOff = dtuGlobalData.currentTimestamp; dtuConnection.dtuActiveOffToCloudUpdate = true; + dtuGlobalData.updateReceived = true; // update at start of pause } else if (dtuGlobalData.currentTimestamp > lastSwOff + DTU_CLOUD_UPLOAD_SECONDS && dtuConnection.dtuActiveOffToCloudUpdate) { diff --git a/src/mqttHandler.cpp b/src/mqttHandler.cpp index 712f053..462d5f7 100644 --- a/src/mqttHandler.cpp +++ b/src/mqttHandler.cpp @@ -27,13 +27,13 @@ void MQTTHandler::subscribedMessageArrived(char *topic, byte *payload, unsigned for (uint8_t i = 0; i < length; i++) incommingMessage += (char)payload[i]; - Serial.println("MQTT: Message arrived [" + String(topic) + "] -> '" + incommingMessage + "'"); + // Serial.println("MQTT: Message arrived [" + String(topic) + "] -> '" + incommingMessage + "'"); if (instance != nullptr) { incommingMessage = incommingMessage.substring(1, length + 1); //'#' has to be ignored if (String(topic) == instance->mqttMainTopicPath + "/inverter/PowerLimit_Set") { - + int gotLimit = (incommingMessage).toInt(); uint8_t setLimit = 0; if (gotLimit >= 2 && gotLimit <= 100) @@ -50,46 +50,62 @@ void MQTTHandler::subscribedMessageArrived(char *topic, byte *payload, unsigned { // Serial.println("MQTT: received message for topic: " + String(topic) + " - value: " + incommingMessage); if (String(topic) == instance->mqttMainTopicPath + "/grid/P") - { instance->lastRemoteInverterData.grid.power = incommingMessage.toFloat(); - } else if(String(topic) == instance->mqttMainTopicPath + "/grid/U") { + else if (String(topic) == instance->mqttMainTopicPath + "/grid/U") instance->lastRemoteInverterData.grid.voltage = incommingMessage.toFloat(); - } else if(String(topic) == instance->mqttMainTopicPath + "/grid/I") { + else if (String(topic) == instance->mqttMainTopicPath + "/grid/I") instance->lastRemoteInverterData.grid.current = incommingMessage.toFloat(); - } else if(String(topic) == instance->mqttMainTopicPath + "/grid/dailyEnergy") { + else if (String(topic) == instance->mqttMainTopicPath + "/grid/dailyEnergy") instance->lastRemoteInverterData.grid.dailyEnergy = incommingMessage.toFloat(); - } else if(String(topic) == instance->mqttMainTopicPath + "/grid/totalEnergy") { + else if (String(topic) == instance->mqttMainTopicPath + "/grid/totalEnergy") instance->lastRemoteInverterData.grid.totalEnergy = incommingMessage.toFloat(); - } else if(String(topic) == instance->mqttMainTopicPath + "/pv0/P") { + else if (String(topic) == instance->mqttMainTopicPath + "/pv0/P") instance->lastRemoteInverterData.pv0.power = incommingMessage.toFloat(); - } else if(String(topic) == instance->mqttMainTopicPath + "/pv0/I") { + else if (String(topic) == instance->mqttMainTopicPath + "/pv0/I") instance->lastRemoteInverterData.pv0.current = incommingMessage.toFloat(); - } else if(String(topic) == instance->mqttMainTopicPath + "/pv0/U") { + else if (String(topic) == instance->mqttMainTopicPath + "/pv0/U") instance->lastRemoteInverterData.pv0.voltage = incommingMessage.toFloat(); - } else if(String(topic) == instance->mqttMainTopicPath + "/pv0/dailyEnergy") { + else if (String(topic) == instance->mqttMainTopicPath + "/pv0/dailyEnergy") instance->lastRemoteInverterData.pv0.dailyEnergy = incommingMessage.toFloat(); - } else if(String(topic) == instance->mqttMainTopicPath + "/pv0/totalEnergy") { + else if (String(topic) == instance->mqttMainTopicPath + "/pv0/totalEnergy") instance->lastRemoteInverterData.pv0.totalEnergy = incommingMessage.toFloat(); - } else if(String(topic) == instance->mqttMainTopicPath + "/pv1/P") { + else if (String(topic) == instance->mqttMainTopicPath + "/pv1/P") instance->lastRemoteInverterData.pv1.power = incommingMessage.toFloat(); - } else if(String(topic) == instance->mqttMainTopicPath + "/pv1/I") { + else if (String(topic) == instance->mqttMainTopicPath + "/pv1/I") instance->lastRemoteInverterData.pv1.current = incommingMessage.toFloat(); - } else if(String(topic) == instance->mqttMainTopicPath + "/pv1/U") { + else if (String(topic) == instance->mqttMainTopicPath + "/pv1/U") instance->lastRemoteInverterData.pv1.voltage = incommingMessage.toFloat(); - } else if(String(topic) == instance->mqttMainTopicPath + "/pv1/dailyEnergy") { + else if (String(topic) == instance->mqttMainTopicPath + "/pv1/dailyEnergy") instance->lastRemoteInverterData.pv1.dailyEnergy = incommingMessage.toFloat(); - } else if(String(topic) == instance->mqttMainTopicPath + "/pv1/totalEnergy") { + else if (String(topic) == instance->mqttMainTopicPath + "/pv1/totalEnergy") instance->lastRemoteInverterData.pv1.totalEnergy = incommingMessage.toFloat(); - } else if(String(topic) == instance->mqttMainTopicPath + "/inverter/Temp") { + else if (String(topic) == instance->mqttMainTopicPath + "/inverter/Temp") instance->lastRemoteInverterData.inverterTemp = incommingMessage.toFloat(); - } else if(String(topic) == instance->mqttMainTopicPath + "/inverter/PowerLimit") { + else if (String(topic) == instance->mqttMainTopicPath + "/inverter/PowerLimit") instance->lastRemoteInverterData.powerLimit = incommingMessage.toInt(); - } else if(String(topic) == instance->mqttMainTopicPath + "/inverter/WifiRSSI") { + else if (String(topic) == instance->mqttMainTopicPath + "/inverter/WifiRSSI") instance->lastRemoteInverterData.dtuRssi = incommingMessage.toInt(); - } else if(String(topic) == instance->mqttMainTopicPath + "/time/stamp") { + else if (String(topic) == instance->mqttMainTopicPath + "/inverter/cloudPause") + { + if (incommingMessage == "1") + instance->lastRemoteInverterData.cloudPause = true; + 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") + { instance->lastRemoteInverterData.respTimestamp = incommingMessage.toInt(); instance->lastRemoteInverterData.updateReceived = true; - } + } else { Serial.println("MQTT: received message for unknown topic: " + String(topic)); @@ -284,36 +300,42 @@ void MQTTHandler::reconnect() client.subscribe((mqttMainTopicPath + "/grid/totalEnergy").c_str()); Serial.println("MQTT:\t\t subscribe to: " + (mqttMainTopicPath + "/grid/totalEnergy")); - client.subscribe((mqttMainTopicPath + "/pv0/P").c_str()); // Panel 0 power + client.subscribe((mqttMainTopicPath + "/pv0/P").c_str()); // Panel 0 power Serial.println("MQTT:\t\t subscribe to: " + (mqttMainTopicPath + "/pv0/P")); - client.subscribe((mqttMainTopicPath + "/pv0/I").c_str()); // Panel 0 current + client.subscribe((mqttMainTopicPath + "/pv0/I").c_str()); // Panel 0 current Serial.println("MQTT:\t\t subscribe to: " + (mqttMainTopicPath + "/pv0/I")); - client.subscribe((mqttMainTopicPath + "/pv0/U").c_str()); // Panel 0 voltage + client.subscribe((mqttMainTopicPath + "/pv0/U").c_str()); // Panel 0 voltage Serial.println("MQTT:\t\t subscribe to: " + (mqttMainTopicPath + "/pv0/U")); client.subscribe((mqttMainTopicPath + "/pv0/dailyEnergy").c_str()); Serial.println("MQTT:\t\t subscribe to: " + (mqttMainTopicPath + "/pv0/dailyEnergy")); client.subscribe((mqttMainTopicPath + "/pv0/totalEnergy").c_str()); Serial.println("MQTT:\t\t subscribe to: " + (mqttMainTopicPath + "/pv0/totalEnergy")); - - client.subscribe((mqttMainTopicPath + "/pv1/P").c_str()); // Panel 1 power + + client.subscribe((mqttMainTopicPath + "/pv1/P").c_str()); // Panel 1 power Serial.println("MQTT:\t\t subscribe to: " + (mqttMainTopicPath + "/pv1/P")); - client.subscribe((mqttMainTopicPath + "/pv1/I").c_str()); // Panel 1 current + client.subscribe((mqttMainTopicPath + "/pv1/I").c_str()); // Panel 1 current Serial.println("MQTT:\t\t subscribe to: " + (mqttMainTopicPath + "/pv1/I")); - client.subscribe((mqttMainTopicPath + "/pv1/U").c_str()); // Panel 1 voltage + client.subscribe((mqttMainTopicPath + "/pv1/U").c_str()); // Panel 1 voltage Serial.println("MQTT:\t\t subscribe to: " + (mqttMainTopicPath + "/pv1/U")); client.subscribe((mqttMainTopicPath + "/pv1/dailyEnergy").c_str()); Serial.println("MQTT:\t\t subscribe to: " + (mqttMainTopicPath + "/pv1/dailyEnergy")); client.subscribe((mqttMainTopicPath + "/pv1/totalEnergy").c_str()); Serial.println("MQTT:\t\t subscribe to: " + (mqttMainTopicPath + "/pv1/totalEnergy")); - + client.subscribe((mqttMainTopicPath + "/inverter/Temp").c_str()); Serial.println("MQTT:\t\t subscribe to: " + (mqttMainTopicPath + "/inverter/Temp")); client.subscribe((mqttMainTopicPath + "/inverter/PowerLimit").c_str()); Serial.println("MQTT:\t\t subscribe to: " + (mqttMainTopicPath + "/inverter/PowerLimit")); client.subscribe((mqttMainTopicPath + "/inverter/WifiRSSI").c_str()); 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()); - Serial.println("MQTT:\t\t subscribe to: " + (mqttMainTopicPath + "/time_stamp")); + Serial.println("MQTT:\t\t subscribe to: " + (mqttMainTopicPath + "/time_stamp")); } else { @@ -381,11 +403,14 @@ void MQTTHandler::setUseTLS(bool useTLS) { stopConnection(); this->useTLS = useTLS; - if(useTLS) { + if (useTLS) + { wifiClientSecure.setInsecure(); client.setClient(wifiClientSecure); Serial.println("MQTT:\t\t setUseTLS: initialized with TLS"); - } else { + } + else + { client.setClient(wifiClient); Serial.println("MQTT:\t\t setUseTLS: initialized without TLS"); }