From 97dfbb593620640e05d3c896507e43458f8cdbc9 Mon Sep 17 00:00:00 2001 From: lumapu Date: Sun, 24 Apr 2022 11:45:56 +0200 Subject: [PATCH] * communication works again * reordered HM1200 values (for Serial print) --- tools/esp8266/app.cpp | 41 +++++++++++++++++++++++++------------ tools/esp8266/app.h | 1 + tools/esp8266/defines.h | 2 +- tools/esp8266/esp8266.ino | 1 + tools/esp8266/hmInverters.h | 22 ++++++++++---------- tools/esp8266/hmRadio.h | 12 ++++++----- 6 files changed, 49 insertions(+), 30 deletions(-) diff --git a/tools/esp8266/app.cpp b/tools/esp8266/app.cpp index aa05324a..4f1c1e3d 100644 --- a/tools/esp8266/app.cpp +++ b/tools/esp8266/app.cpp @@ -130,10 +130,25 @@ void app::loop(void) { uint8_t size = 0; inverter_t *inv = mSys->getInverterByPos(0); - size = mSys->Radio.getTimePacket(&inv->radioId.u64, mSendBuf, mTimestamp); + + + //if((mSendCnt % 6) == 0) + size = mSys->Radio.getTimePacket(&inv->radioId.u64, mSendBuf, mTimestamp); + /*else if((mSendCnt % 6) == 1) + size = mSys->Radio.getCmdPacket(&inv->radioId.u64, mSendBuf, 0x15, 0x81); + else if((mSendCnt % 6) == 2) + size = mSys->Radio.getCmdPacket(&inv->radioId.u64, mSendBuf, 0x15, 0x80); + else if((mSendCnt % 6) == 3) + size = mSys->Radio.getCmdPacket(&inv->radioId.u64, mSendBuf, 0x15, 0x83); + else if((mSendCnt % 6) == 4) + size = mSys->Radio.getCmdPacket(&inv->radioId.u64, mSendBuf, 0x15, 0x82); + else if((mSendCnt % 6) == 5) + size = mSys->Radio.getCmdPacket(&inv->radioId.u64, mSendBuf, 0x15, 0x84);*/ + + //Serial.println("sent packet: #" + String(mSendCnt)); - //dumpBuf(mSendBuf, size); + //dumpBuf("SEN ", mSendBuf, size); sendPacket(inv, mSendBuf, size); mSendCnt++; @@ -141,36 +156,36 @@ void app::loop(void) { // mqtt - //mMqtt.loop(); + mMqtt.loop(); if(mMqttEvt) { mMqttEvt = false; - /*mMqtt.isConnected(true); - char topic[20], val[10]; + mMqtt.isConnected(true); + char topic[30], val[10]; for(uint8_t id = 0; id < mSys->getNumInverters(); id++) { inverter_t *iv = mSys->getInverterByPos(id); if(NULL != iv) { for(uint8_t i = 0; i < iv->listLen; i++) { if(0.0f != mSys->getValue(iv, i)) { - sprintf(topic, "%s/ch%d/%s", iv->name, iv->assign[i].ch, fields[iv->assign[i].fieldId]); - sprintf(val, "%.3f", mSys->getValue(iv, i)); + snprintf(topic, 30, "%s/ch%d/%s", iv->name, iv->assign[i].ch, fields[iv->assign[i].fieldId]); + snprintf(val, 10, "%.3f", mSys->getValue(iv, i)); mMqtt.sendMsg(topic, val); delay(10); } } } - }*/ + } // Serial debug - char topic[20], val[10]; + //char topic[30], val[10]; for(uint8_t id = 0; id < mSys->getNumInverters(); id++) { inverter_t *iv = mSys->getInverterByPos(id); if(NULL != iv) { for(uint8_t i = 0; i < iv->listLen; i++) { - //if(0.0f != mSys->getValue(iv, i)) { - sprintf(topic, "%s/ch%d/%s", iv->name, iv->assign[i].ch, mSys->getFieldName(iv, i)); - sprintf(val, "%.3f %s", mSys->getValue(iv, i), mSys->getUnit(iv, i)); + if(0.0f != mSys->getValue(iv, i)) { + snprintf(topic, 30, "%s/ch%d/%s", iv->name, iv->assign[i].ch, mSys->getFieldName(iv, i)); + snprintf(val, 10, "%.3f %s", mSys->getValue(iv, i), mSys->getUnit(iv, i)); Serial.println(String(topic) + ": " + String(val)); - //} + } } } } diff --git a/tools/esp8266/app.h b/tools/esp8266/app.h index 80aba5f6..977d0b41 100644 --- a/tools/esp8266/app.h +++ b/tools/esp8266/app.h @@ -81,6 +81,7 @@ class app : public Main { uint32_t mCmds[6]; uint32_t mChannelStat[4]; + uint32_t mRecCnt; // mqtt mqtt mMqtt; diff --git a/tools/esp8266/defines.h b/tools/esp8266/defines.h index adc4ac80..f1f5b121 100644 --- a/tools/esp8266/defines.h +++ b/tools/esp8266/defines.h @@ -23,7 +23,7 @@ //------------------------------------- #define VERSION_MAJOR 0 #define VERSION_MINOR 2 -#define VERSION_PATCH 1 +#define VERSION_PATCH 2 //------------------------------------- diff --git a/tools/esp8266/esp8266.ino b/tools/esp8266/esp8266.ino index 86c413d3..5bb82995 100644 --- a/tools/esp8266/esp8266.ino +++ b/tools/esp8266/esp8266.ino @@ -13,6 +13,7 @@ app myApp; //----------------------------------------------------------------------------- void setup() { + // TODO: move to HmRadio pinMode(RF24_IRQ_PIN, INPUT_PULLUP); attachInterrupt(digitalPinToInterrupt(RF24_IRQ_PIN), handleIntr, FALLING); diff --git a/tools/esp8266/hmInverters.h b/tools/esp8266/hmInverters.h index e1f6d86c..44c89669 100644 --- a/tools/esp8266/hmInverters.h +++ b/tools/esp8266/hmInverters.h @@ -83,26 +83,26 @@ const byteAssign_t hm600assignment[] = { const byteAssign_t hm1200assignment[] = { { FLD_UDC, UNIT_V, CH1, CMD01, 3, 2, 10 }, { FLD_IDC, UNIT_A, CH1, CMD01, 5, 2, 100 }, - { FLD_IDC, UNIT_A, CH2, CMD01, 7, 2, 100 }, { FLD_PDC, UNIT_W, CH1, CMD01, 9, 2, 10 }, - { FLD_PDC, UNIT_W, CH2, CMD01, 11, 2, 10 }, - { FLD_YT, UNIT_KWH, CH1, CMD01, 13, 4, 1000 }, - { FLD_YT, UNIT_KWH, CH2, CMD02, 1, 4, 1000 }, { FLD_YD, UNIT_WH, CH1, CMD02, 5, 2, 1 }, - { FLD_YD, UNIT_WH, CH2, CMD02, 7, 2, 1 }, + { FLD_YT, UNIT_KWH, CH1, CMD01, 13, 4, 1000 }, { FLD_UDC, UNIT_V, CH2, CMD02, 9, 2, 10 }, + { FLD_IDC, UNIT_A, CH2, CMD01, 7, 2, 100 }, + { FLD_PDC, UNIT_W, CH2, CMD01, 11, 2, 10 }, + { FLD_YD, UNIT_WH, CH2, CMD02, 7, 2, 1 }, + { FLD_YT, UNIT_KWH, CH2, CMD02, 1, 4, 1000 }, { FLD_IDC, UNIT_A, CH3, CMD02, 11, 2, 100 }, - { FLD_IDC, UNIT_A, CH4, CMD02, 13, 2, 100 }, { FLD_PDC, UNIT_W, CH3, CMD02, 15, 2, 10 }, - { FLD_PDC, UNIT_W, CH4, CMD03, 1, 2, 10 }, - { FLD_YT, UNIT_KWH, CH3, CMD03, 3, 4, 1000 }, - { FLD_YT, UNIT_KWH, CH4, CMD03, 7, 4, 1000 }, { FLD_YD, UNIT_WH, CH3, CMD03, 11, 2, 1 }, + { FLD_YT, UNIT_KWH, CH3, CMD03, 3, 4, 1000 }, + { FLD_IDC, UNIT_A, CH4, CMD02, 13, 2, 100 }, + { FLD_PDC, UNIT_W, CH4, CMD03, 1, 2, 10 }, { FLD_YD, UNIT_WH, CH4, CMD03, 13, 2, 1 }, + { FLD_YT, UNIT_KWH, CH4, CMD03, 7, 4, 1000 }, { FLD_UAC, UNIT_V, CH0, CMD03, 15, 2, 10 }, - { FLD_F, UNIT_HZ, CH0, CMD84, 1, 2, 100 }, - { FLD_PAC, UNIT_W, CH0, CMD84, 3, 2, 10 }, { FLD_IAC, UNIT_A, CH0, CMD84, 7, 2, 100 }, + { FLD_PAC, UNIT_W, CH0, CMD84, 3, 2, 10 }, + { FLD_F, UNIT_HZ, CH0, CMD84, 1, 2, 100 }, { FLD_PCT, UNIT_PCT, CH0, CMD84, 9, 2, 10 }, { FLD_T, UNIT_C, CH0, CMD84, 11, 2, 10 } }; diff --git a/tools/esp8266/hmRadio.h b/tools/esp8266/hmRadio.h index 0f8e39a6..05264d4a 100644 --- a/tools/esp8266/hmRadio.h +++ b/tools/esp8266/hmRadio.h @@ -5,7 +5,7 @@ #include #include "crc.h" -#define CHANNEL_HOP // switch between channels or use static channel to send +//#define CHANNEL_HOP // switch between channels or use static channel to send #define DEFAULT_RECV_CHANNEL 3 #define MAX_RF_PAYLOAD_SIZE 64 @@ -42,7 +42,7 @@ template > 8)); - CP_U32_BigEndian(&buf[5], (DTU_ID >> 8)); + CP_U32_BigEndian(&buf[1], ((*invId) >> 8)); + CP_U32_BigEndian(&buf[5], (DTU_ID >> 8)); buf[9] = cmd; if(calcCrc) buf[10] = crc8(buf, 10); @@ -116,7 +118,7 @@ class HmRadio { } protected: - void getDtuIdCrc(void) { + void calcDtuCrc(void) { uint64_t addr = DTU_RADIO_ID; uint8_t tmp[5]; for(int8_t i = 4; i >= 0; i--) {