From 193802aae4658598881c103573caf72fb28861a5 Mon Sep 17 00:00:00 2001 From: fila612 Date: Mon, 18 Jul 2022 09:58:02 +0200 Subject: [PATCH 1/9] HASS - MQTT Retained Messages MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In #104 durch @KG3RK3N vorgeschlagen und von mir smoke-getestet. Scheint den gewünschten Erfolg zu bringen. --- tools/esp8266/app.cpp | 2 +- tools/esp8266/mqtt.h | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tools/esp8266/app.cpp b/tools/esp8266/app.cpp index 38b75e6e..dbb3ee9e 100644 --- a/tools/esp8266/app.cpp +++ b/tools/esp8266/app.cpp @@ -930,7 +930,7 @@ void app::sendMqttDiscoveryConfig(void) { } serializeJson(doc, buffer); - mMqtt.sendMsg2(discoveryTopic, buffer); + mMqtt.sendMsg2(discoveryTopic, buffer, true); doc.clear(); yield(); diff --git a/tools/esp8266/mqtt.h b/tools/esp8266/mqtt.h index 853cd9ba..89570344 100644 --- a/tools/esp8266/mqtt.h +++ b/tools/esp8266/mqtt.h @@ -39,15 +39,15 @@ class mqtt { //DPRINTLN(DBG_VERBOSE, F("mqtt.h:sendMsg")); char top[64]; snprintf(top, 64, "%s/%s", mTopic, topic); - sendMsg2(top, msg); + sendMsg2(top, msg, false); } - void sendMsg2(const char *topic, const char *msg) { + void sendMsg2(const char *topic, const char *msg, boolean retained) { if(mAddressSet) { if(!mClient->connected()) reconnect(); if(mClient->connected()) - mClient->publish(topic, msg); + mClient->publish(topic, msg, retained); } } From 836dc1526bbe5a2c1b75e73e0719ed3a4197ad21 Mon Sep 17 00:00:00 2001 From: stefan123t Date: Fri, 29 Jul 2022 10:51:56 +0200 Subject: [PATCH 2/9] Commented Error-Codes with Hex-Equivalents Commented Error-Codes with Hex-Equivalents --- tools/rpi/hoymiles/decoders/__init__.py | 138 ++++++++++++------------ 1 file changed, 70 insertions(+), 68 deletions(-) diff --git a/tools/rpi/hoymiles/decoders/__init__.py b/tools/rpi/hoymiles/decoders/__init__.py index 2b27a2cc..e2b7c7ff 100644 --- a/tools/rpi/hoymiles/decoders/__init__.py +++ b/tools/rpi/hoymiles/decoders/__init__.py @@ -217,74 +217,76 @@ class EventsResponse(UnknownResponse): """ Hoymiles micro-inverter event log decode helper """ alarm_codes = { - 1: 'Inverter start', - 2: 'DTU command failed', - 121: 'Over temperature protection', - 125: 'Grid configuration parameter error', - 126: 'Software error code 126', - 127: 'Firmware error', - 128: 'Software error code 128', - 129: 'Software error code 129', - 130: 'Offline', - 141: 'Grid overvoltage', - 142: 'Average grid overvoltage', - 143: 'Grid undervoltage', - 144: 'Grid overfrequency', - 145: 'Grid underfrequency', - 146: 'Rapid grid frequency change', - 147: 'Power grid outage', - 148: 'Grid disconnection', - 149: 'Island detected', - 205: 'Input port 1 & 2 overvoltage', - 206: 'Input port 3 & 4 overvoltage', - 207: 'Input port 1 & 2 undervoltage', - 208: 'Input port 3 & 4 undervoltage', - 209: 'Port 1 no input', - 210: 'Port 2 no input', - 211: 'Port 3 no input', - 212: 'Port 4 no input', - 213: 'PV-1 & PV-2 abnormal wiring', - 214: 'PV-3 & PV-4 abnormal wiring', - 215: 'PV-1 Input overvoltage', - 216: 'PV-1 Input undervoltage', - 217: 'PV-2 Input overvoltage', - 218: 'PV-2 Input undervoltage', - 219: 'PV-3 Input overvoltage', - 220: 'PV-3 Input undervoltage', - 221: 'PV-4 Input overvoltage', - 222: 'PV-4 Input undervoltage', - 301: 'Hardware error code 301', - 302: 'Hardware error code 302', - 303: 'Hardware error code 303', - 304: 'Hardware error code 304', - 305: 'Hardware error code 305', - 306: 'Hardware error code 306', - 307: 'Hardware error code 307', - 308: 'Hardware error code 308', - 309: 'Hardware error code 309', - 310: 'Hardware error code 310', - 311: 'Hardware error code 311', - 312: 'Hardware error code 312', - 313: 'Hardware error code 313', - 314: 'Hardware error code 314', - 5041: 'Error code-04 Port 1', - 5042: 'Error code-04 Port 2', - 5043: 'Error code-04 Port 3', - 5044: 'Error code-04 Port 4', - 5051: 'PV Input 1 Overvoltage/Undervoltage', - 5052: 'PV Input 2 Overvoltage/Undervoltage', - 5053: 'PV Input 3 Overvoltage/Undervoltage', - 5054: 'PV Input 4 Overvoltage/Undervoltage', - 5060: 'Abnormal bias', - 5070: 'Over temperature protection', - 5080: 'Grid Overvoltage/Undervoltage', - 5090: 'Grid Overfrequency/Underfrequency', - 5100: 'Island detected', - 5120: 'EEPROM reading and writing error', - 5150: '10 min value grid overvoltage', - 5200: 'Firmware error', - 8310: 'Shut down', - 9000: 'Microinverter is suspected of being stolen' + // HM Error Codes + 1: 'Inverter start', // 0x01 + 2: 'DTU command failed', // 0x02 + 121: 'Over temperature protection', // 0x79 + 125: 'Grid configuration parameter error', // 0x7D + 126: 'Software error code 126', // 0x7E + 127: 'Firmware error', // 0x7F + 128: 'Software error code 128', // 0x80 + 129: 'Software error code 129', // 0x81 + 130: 'Offline', // 0x82 + 141: 'Grid overvoltage', // 0x8D + 142: 'Average grid overvoltage', // 0x8E + 143: 'Grid undervoltage', // 0x8F + 144: 'Grid overfrequency', // 0x90 + 145: 'Grid underfrequency', // 0x91 + 146: 'Rapid grid frequency change', // 0x92 + 147: 'Power grid outage', // 0x93 + 148: 'Grid disconnection', // 0x94 + 149: 'Island detected', // 0x95 + 205: 'Input port 1 & 2 overvoltage', // 0xCD + 206: 'Input port 3 & 4 overvoltage', // 0xCE + 207: 'Input port 1 & 2 undervoltage', // 0xCF + 208: 'Input port 3 & 4 undervoltage', // 0xD0 + 209: 'Port 1 no input', // 0xD1 + 210: 'Port 2 no input', // 0xD2 + 211: 'Port 3 no input', // 0xD3 + 212: 'Port 4 no input', // 0xD4 + 213: 'PV-1 & PV-2 abnormal wiring', // 0xD5 + 214: 'PV-3 & PV-4 abnormal wiring', // 0xD6 + 215: 'PV-1 Input overvoltage', // 0xD7 + 216: 'PV-1 Input undervoltage', // 0xD8 + 217: 'PV-2 Input overvoltage', // 0xD9 + 218: 'PV-2 Input undervoltage', // 0xDA + 219: 'PV-3 Input overvoltage', // 0xDB + 220: 'PV-3 Input undervoltage', // 0xDC + 221: 'PV-4 Input overvoltage', // 0xDD + 222: 'PV-4 Input undervoltage', // 0xDE + 301: 'Hardware error code 301', // 0x012D + 302: 'Hardware error code 302', // 0x012E + 303: 'Hardware error code 303', // 0x012F + 304: 'Hardware error code 304', // 0x0130 + 305: 'Hardware error code 305', // 0x0131 + 306: 'Hardware error code 306', // 0x0132 + 307: 'Hardware error code 307', // 0x0133 + 308: 'Hardware error code 308', // 0x0134 + 309: 'Hardware error code 309', // 0x0135 + 310: 'Hardware error code 310', // 0x0136 + 311: 'Hardware error code 311', // 0x0137 + 312: 'Hardware error code 312', // 0x0138 + 313: 'Hardware error code 313', // 0x0139 + 314: 'Hardware error code 314', // 0x013A + // MI Error Codes + 5041: 'Error code-04 Port 1', // 0x13B1 + 5042: 'Error code-04 Port 2', // 0x13B2 + 5043: 'Error code-04 Port 3', // 0x13B3 + 5044: 'Error code-04 Port 4', // 0x13B4 + 5051: 'PV Input 1 Overvoltage/Undervoltage', // 0x13BB + 5052: 'PV Input 2 Overvoltage/Undervoltage', // 0x13BC + 5053: 'PV Input 3 Overvoltage/Undervoltage', // 0x13BD + 5054: 'PV Input 4 Overvoltage/Undervoltage', // 0x13BE + 5060: 'Abnormal bias', // 0x13C4 + 5070: 'Over temperature protection', // 0x13CE + 5080: 'Grid Overvoltage/Undervoltage', // 0x13D8 + 5090: 'Grid Overfrequency/Underfrequency', // 0x13E2 + 5100: 'Island detected', // 0x13EC + 5120: 'EEPROM reading and writing error', // 0x1400 + 5150: '10 min value grid overvoltage', // 0x141E + 5200: 'Firmware error', // 0x1450 + 8310: 'Shut down', // 0x2076 + 9000: 'Microinverter is suspected of being stolen' // 0x2328 } def __init__(self, *args, **params): From 6014e4f8509476257bd3b42139cfdfac74f02982 Mon Sep 17 00:00:00 2001 From: Kai Gerken Date: Fri, 29 Jul 2022 16:20:07 +0200 Subject: [PATCH 3/9] Add handling for responses with Frame ID 0x00 --- tools/esp8266/app.cpp | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/tools/esp8266/app.cpp b/tools/esp8266/app.cpp index dbb3ee9e..c1c3d78c 100644 --- a/tools/esp8266/app.cpp +++ b/tools/esp8266/app.cpp @@ -231,16 +231,20 @@ void app::loop(void) { Inverter<> *iv = mSys->findInverter(&p->packet[1]); if(NULL != iv) { uint8_t *pid = &p->packet[9]; - if((*pid & 0x7F) < 5) { - memcpy(mPayload[iv->id].data[(*pid & 0x7F) - 1], &p->packet[10], len-11); - mPayload[iv->id].len[(*pid & 0x7F) - 1] = len-11; - } + if (*pid == 0x00) { + DPRINT(DBG_DEBUG, "fragment number zero received and ignored"); + } else { + if((*pid & 0x7F) < 5) { + memcpy(mPayload[iv->id].data[(*pid & 0x7F) - 1], &p->packet[10], len-11); + mPayload[iv->id].len[(*pid & 0x7F) - 1] = len-11; + } - if((*pid & 0x80) == 0x80) { - if((*pid & 0x7f) > mPayload[iv->id].maxPackId) { - mPayload[iv->id].maxPackId = (*pid & 0x7f); - if(*pid > 0x81) - mLastPacketId = *pid; + if((*pid & 0x80) == 0x80) { + if((*pid & 0x7f) > mPayload[iv->id].maxPackId) { + mPayload[iv->id].maxPackId = (*pid & 0x7f); + if(*pid > 0x81) + mLastPacketId = *pid; + } } } } From 1a679130d8d99e17dd921cfa918083b4260fdcb8 Mon Sep 17 00:00:00 2001 From: stefan123t Date: Wed, 3 Aug 2022 18:58:45 +0200 Subject: [PATCH 4/9] fix #106 PubSubClient reconnect, which maintains a reference to char* mAddr --- tools/esp8266/mqtt.h | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/tools/esp8266/mqtt.h b/tools/esp8266/mqtt.h index 89570344..8af53d83 100644 --- a/tools/esp8266/mqtt.h +++ b/tools/esp8266/mqtt.h @@ -16,6 +16,7 @@ class mqtt { mClient = new PubSubClient(mEspClient); mAddressSet = false; + memset(mAddr, 0, MQTT_ADDR_LEN); memset(mUser, 0, MQTT_USER_LEN); memset(mPwd, 0, MQTT_PWD_LEN); memset(mTopic, 0, MQTT_TOPIC_LEN); @@ -23,13 +24,14 @@ class mqtt { ~mqtt() { } - void setup(const char *broker, const char *topic, const char *user, const char *pwd, uint16_t port) { + void setup(const char *addr, const char *topic, const char *user, const char *pwd, uint16_t port) { DPRINTLN(DBG_VERBOSE, F("mqtt.h:setup")); mAddressSet = true; - mClient->setServer(broker, port); + mClient->setServer(addr, port); mClient->setBufferSize(MQTT_MAX_PACKET_SIZE); mPort = port; + snprintf(mAddr, MQTT_ADDR_LEN, "%s", addr); snprintf(mUser, MQTT_USER_LEN, "%s", user); snprintf(mPwd, MQTT_PWD_LEN, "%s", pwd); snprintf(mTopic, MQTT_TOPIC_LEN, "%s", topic); @@ -58,6 +60,11 @@ class mqtt { return mClient->connected(); } + char *getAddr(void) { + //DPRINTLN(DBG_VERBOSE, F("mqtt.h:getAddr")); + return mAddr; + } + char *getUser(void) { //DPRINTLN(DBG_VERBOSE, F("mqtt.h:getUser")); return mUser; @@ -88,10 +95,12 @@ class mqtt { void reconnect(void) { //DPRINTLN(DBG_VERBOSE, F("mqtt.h:reconnect")); if(!mClient->connected()) { - if((strlen(mUser) > 0) && (strlen(mPwd) > 0)) - mClient->connect(DEF_DEVICE_NAME, mUser, mPwd); - else - mClient->connect(DEF_DEVICE_NAME); + if(strlen(mAddr) > 0) { + if((strlen(mUser) > 0) && (strlen(mPwd) > 0)) + mClient->connect(mAddr, mUser, mPwd); + else + mClient->connect(mAddr); + } } } @@ -100,6 +109,7 @@ class mqtt { bool mAddressSet; uint16_t mPort; + char mAddr[MQTT_ADDR_LEN]; char mUser[MQTT_USER_LEN]; char mPwd[MQTT_PWD_LEN]; char mTopic[MQTT_TOPIC_LEN]; From 7c6e0685625aea0573e18f85ce62829a71e1543a Mon Sep 17 00:00:00 2001 From: stefan123t Date: Wed, 3 Aug 2022 20:52:22 +0200 Subject: [PATCH 5/9] fix #112 switch both TX & RX channels in hmRadio.h --- tools/esp8266/app.cpp | 9 +++--- tools/esp8266/hmRadio.h | 71 ++++++++++++++++++++--------------------- 2 files changed, 40 insertions(+), 40 deletions(-) diff --git a/tools/esp8266/app.cpp b/tools/esp8266/app.cpp index dbb3ee9e..a9df4e75 100644 --- a/tools/esp8266/app.cpp +++ b/tools/esp8266/app.cpp @@ -124,8 +124,8 @@ void app::setup(uint32_t timeout) { // mqtt - char mqttAddr[MQTT_ADDR_LEN]; uint16_t mqttPort; + char mqttAddr[MQTT_ADDR_LEN]; char mqttUser[MQTT_USER_LEN]; char mqttPwd[MQTT_PWD_LEN]; char mqttTopic[MQTT_TOPIC_LEN]; @@ -209,9 +209,9 @@ void app::loop(void) { yield(); if(checkTicker(&mRxTicker, 5)) { - DPRINTLN(DBG_DEBUG, F("app_loops =") + String(app_loops)); + //DPRINTLN(DBG_VERBOSE, F("app_loops =") + String(app_loops)); app_loops=0; - DPRINT(DBG_DEBUG, F("a")); + DPRINT(DBG_VERBOSE, F("a")); bool rxRdy = mSys->Radio.switchRxCh(); @@ -222,7 +222,8 @@ void app::loop(void) { if(mSys->Radio.checkPaketCrc(p->packet, &len, p->rxCh)) { // process buffer only on first occurrence if(mSerialDebug) { - DPRINT(DBG_DEBUG, "Received " + String(len) + " bytes channel " + String(p->rxCh) + ": "); + DPRINT(DBG_INFO, "RX " + String(len) + "B Ch" + String(p->rxCh) + " | "); + mSys->Radio.dumpBuf(NULL, p->packet, len); } mFrameCnt++; diff --git a/tools/esp8266/hmRadio.h b/tools/esp8266/hmRadio.h index 18058e76..ebc6dcae 100644 --- a/tools/esp8266/hmRadio.h +++ b/tools/esp8266/hmRadio.h @@ -19,8 +19,8 @@ #define DTU_RADIO_ID ((uint64_t)0x1234567801ULL) #define DUMMY_RADIO_ID ((uint64_t)0xDEADBEEF01ULL) -#define RX_CHANNELS 5 -#define RX_LOOP_CNT 300 +#define RF_CHANNELS 5 +#define RF_LOOP_CNT 300 const char* const rf24AmpPower[] = {"MIN", "LOW", "HIGH", "MAX"}; @@ -56,18 +56,18 @@ class HmRadio { public: HmRadio() : mNrf24(CE_PIN, CS_PIN, SPI_SPEED) { DPRINTLN(DBG_VERBOSE, F("hmRadio.h : HmRadio():mNrf24(CE_PIN: ") + String(CE_PIN) + F(", CS_PIN: ") + String(CS_PIN) + F(", SPI_SPEED: ") + String(SPI_SPEED) + ")"); - mTxChLst[0] = 40; - //mTxChIdx = 1; // Depending on the program, the module can work on 2403, 2423, 2440, 2461 or 2475MHz. // Channel List 2403, 2423, 2440, 2461, 2475MHz - mRxChLst[0] = 03; - mRxChLst[1] = 23; - mRxChLst[2] = 40; - mRxChLst[3] = 61; - mRxChLst[4] = 75; - mRxChIdx = 0; - mRxLoopCnt = RX_LOOP_CNT; + mRfChLst[0] = 03; + mRfChLst[1] = 23; + mRfChLst[2] = 40; + mRfChLst[3] = 61; + mRfChLst[4] = 75; + + mTxChIdx = 2; // Start TX with 40 + mRxChIdx = 0; // Start RX with 03 + mRxLoopCnt = RF_LOOP_CNT; pinCs = CS_PIN; pinCe = CE_PIN; @@ -109,7 +109,7 @@ class HmRadio { DPRINTLN(DBG_INFO, F("Radio Config:")); mNrf24.printPrettyDetails(); - mTxCh = getDefaultChannel(); + mTxCh = setDefaultChannels(); if(!mNrf24.isChipConnected()) { DPRINTLN(DBG_WARN, F("WARNING! your NRF24 module can't be reached, check the wiring")); @@ -128,7 +128,7 @@ class HmRadio { while(mNrf24.available(&pipe)) { if(!mBufCtrl->full()) { p = mBufCtrl->getFront(); - p->rxCh = mRxChLst[mRxChIdx]; + p->rxCh = mRfChLst[mRxChIdx]; len = mNrf24.getPayloadSize(); if(len > MAX_RF_PAYLOAD_SIZE) len = MAX_RF_PAYLOAD_SIZE; @@ -152,20 +152,13 @@ class HmRadio { mIrqRcvd = true; } - uint8_t getDefaultChannel(void) { - //DPRINTLN(DBG_VERBOSE, F("hmRadio.h:getDefaultChannel")); - return mTxChLst[0]; - } - /*uint8_t getLastChannel(void) { - return mTxChLst[mTxChIdx]; + uint8_t setDefaultChannels(void) { + //DPRINTLN(DBG_VERBOSE, F("hmRadio.h:setDefaultChannels")); + mTxChIdx = 2; // Start TX with 40 + mRxChIdx = 0; // Start RX with 03 + return mRfChLst[mTxChIdx]; } - uint8_t getNxtChannel(void) { - if(++mTxChIdx >= 4) - mTxChIdx = 0; - return mTxChLst[mTxChIdx]; - }*/ - void sendTimePacket(uint64_t invId, uint32_t ts) { //DPRINTLN(DBG_VERBOSE, F("hmRadio.h:sendTimePacket")); sendCmdPacket(invId, 0x15, 0x80, false); @@ -257,7 +250,7 @@ class HmRadio { //DPRINTLN(DBG_VERBOSE, "sent packet: #" + String(mSendCnt)); //dumpBuf("SEN ", buf, len); if(mSerialDebug) { - DPRINT(DBG_INFO, "Transmit " + String(len) + " | "); + DPRINT(DBG_INFO, "TX " + String(len) + "B Ch" + String(mRfChLst[mTxChIdx]) + " | "); dumpBuf(NULL, buf, len); } @@ -265,10 +258,10 @@ class HmRadio { mNrf24.stopListening(); if(clear) - mRxLoopCnt = RX_LOOP_CNT; + mRxLoopCnt = RF_LOOP_CNT; - mTxCh = getDefaultChannel(); - mNrf24.setChannel(mTxCh); + mNrf24.setChannel(mRfChLst[mTxChIdx]); + mTxCh = getTxNxtChannel(); // switch channel for next packet mNrf24.openWritingPipe(invId); // TODO: deprecated mNrf24.setCRCLength(RF24_CRC_16); mNrf24.enableDynamicPayloads(); @@ -279,7 +272,7 @@ class HmRadio { // Try to avoid zero payload acks (has no effect) mNrf24.openWritingPipe(DUMMY_RADIO_ID); // TODO: why dummy radio id?, deprecated mRxChIdx = 0; - mNrf24.setChannel(mRxChLst[mRxChIdx]); + mNrf24.setChannel(mRfChLst[mRxChIdx]); mNrf24.setAutoAck(false); mNrf24.setRetries(0, 0); mNrf24.disableDynamicPayloads(); @@ -290,19 +283,25 @@ class HmRadio { mSendCnt++; } + uint8_t getTxNxtChannel(void) { + + if(++mTxChIdx >= RF_CHANNELS) + mTxChIdx = 0; + return mRfChLst[mTxChIdx]; + } + uint8_t getRxNxtChannel(void) { - if(++mRxChIdx >= RX_CHANNELS) + if(++mRxChIdx >= RF_CHANNELS) mRxChIdx = 0; - return mRxChLst[mRxChIdx]; + return mRfChLst[mRxChIdx]; } uint8_t mTxCh; - uint8_t mTxChLst[1]; - //uint8_t mTxChIdx; - - uint8_t mRxChLst[RX_CHANNELS]; + uint8_t mTxChIdx; + uint8_t mRfChLst[RF_CHANNELS]; + uint8_t mRxChIdx; uint16_t mRxLoopCnt; From 7e45c9299902edf1acbd14636e99a2cae74276a8 Mon Sep 17 00:00:00 2001 From: stefan123t Date: Wed, 3 Aug 2022 21:06:25 +0200 Subject: [PATCH 6/9] debug #106 add debug options as comments to platformio.ini --- tools/esp8266/platformio.ini | 74 ++++++++++++++++++++++++++++-------- 1 file changed, 59 insertions(+), 15 deletions(-) diff --git a/tools/esp8266/platformio.ini b/tools/esp8266/platformio.ini index 0728ec47..b9def408 100644 --- a/tools/esp8266/platformio.ini +++ b/tools/esp8266/platformio.ini @@ -1,3 +1,13 @@ +; PlatformIO Project Configuration File +; +; Build options: build flags, source filter +; Upload options: custom upload port, speed and extra flags +; Library options: dependencies, extra library storages +; Advanced options: extra scripting +; +; Please visit documentation for the other options and examples +; https://docs.platformio.org/page/projectconf.html + [platformio] src_dir = . @@ -5,33 +15,67 @@ src_dir = . platform = espressif8266 framework = arduino board = d1_mini -monitor_speed = 115200 board_build.f_cpu = 80000000L + +; ;;;;; Possible Debug options ;;;;;; +; https://docs.platformio.org/en/latest/platforms/espressif8266.html#debug-level ;build_flags = -DDEBUG_ESP_PORT=Serial + ;-DDEBUG_ESP_CORE + ;-DDEBUG_ESP_WIFI + ;-DDEBUG_ESP_HTTP_CLIENT + ;-DDEBUG_ESP_HTTP_SERVER + ;-DDEBUG_ESP_OOM + +monitor_speed = 115200 +monitor_filters = + ;default ; Remove typical terminal control codes from input + time ; Add timestamp with milliseconds for each new line + ;log2file ; Log data to a file “platformio-device-monitor-*.log” located in the current working directory -lib_deps = - nrf24/RF24@1.4.2 +lib_deps = + nrf24/RF24@1.4.2 paulstoffregen/Time@^1.6.1 knolleary/PubSubClient@^2.8 - bblanchon/ArduinoJson@^6.19.4 - ;esp8266/DNSServer@1.1.0 - ;esp8266/EEPROM@^1.0 - ;esp8266/ESP8266HTTPUpdateServer@^1.0 - ;esp8266/ESP8266WebServer@^1.0 - ;esp8266/ESP8266WiFi@^1.0 - ;esp8266/SPI@1.0 - ;esp8266/Ticker@^1.0 + bblanchon/ArduinoJson@^6.19.4 + ;esp8266/DNSServer@1.1.0 + ;esp8266/EEPROM@^1.0 + ;esp8266/ESP8266HTTPUpdateServer@^1.0 + ;esp8266/ESP8266WebServer@^1.0 + ;esp8266/ESP8266WiFi@^1.0 + ;esp8266/SPI@1.0 + ;esp8266/Ticker@^1.0 [env:node_mcu_v2] platform = espressif8266 framework = arduino board = nodemcuv2 -monitor_speed = 115200 board_build.f_cpu = 80000000L + +; ;;;;; Possible Debug options ;;;;;; +; https://docs.platformio.org/en/latest/platforms/espressif8266.html#debug-level +;build_flags = -DDEBUG_ESP_PORT=Serial + ;-DDEBUG_ESP_CORE + ;-DDEBUG_ESP_WIFI + ;-DDEBUG_ESP_HTTP_CLIENT + ;-DDEBUG_ESP_HTTP_SERVER + ;-DDEBUG_ESP_OOM + +monitor_speed = 115200 +monitor_filters = + ;default ; Remove typical terminal control codes from input + time ; Add timestamp with milliseconds for each new line + ;log2file ; Log data to a file “platformio-device-monitor-*.log” located in the current working directory upload_port = /dev/ttyUSB0 -lib_deps = - nrf24/RF24@1.4.2 +lib_deps = + nrf24/RF24@1.4.2 paulstoffregen/Time@^1.6.1 knolleary/PubSubClient@^2.8 - bblanchon/ArduinoJson@^6.19.4 + bblanchon/ArduinoJson@^6.19.4 + ;esp8266/DNSServer@1.1.0 + ;esp8266/EEPROM@^1.0 + ;esp8266/ESP8266HTTPUpdateServer@^1.0 + ;esp8266/ESP8266WebServer@^1.0 + ;esp8266/ESP8266WiFi@^1.0 + ;esp8266/SPI@1.0 + ;esp8266/Ticker@^1.0 From f657ace3284ae72d41debaa8841c8366261825eb Mon Sep 17 00:00:00 2001 From: stefan123t Date: Thu, 4 Aug 2022 00:58:46 +0200 Subject: [PATCH 7/9] fix #106 handpickled mDevName changes from #120 --- tools/esp8266/app.cpp | 17 ++++++++++----- tools/esp8266/mqtt.h | 51 +++++++++++++++++++++++++++---------------- 2 files changed, 43 insertions(+), 25 deletions(-) diff --git a/tools/esp8266/app.cpp b/tools/esp8266/app.cpp index d6014724..ebf5142d 100644 --- a/tools/esp8266/app.cpp +++ b/tools/esp8266/app.cpp @@ -129,12 +129,14 @@ void app::setup(uint32_t timeout) { char mqttUser[MQTT_USER_LEN]; char mqttPwd[MQTT_PWD_LEN]; char mqttTopic[MQTT_TOPIC_LEN]; - mEep->read(ADDR_MQTT_ADDR, mqttAddr, MQTT_ADDR_LEN); - mEep->read(ADDR_MQTT_USER, mqttUser, MQTT_USER_LEN); - mEep->read(ADDR_MQTT_PWD, mqttPwd, MQTT_PWD_LEN); - mEep->read(ADDR_MQTT_TOPIC, mqttTopic, MQTT_TOPIC_LEN); + char mqttDevName[DEVNAME_LEN]; + mEep->read(ADDR_MQTT_ADDR, mqttAddr, MQTT_ADDR_LEN); + mEep->read(ADDR_MQTT_USER, mqttUser, MQTT_USER_LEN); + mEep->read(ADDR_MQTT_PWD, mqttPwd, MQTT_PWD_LEN); + mEep->read(ADDR_MQTT_TOPIC, mqttTopic, MQTT_TOPIC_LEN); + mEep->read(ADDR_DEVNAME, mqttDevName, DEVNAME_LEN); //mEep->read(ADDR_MQTT_INTERVAL, &mMqttInterval); - mEep->read(ADDR_MQTT_PORT, &mqttPort); + mEep->read(ADDR_MQTT_PORT, &mqttPort); if(mqttAddr[0] > 0) { mMqttActive = true; @@ -147,13 +149,14 @@ void app::setup(uint32_t timeout) { if(0 == mqttPort) mqttPort = 1883; - mMqtt.setup(mqttAddr, mqttTopic, mqttUser, mqttPwd, mqttPort); + mMqtt.setup(mqttAddr, mqttTopic, mqttUser, mqttPwd, mqttDevName, mqttPort); mMqttTicker = 0; mSerialTicker = 0; if(mqttAddr[0] > 0) { char topic[30]; + mMqtt.sendMsg("device", mqttDevName); mMqtt.sendMsg("version", mVersion); for(uint8_t i = 0; i < MAX_NUM_INVERTERS; i ++) { iv = mSys->getInverterByPos(i); @@ -296,6 +299,7 @@ void app::loop(void) { Inverter<> *iv = mSys->getInverterByPos(id); if(NULL != iv) { if(iv->isAvailable(mTimestamp)) { + DPRINTLN(DBG_INFO, "Inverter: " + String(id)); for(uint8_t i = 0; i < iv->listLen; i++) { if(0.0f != iv->getValue(i)) { snprintf(topic, 30, "%s/ch%d/%s", iv->name, iv->assign[i].ch, iv->getFieldName(i)); @@ -304,6 +308,7 @@ void app::loop(void) { } yield(); } + DPRINTLN(DBG_INFO, ""); } } } diff --git a/tools/esp8266/mqtt.h b/tools/esp8266/mqtt.h index 8af53d83..e8aecb10 100644 --- a/tools/esp8266/mqtt.h +++ b/tools/esp8266/mqtt.h @@ -16,25 +16,28 @@ class mqtt { mClient = new PubSubClient(mEspClient); mAddressSet = false; - memset(mAddr, 0, MQTT_ADDR_LEN); - memset(mUser, 0, MQTT_USER_LEN); - memset(mPwd, 0, MQTT_PWD_LEN); - memset(mTopic, 0, MQTT_TOPIC_LEN); + memset(mBroker, 0, MQTT_ADDR_LEN); + memset(mUser, 0, MQTT_USER_LEN); + memset(mPwd, 0, MQTT_PWD_LEN); + memset(mTopic, 0, MQTT_TOPIC_LEN); + memset(mDevName, 0, DEVNAME_LEN); } ~mqtt() { } - void setup(const char *addr, const char *topic, const char *user, const char *pwd, uint16_t port) { + void setup(const char *broker, const char *topic, const char *user, const char *pwd, const char *devname, uint16_t port) { DPRINTLN(DBG_VERBOSE, F("mqtt.h:setup")); mAddressSet = true; - mClient->setServer(addr, port); - mClient->setBufferSize(MQTT_MAX_PACKET_SIZE); mPort = port; - snprintf(mAddr, MQTT_ADDR_LEN, "%s", addr); - snprintf(mUser, MQTT_USER_LEN, "%s", user); - snprintf(mPwd, MQTT_PWD_LEN, "%s", pwd); - snprintf(mTopic, MQTT_TOPIC_LEN, "%s", topic); + snprintf(mBroker, MQTT_ADDR_LEN, "%s", broker); + snprintf(mUser, MQTT_USER_LEN, "%s", user); + snprintf(mPwd, MQTT_PWD_LEN, "%s", pwd); + snprintf(mTopic, MQTT_TOPIC_LEN, "%s", topic); + snprintf(mDevName, DEVNAME_LEN, "%s", devname); + + mClient->setServer(mBroker, mPort); + mClient->setBufferSize(MQTT_MAX_PACKET_SIZE); } void sendMsg(const char *topic, const char *msg) { @@ -60,9 +63,9 @@ class mqtt { return mClient->connected(); } - char *getAddr(void) { - //DPRINTLN(DBG_VERBOSE, F("mqtt.h:getAddr")); - return mAddr; + char *getBroker(void) { + //DPRINTLN(DBG_VERBOSE, F("mqtt.h:getBroker")); + return mBroker; } char *getUser(void) { @@ -80,6 +83,11 @@ class mqtt { return mTopic; } + char *getDevName(void) { + //DPRINTLN(DBG_VERBOSE, F("mqtt.h:getDevName")); + return mDevName; + } + uint16_t getPort(void) { return mPort; } @@ -93,15 +101,19 @@ class mqtt { private: void reconnect(void) { - //DPRINTLN(DBG_VERBOSE, F("mqtt.h:reconnect")); + DPRINTLN(DBG_DEBUG, F("mqtt.h:reconnect")); + DPRINTLN(DBG_DEBUG, F("MQTT mClient->_state ") + String(mClient->state()) ); + DPRINTLN(DBG_DEBUG, F("WIFI mEspClient.status ") + String(mEspClient.status()) ); if(!mClient->connected()) { - if(strlen(mAddr) > 0) { + if(strlen(mDevName) > 0) { if((strlen(mUser) > 0) && (strlen(mPwd) > 0)) - mClient->connect(mAddr, mUser, mPwd); + mClient->connect(mDevName, mUser, mPwd); else - mClient->connect(mAddr); + mClient->connect(mDevName); } } + DPRINTLN(DBG_DEBUG, F("MQTT mClient->_state ") + String(mClient->state()) ); + DPRINTLN(DBG_DEBUG, F("WIFI mEspClient.status ") + String(mEspClient.status()) ); } WiFiClient mEspClient; @@ -109,10 +121,11 @@ class mqtt { bool mAddressSet; uint16_t mPort; - char mAddr[MQTT_ADDR_LEN]; + char mBroker[MQTT_ADDR_LEN]; char mUser[MQTT_USER_LEN]; char mPwd[MQTT_PWD_LEN]; char mTopic[MQTT_TOPIC_LEN]; + char mDevName[DEVNAME_LEN]; }; #endif /*__MQTT_H_*/ From 966a25bcd0c2772c24888487d4391fe9ac61c003 Mon Sep 17 00:00:00 2001 From: stefan123t Date: Thu, 4 Aug 2022 01:19:46 +0200 Subject: [PATCH 8/9] add mClient->setServer as suggested in #120 --- tools/esp8266/mqtt.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tools/esp8266/mqtt.h b/tools/esp8266/mqtt.h index e8aecb10..4a9d3509 100644 --- a/tools/esp8266/mqtt.h +++ b/tools/esp8266/mqtt.h @@ -106,6 +106,10 @@ class mqtt { DPRINTLN(DBG_DEBUG, F("WIFI mEspClient.status ") + String(mEspClient.status()) ); if(!mClient->connected()) { if(strlen(mDevName) > 0) { + // der Server und der Port müssen neu gesetzt werden, + // da ein MQTT_CONNECTION_LOST -3 die Werte zerstört hat. + mClient->setServer(mBroker, mPort); + mClient->setBufferSize(MQTT_MAX_PACKET_SIZE); if((strlen(mUser) > 0) && (strlen(mPwd) > 0)) mClient->connect(mDevName, mUser, mPwd); else From 375a1ca9553069b80a6928bb161b02041290e3e6 Mon Sep 17 00:00:00 2001 From: lumapu Date: Thu, 4 Aug 2022 07:31:36 +0200 Subject: [PATCH 9/9] increased version to 0.4.26 --- tools/esp8266/defines.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/esp8266/defines.h b/tools/esp8266/defines.h index c746930c..66c1d889 100644 --- a/tools/esp8266/defines.h +++ b/tools/esp8266/defines.h @@ -21,7 +21,7 @@ //------------------------------------- #define VERSION_MAJOR 0 #define VERSION_MINOR 4 -#define VERSION_PATCH 25 +#define VERSION_PATCH 26 //-------------------------------------