mirror of
https://github.com/lumapu/ahoy.git
synced 2025-05-28 16:26:12 +02:00
fix mqtt send all received records
renamed inverter address to serial number in setup
This commit is contained in:
parent
0ab382986b
commit
57b8a0abab
5 changed files with 126 additions and 118 deletions
|
@ -292,12 +292,11 @@ bool app::buildPayload(uint8_t id) {
|
|||
|
||||
//-----------------------------------------------------------------------------
|
||||
void app::processPayload(bool retransmit) {
|
||||
bool doMQTT = false;
|
||||
|
||||
// DPRINTLN(DBG_INFO, F("processPayload"));
|
||||
for (uint8_t id = 0; id < mSys->getNumInverters(); 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)) {
|
||||
// no processing needed if txId is not 0x95
|
||||
// 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 (!buildPayload(iv->id)) // payload not complete
|
||||
{
|
||||
if (mPayload[iv->id].requested) {
|
||||
if (retransmit) {
|
||||
if (!buildPayload(iv->id)) { // payload not complete
|
||||
if ((mPayload[iv->id].requested) && (retransmit)) {
|
||||
if (iv->devControlCmd == Restart || iv->devControlCmd == CleanState_LockAndAlarm) {
|
||||
// This is required to prevent retransmissions without answer.
|
||||
DPRINTLN(DBG_INFO, F("Prevent retransmit on Restart / CleanState_LockAndAlarm..."));
|
||||
|
@ -340,7 +337,6 @@ void app::processPayload(bool retransmit) {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else { // payload complete
|
||||
DPRINTLN(DBG_INFO, F("procPyld: cmd: ") + String(mPayload[iv->id].txCmd));
|
||||
DPRINTLN(DBG_INFO, F("procPyld: txid: 0x") + String(mPayload[iv->id].txId, HEX));
|
||||
|
@ -378,7 +374,7 @@ void app::processPayload(bool retransmit) {
|
|||
}
|
||||
iv->doCalculations();
|
||||
|
||||
doMQTT = true;
|
||||
mMqttSendList.push(mPayload[iv->id].txCmd);
|
||||
} else {
|
||||
DPRINTLN(DBG_ERROR, F("plausibility check failed, expected ") + String(rec->pyldLen) + F(" bytes"));
|
||||
mStat.rxFail++;
|
||||
|
@ -389,13 +385,13 @@ void app::processPayload(bool retransmit) {
|
|||
}
|
||||
|
||||
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
|
||||
// MQTT aussenden in 2 sek aktivieren
|
||||
if ((mMqttInterval != 0xffff) && doMQTT) {
|
||||
if ((mMqttInterval != 0xffff) && (!mMqttSendList.empty())) {
|
||||
mMqttTicker = mMqttInterval - 2;
|
||||
}
|
||||
}
|
||||
|
@ -529,8 +525,6 @@ void app::sendMqttDiscoveryConfig(void) {
|
|||
Inverter<> *iv = mSys->getInverterByPos(id);
|
||||
if (NULL != iv) {
|
||||
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);
|
||||
deviceDoc["name"] = iv->name;
|
||||
deviceDoc["ids"] = String(iv->serial.u64, HEX);
|
||||
|
@ -573,7 +567,6 @@ void app::sendMqttDiscoveryConfig(void) {
|
|||
mMqttConfigSendState[id] = true;
|
||||
|
||||
yield();
|
||||
//}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -589,11 +582,19 @@ void app::sendMqtt(void) {
|
|||
|
||||
mMqtt.sendMsg("uptime", val);
|
||||
|
||||
if(mMqttSendList.empty())
|
||||
return;
|
||||
|
||||
while(!mMqttSendList.empty()) {
|
||||
for (uint8_t id = 0; id < mSys->getNumInverters(); id++) {
|
||||
Inverter<> *iv = mSys->getInverterByPos(id);
|
||||
if (NULL != iv) {
|
||||
record_t<> *rec = iv->getRecordStruct(RealTimeRunData_Debug);
|
||||
if (NULL != iv)
|
||||
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;
|
||||
if (!iv->isAvailable(mUtcTimestamp, rec))
|
||||
status = MQTT_STATUS_NOT_AVAIL_NOT_PROD;
|
||||
|
@ -601,7 +602,6 @@ void app::sendMqtt(void) {
|
|||
if (MQTT_STATUS_AVAIL_PROD == status)
|
||||
status = MQTT_STATUS_AVAIL_NOT_PROD;
|
||||
}
|
||||
|
||||
snprintf(topic, 32 + MAX_NAME_LENGTH, "%s/available_text", iv->name);
|
||||
snprintf(val, 32, "%s%s%s%s",
|
||||
(MQTT_STATUS_NOT_AVAIL_NOT_PROD) ? "not " : "",
|
||||
|
@ -615,15 +615,19 @@ void app::sendMqtt(void) {
|
|||
snprintf(val, 32, "%d", status);
|
||||
mMqtt.sendMsg(topic, val);
|
||||
|
||||
if (iv->isAvailable(mUtcTimestamp, rec)) {
|
||||
snprintf(topic, 32 + MAX_NAME_LENGTH, "%s/last_success", iv->name);
|
||||
snprintf(val, 48, "%i", iv->getLastTs(rec) * 1000);
|
||||
mMqtt.sendMsg(topic, val);
|
||||
}
|
||||
|
||||
// data
|
||||
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(val, 10, "%.3f", iv->getValue(i, rec));
|
||||
mMqtt.sendMsg(topic, val);
|
||||
|
||||
// calculate total values for RealTimeRunData_Debug
|
||||
if (mMqttSendList.front() == RealTimeRunData_Debug) {
|
||||
if (CH0 == rec->assign[i].ch) {
|
||||
switch (rec->assign[i].fieldId) {
|
||||
case FLD_PAC:
|
||||
|
@ -640,13 +644,15 @@ void app::sendMqtt(void) {
|
|||
break;
|
||||
}
|
||||
}
|
||||
yield();
|
||||
}
|
||||
sendTotal = true;
|
||||
}
|
||||
yield();
|
||||
}
|
||||
}
|
||||
|
||||
mMqttSendList.pop(); // remove from list once all inverters were processed
|
||||
}
|
||||
|
||||
if (true == sendTotal) {
|
||||
uint8_t fieldId;
|
||||
for (uint8_t i = 0; i < 4; i++) {
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include "Arduino.h"
|
||||
|
||||
|
||||
#include <queue>
|
||||
#include <RF24.h>
|
||||
#include <RF24_config.h>
|
||||
#include <ArduinoJson.h>
|
||||
|
@ -287,6 +288,7 @@ class app {
|
|||
uint16_t mMqttInterval;
|
||||
bool mMqttActive;
|
||||
bool mMqttConfigSendState[MAX_NUM_INVERTERS];
|
||||
std::queue<uint8_t> mMqttSendList;
|
||||
|
||||
// serial
|
||||
uint16_t mSerialTicker;
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
//-------------------------------------
|
||||
#define VERSION_MAJOR 0
|
||||
#define VERSION_MINOR 5
|
||||
#define VERSION_PATCH 26
|
||||
#define VERSION_PATCH 27
|
||||
|
||||
|
||||
//-------------------------------------
|
||||
|
|
|
@ -242,7 +242,7 @@
|
|||
id = "inv" + id;
|
||||
|
||||
|
||||
iv.appendChild(lbl(id + "Addr", "Address*"));
|
||||
iv.appendChild(lbl(id + "Addr", "Serial Number (12 digits)*"));
|
||||
var addr = inp(id + "Addr", obj["serial"], 12)
|
||||
iv.appendChild(addr);
|
||||
['keyup', 'change'].forEach(function(evt) {
|
||||
|
|
|
@ -81,8 +81,8 @@ span.seperator {
|
|||
}
|
||||
|
||||
#footer {
|
||||
height: 120px;
|
||||
margin-top: -120px;
|
||||
height: 121px;
|
||||
margin-top: -121px;
|
||||
background-color: #555;
|
||||
width: 100%;
|
||||
font-size: 13px;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue