Browse Source

* communication works again

* reordered HM1200 values (for Serial print)
pull/8/head
lumapu 3 years ago
parent
commit
97dfbb5936
  1. 41
      tools/esp8266/app.cpp
  2. 1
      tools/esp8266/app.h
  3. 2
      tools/esp8266/defines.h
  4. 1
      tools/esp8266/esp8266.ino
  5. 22
      tools/esp8266/hmInverters.h
  6. 12
      tools/esp8266/hmRadio.h

41
tools/esp8266/app.cpp

@ -130,10 +130,25 @@ void app::loop(void) {
uint8_t size = 0; uint8_t size = 0;
inverter_t *inv = mSys->getInverterByPos(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)); //Serial.println("sent packet: #" + String(mSendCnt));
//dumpBuf(mSendBuf, size); //dumpBuf("SEN ", mSendBuf, size);
sendPacket(inv, mSendBuf, size); sendPacket(inv, mSendBuf, size);
mSendCnt++; mSendCnt++;
@ -141,36 +156,36 @@ void app::loop(void) {
// mqtt // mqtt
//mMqtt.loop(); mMqtt.loop();
if(mMqttEvt) { if(mMqttEvt) {
mMqttEvt = false; mMqttEvt = false;
/*mMqtt.isConnected(true); mMqtt.isConnected(true);
char topic[20], val[10]; char topic[30], val[10];
for(uint8_t id = 0; id < mSys->getNumInverters(); id++) { for(uint8_t id = 0; id < mSys->getNumInverters(); id++) {
inverter_t *iv = mSys->getInverterByPos(id); inverter_t *iv = mSys->getInverterByPos(id);
if(NULL != iv) { if(NULL != iv) {
for(uint8_t i = 0; i < iv->listLen; i++) { for(uint8_t i = 0; i < iv->listLen; i++) {
if(0.0f != mSys->getValue(iv, 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]); snprintf(topic, 30, "%s/ch%d/%s", iv->name, iv->assign[i].ch, fields[iv->assign[i].fieldId]);
sprintf(val, "%.3f", mSys->getValue(iv, i)); snprintf(val, 10, "%.3f", mSys->getValue(iv, i));
mMqtt.sendMsg(topic, val); mMqtt.sendMsg(topic, val);
delay(10); delay(10);
} }
} }
} }
}*/ }
// Serial debug // Serial debug
char topic[20], val[10]; //char topic[30], val[10];
for(uint8_t id = 0; id < mSys->getNumInverters(); id++) { for(uint8_t id = 0; id < mSys->getNumInverters(); id++) {
inverter_t *iv = mSys->getInverterByPos(id); inverter_t *iv = mSys->getInverterByPos(id);
if(NULL != iv) { if(NULL != iv) {
for(uint8_t i = 0; i < iv->listLen; i++) { for(uint8_t i = 0; i < iv->listLen; i++) {
//if(0.0f != mSys->getValue(iv, i)) { if(0.0f != mSys->getValue(iv, i)) {
sprintf(topic, "%s/ch%d/%s", iv->name, iv->assign[i].ch, mSys->getFieldName(iv, i)); snprintf(topic, 30, "%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)); snprintf(val, 10, "%.3f %s", mSys->getValue(iv, i), mSys->getUnit(iv, i));
Serial.println(String(topic) + ": " + String(val)); Serial.println(String(topic) + ": " + String(val));
//} }
} }
} }
} }

1
tools/esp8266/app.h

@ -81,6 +81,7 @@ class app : public Main {
uint32_t mCmds[6]; uint32_t mCmds[6];
uint32_t mChannelStat[4]; uint32_t mChannelStat[4];
uint32_t mRecCnt;
// mqtt // mqtt
mqtt mMqtt; mqtt mMqtt;

2
tools/esp8266/defines.h

@ -23,7 +23,7 @@
//------------------------------------- //-------------------------------------
#define VERSION_MAJOR 0 #define VERSION_MAJOR 0
#define VERSION_MINOR 2 #define VERSION_MINOR 2
#define VERSION_PATCH 1 #define VERSION_PATCH 2
//------------------------------------- //-------------------------------------

1
tools/esp8266/esp8266.ino

@ -13,6 +13,7 @@ app myApp;
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void setup() { void setup() {
// TODO: move to HmRadio
pinMode(RF24_IRQ_PIN, INPUT_PULLUP); pinMode(RF24_IRQ_PIN, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(RF24_IRQ_PIN), handleIntr, FALLING); attachInterrupt(digitalPinToInterrupt(RF24_IRQ_PIN), handleIntr, FALLING);

22
tools/esp8266/hmInverters.h

@ -83,26 +83,26 @@ const byteAssign_t hm600assignment[] = {
const byteAssign_t hm1200assignment[] = { const byteAssign_t hm1200assignment[] = {
{ FLD_UDC, UNIT_V, CH1, CMD01, 3, 2, 10 }, { FLD_UDC, UNIT_V, CH1, CMD01, 3, 2, 10 },
{ FLD_IDC, UNIT_A, CH1, CMD01, 5, 2, 100 }, { 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, 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, 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_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, 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, 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_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_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_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_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_PCT, UNIT_PCT, CH0, CMD84, 9, 2, 10 },
{ FLD_T, UNIT_C, CH0, CMD84, 11, 2, 10 } { FLD_T, UNIT_C, CH0, CMD84, 11, 2, 10 }
}; };

12
tools/esp8266/hmRadio.h

@ -5,7 +5,7 @@
#include <RF24_config.h> #include <RF24_config.h>
#include "crc.h" #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 DEFAULT_RECV_CHANNEL 3
#define MAX_RF_PAYLOAD_SIZE 64 #define MAX_RF_PAYLOAD_SIZE 64
@ -42,7 +42,7 @@ template <uint8_t CE_PIN, uint8_t CS_PIN, uint8_t IRQ_PIN, uint64_t DTU_ID=DTU_R
class HmRadio { class HmRadio {
public: public:
HmRadio() { HmRadio() {
pinMode(IRQ_PIN, INPUT_PULLUP); //pinMode(IRQ_PIN, INPUT_PULLUP);
//attachInterrupt(digitalPinToInterrupt(IRQ_PIN), handleIntr, FALLING); //attachInterrupt(digitalPinToInterrupt(IRQ_PIN), handleIntr, FALLING);
mSendChan[0] = 23; mSendChan[0] = 23;
@ -50,6 +50,8 @@ class HmRadio {
mSendChan[2] = 61; mSendChan[2] = 61;
mSendChan[3] = 75; mSendChan[3] = 75;
mChanIdx = 1; mChanIdx = 1;
calcDtuCrc();
} }
~HmRadio() {} ~HmRadio() {}
@ -84,8 +86,8 @@ class HmRadio {
uint8_t getCmdPacket(const uint64_t *invId, uint8_t buf[], uint8_t mid, uint8_t cmd, bool calcCrc = true) { uint8_t getCmdPacket(const uint64_t *invId, uint8_t buf[], uint8_t mid, uint8_t cmd, bool calcCrc = true) {
memset(buf, 0, MAX_RF_PAYLOAD_SIZE); memset(buf, 0, MAX_RF_PAYLOAD_SIZE);
buf[0] = mid; // message id buf[0] = mid; // message id
CP_U32_BigEndian(&buf[1], (*invId >> 8)); CP_U32_BigEndian(&buf[1], ((*invId) >> 8));
CP_U32_BigEndian(&buf[5], (DTU_ID >> 8)); CP_U32_BigEndian(&buf[5], (DTU_ID >> 8));
buf[9] = cmd; buf[9] = cmd;
if(calcCrc) if(calcCrc)
buf[10] = crc8(buf, 10); buf[10] = crc8(buf, 10);
@ -116,7 +118,7 @@ class HmRadio {
} }
protected: protected:
void getDtuIdCrc(void) { void calcDtuCrc(void) {
uint64_t addr = DTU_RADIO_ID; uint64_t addr = DTU_RADIO_ID;
uint8_t tmp[5]; uint8_t tmp[5];
for(int8_t i = 4; i >= 0; i--) { for(int8_t i = 4; i >= 0; i--) {

Loading…
Cancel
Save