|
@ -292,12 +292,11 @@ bool app::buildPayload(uint8_t id) { |
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
//-----------------------------------------------------------------------------
|
|
|
void app::processPayload(bool retransmit) { |
|
|
void app::processPayload(bool retransmit) { |
|
|
bool doMQTT = false; |
|
|
|
|
|
|
|
|
|
|
|
// DPRINTLN(DBG_INFO, F("processPayload"));
|
|
|
|
|
|
for (uint8_t id = 0; id < mSys->getNumInverters(); id++) { |
|
|
for (uint8_t id = 0; id < mSys->getNumInverters(); id++) { |
|
|
Inverter<> *iv = mSys->getInverterByPos(id); |
|
|
Inverter<> *iv = mSys->getInverterByPos(id); |
|
|
if (NULL != iv) { |
|
|
if (NULL != iv) |
|
|
|
|
|
break; // skip to next inverter
|
|
|
|
|
|
|
|
|
if ((mPayload[iv->id].txId != (TX_REQ_INFO + ALL_FRAMES)) && (0 != mPayload[iv->id].txId)) { |
|
|
if ((mPayload[iv->id].txId != (TX_REQ_INFO + ALL_FRAMES)) && (0 != mPayload[iv->id].txId)) { |
|
|
// no processing needed if txId is not 0x95
|
|
|
// no processing needed if txId is not 0x95
|
|
|
// DPRINTLN(DBG_INFO, F("processPayload - set complete, txId: ") + String(mPayload[iv->id].txId, HEX));
|
|
|
// DPRINTLN(DBG_INFO, F("processPayload - set complete, txId: ") + String(mPayload[iv->id].txId, HEX));
|
|
@ -305,10 +304,8 @@ void app::processPayload(bool retransmit) { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (!mPayload[iv->id].complete) { |
|
|
if (!mPayload[iv->id].complete) { |
|
|
if (!buildPayload(iv->id)) // payload not complete
|
|
|
if (!buildPayload(iv->id)) { // payload not complete
|
|
|
{ |
|
|
if ((mPayload[iv->id].requested) && (retransmit)) { |
|
|
if (mPayload[iv->id].requested) { |
|
|
|
|
|
if (retransmit) { |
|
|
|
|
|
if (iv->devControlCmd == Restart || iv->devControlCmd == CleanState_LockAndAlarm) { |
|
|
if (iv->devControlCmd == Restart || iv->devControlCmd == CleanState_LockAndAlarm) { |
|
|
// This is required to prevent retransmissions without answer.
|
|
|
// This is required to prevent retransmissions without answer.
|
|
|
DPRINTLN(DBG_INFO, F("Prevent retransmit on Restart / CleanState_LockAndAlarm...")); |
|
|
DPRINTLN(DBG_INFO, F("Prevent retransmit on Restart / CleanState_LockAndAlarm...")); |
|
@ -340,7 +337,6 @@ void app::processPayload(bool retransmit) { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
} else { // payload complete
|
|
|
} else { // payload complete
|
|
|
DPRINTLN(DBG_INFO, F("procPyld: cmd: ") + String(mPayload[iv->id].txCmd)); |
|
|
DPRINTLN(DBG_INFO, F("procPyld: cmd: ") + String(mPayload[iv->id].txCmd)); |
|
|
DPRINTLN(DBG_INFO, F("procPyld: txid: 0x") + String(mPayload[iv->id].txId, HEX)); |
|
|
DPRINTLN(DBG_INFO, F("procPyld: txid: 0x") + String(mPayload[iv->id].txId, HEX)); |
|
@ -378,7 +374,7 @@ void app::processPayload(bool retransmit) { |
|
|
} |
|
|
} |
|
|
iv->doCalculations(); |
|
|
iv->doCalculations(); |
|
|
|
|
|
|
|
|
doMQTT = true; |
|
|
mMqttSendList.push(mPayload[iv->id].txCmd); |
|
|
} else { |
|
|
} else { |
|
|
DPRINTLN(DBG_ERROR, F("plausibility check failed, expected ") + String(rec->pyldLen) + F(" bytes")); |
|
|
DPRINTLN(DBG_ERROR, F("plausibility check failed, expected ") + String(rec->pyldLen) + F(" bytes")); |
|
|
mStat.rxFail++; |
|
|
mStat.rxFail++; |
|
@ -389,13 +385,13 @@ void app::processPayload(bool retransmit) { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
yield(); |
|
|
yield(); |
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// ist MQTT aktiviert und es wurden Daten vom einem oder mehreren WR aufbereitet ( doMQTT = true)
|
|
|
// ist MQTT aktiviert und es wurden Daten vom einem oder mehreren WR aufbereitet
|
|
|
// dann die den mMqttTicker auf mMqttIntervall -2 setzen, also
|
|
|
// dann die den mMqttTicker auf mMqttIntervall -2 setzen, also
|
|
|
// MQTT aussenden in 2 sek aktivieren
|
|
|
// MQTT aussenden in 2 sek aktivieren
|
|
|
if ((mMqttInterval != 0xffff) && doMQTT) { |
|
|
if ((mMqttInterval != 0xffff) && (!mMqttSendList.empty())) { |
|
|
mMqttTicker = mMqttInterval - 2; |
|
|
mMqttTicker = mMqttInterval - 2; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
@ -529,8 +525,6 @@ void app::sendMqttDiscoveryConfig(void) { |
|
|
Inverter<> *iv = mSys->getInverterByPos(id); |
|
|
Inverter<> *iv = mSys->getInverterByPos(id); |
|
|
if (NULL != iv) { |
|
|
if (NULL != iv) { |
|
|
record_t<> *rec = iv->getRecordStruct(RealTimeRunData_Debug); |
|
|
record_t<> *rec = iv->getRecordStruct(RealTimeRunData_Debug); |
|
|
// TODO: next line makes no sense if discovery config is send manually by button
|
|
|
|
|
|
// if(iv->isAvailable(mUtcTimestamp, rec) && mMqttConfigSendState[id] != true) {
|
|
|
|
|
|
DynamicJsonDocument deviceDoc(128); |
|
|
DynamicJsonDocument deviceDoc(128); |
|
|
deviceDoc["name"] = iv->name; |
|
|
deviceDoc["name"] = iv->name; |
|
|
deviceDoc["ids"] = String(iv->serial.u64, HEX); |
|
|
deviceDoc["ids"] = String(iv->serial.u64, HEX); |
|
@ -573,7 +567,6 @@ void app::sendMqttDiscoveryConfig(void) { |
|
|
mMqttConfigSendState[id] = true; |
|
|
mMqttConfigSendState[id] = true; |
|
|
|
|
|
|
|
|
yield(); |
|
|
yield(); |
|
|
//}
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
@ -589,11 +582,19 @@ void app::sendMqtt(void) { |
|
|
|
|
|
|
|
|
mMqtt.sendMsg("uptime", val); |
|
|
mMqtt.sendMsg("uptime", val); |
|
|
|
|
|
|
|
|
|
|
|
if(mMqttSendList.empty()) |
|
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
|
|
while(!mMqttSendList.empty()) { |
|
|
for (uint8_t id = 0; id < mSys->getNumInverters(); id++) { |
|
|
for (uint8_t id = 0; id < mSys->getNumInverters(); id++) { |
|
|
Inverter<> *iv = mSys->getInverterByPos(id); |
|
|
Inverter<> *iv = mSys->getInverterByPos(id); |
|
|
if (NULL != iv) { |
|
|
if (NULL != iv) |
|
|
record_t<> *rec = iv->getRecordStruct(RealTimeRunData_Debug); |
|
|
break; // skip to next inverter
|
|
|
|
|
|
|
|
|
|
|
|
record_t<> *rec = iv->getRecordStruct(mMqttSendList.front()); |
|
|
|
|
|
|
|
|
|
|
|
if(mMqttSendList.front() == RealTimeRunData_Debug) { |
|
|
|
|
|
// inverter status
|
|
|
uint8_t status = MQTT_STATUS_AVAIL_PROD; |
|
|
uint8_t status = MQTT_STATUS_AVAIL_PROD; |
|
|
if (!iv->isAvailable(mUtcTimestamp, rec)) |
|
|
if (!iv->isAvailable(mUtcTimestamp, rec)) |
|
|
status = MQTT_STATUS_NOT_AVAIL_NOT_PROD; |
|
|
status = MQTT_STATUS_NOT_AVAIL_NOT_PROD; |
|
@ -601,7 +602,6 @@ void app::sendMqtt(void) { |
|
|
if (MQTT_STATUS_AVAIL_PROD == status) |
|
|
if (MQTT_STATUS_AVAIL_PROD == status) |
|
|
status = MQTT_STATUS_AVAIL_NOT_PROD; |
|
|
status = MQTT_STATUS_AVAIL_NOT_PROD; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
snprintf(topic, 32 + MAX_NAME_LENGTH, "%s/available_text", iv->name); |
|
|
snprintf(topic, 32 + MAX_NAME_LENGTH, "%s/available_text", iv->name); |
|
|
snprintf(val, 32, "%s%s%s%s", |
|
|
snprintf(val, 32, "%s%s%s%s", |
|
|
(MQTT_STATUS_NOT_AVAIL_NOT_PROD) ? "not " : "", |
|
|
(MQTT_STATUS_NOT_AVAIL_NOT_PROD) ? "not " : "", |
|
@ -615,15 +615,19 @@ void app::sendMqtt(void) { |
|
|
snprintf(val, 32, "%d", status); |
|
|
snprintf(val, 32, "%d", status); |
|
|
mMqtt.sendMsg(topic, val); |
|
|
mMqtt.sendMsg(topic, val); |
|
|
|
|
|
|
|
|
if (iv->isAvailable(mUtcTimestamp, rec)) { |
|
|
|
|
|
snprintf(topic, 32 + MAX_NAME_LENGTH, "%s/last_success", iv->name); |
|
|
snprintf(topic, 32 + MAX_NAME_LENGTH, "%s/last_success", iv->name); |
|
|
snprintf(val, 48, "%i", iv->getLastTs(rec) * 1000); |
|
|
snprintf(val, 48, "%i", iv->getLastTs(rec) * 1000); |
|
|
mMqtt.sendMsg(topic, val); |
|
|
mMqtt.sendMsg(topic, val); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// data
|
|
|
for (uint8_t i = 0; i < rec->length; i++) { |
|
|
for (uint8_t i = 0; i < rec->length; i++) { |
|
|
snprintf(topic, 32 + MAX_NAME_LENGTH, "%s/ch%d/%s", iv->name, rec->assign[i].ch, fields[rec->assign[i].fieldId]); |
|
|
snprintf(topic, 32 + MAX_NAME_LENGTH, "%s/ch%d/%s", iv->name, rec->assign[i].ch, fields[rec->assign[i].fieldId]); |
|
|
snprintf(val, 10, "%.3f", iv->getValue(i, rec)); |
|
|
snprintf(val, 10, "%.3f", iv->getValue(i, rec)); |
|
|
mMqtt.sendMsg(topic, val); |
|
|
mMqtt.sendMsg(topic, val); |
|
|
|
|
|
|
|
|
|
|
|
// calculate total values for RealTimeRunData_Debug
|
|
|
|
|
|
if (mMqttSendList.front() == RealTimeRunData_Debug) { |
|
|
if (CH0 == rec->assign[i].ch) { |
|
|
if (CH0 == rec->assign[i].ch) { |
|
|
switch (rec->assign[i].fieldId) { |
|
|
switch (rec->assign[i].fieldId) { |
|
|
case FLD_PAC: |
|
|
case FLD_PAC: |
|
@ -640,13 +644,15 @@ void app::sendMqtt(void) { |
|
|
break; |
|
|
break; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
yield(); |
|
|
|
|
|
} |
|
|
|
|
|
sendTotal = true; |
|
|
sendTotal = true; |
|
|
} |
|
|
} |
|
|
|
|
|
yield(); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
mMqttSendList.pop(); // remove from list once all inverters were processed
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
if (true == sendTotal) { |
|
|
if (true == sendTotal) { |
|
|
uint8_t fieldId; |
|
|
uint8_t fieldId; |
|
|
for (uint8_t i = 0; i < 4; i++) { |
|
|
for (uint8_t i = 0; i < 4; i++) { |
|
|