From 8ead358f4cd4602e00a7f6fc38df8118f2e4f928 Mon Sep 17 00:00:00 2001 From: lumapu Date: Thu, 27 Apr 2023 23:09:49 +0200 Subject: [PATCH] fix publish loop --- src/app.cpp | 4 +++- src/defines.h | 4 ++-- src/hm/hmPayload.h | 23 +++++++++++++++++++++++ src/publisher/pubMqttIvData.h | 8 ++++---- 4 files changed, 32 insertions(+), 7 deletions(-) diff --git a/src/app.cpp b/src/app.cpp index d2d87f50..c61c81aa 100644 --- a/src/app.cpp +++ b/src/app.cpp @@ -32,7 +32,7 @@ void app::setup() { mSys.enableDebug(); mSys.setup(mConfig->nrf.amplifierPower, mConfig->nrf.pinIrq, mConfig->nrf.pinCe, mConfig->nrf.pinCs, mConfig->nrf.pinSclk, mConfig->nrf.pinMosi, mConfig->nrf.pinMiso); -#if defined(AP_ONLY) + #if defined(AP_ONLY) mInnerLoopCb = std::bind(&app::loopStandard, this); #else mInnerLoopCb = std::bind(&app::loopWifi, this); @@ -171,6 +171,8 @@ void app::regularTickers(void) { if (mConfig->plugin.display.type != 0) everySec(std::bind(&DisplayType::tickerSecond, &mDisplay), "disp"); every(std::bind(&PubSerialType::tick, &mPubSerial), mConfig->serial.interval, "uart"); + + // every([this]() {mPayload.simulation();}, 15, "simul"); } //----------------------------------------------------------------------------- diff --git a/src/defines.h b/src/defines.h index 93722b6c..7260d766 100644 --- a/src/defines.h +++ b/src/defines.h @@ -1,5 +1,5 @@ //----------------------------------------------------------------------------- -// 2023 Ahoy, https://www.mikrocontroller.net/topic/525778 +// 2023 Ahoy, https://ahoydtu.de // Creative Commons - https://creativecommons.org/licenses/by-nc-sa/4.0/deed //----------------------------------------------------------------------------- @@ -13,7 +13,7 @@ //------------------------------------- #define VERSION_MAJOR 0 #define VERSION_MINOR 6 -#define VERSION_PATCH 9 +#define VERSION_PATCH 11 //------------------------------------- typedef struct { diff --git a/src/hm/hmPayload.h b/src/hm/hmPayload.h index 29f380fa..0ec40d22 100644 --- a/src/hm/hmPayload.h +++ b/src/hm/hmPayload.h @@ -70,6 +70,29 @@ class HmPayload { } } + /*void simulation() { + uint8_t pay[] = { + 0x00, 0x01, 0x01, 0x24, 0x02, 0x28, 0x02, 0x33, + 0x06, 0x49, 0x06, 0x6a, 0x00, 0x05, 0x5f, 0x1b, + 0x00, 0x06, 0x66, 0x9a, 0x03, 0xfd, 0x04, 0x0b, + 0x01, 0x23, 0x02, 0x28, 0x02, 0x28, 0x06, 0x41, + 0x06, 0x43, 0x00, 0x05, 0xdc, 0x2c, 0x00, 0x06, + 0x2e, 0x3f, 0x04, 0x01, 0x03, 0xfb, 0x09, 0x78, + 0x13, 0x86, 0x18, 0x15, 0x00, 0xcf, 0x00, 0xfe, + 0x03, 0xe7, 0x01, 0x42, 0x00, 0x03 + }; + + Inverter<> *iv = mSys->getInverterByPos(0); + record_t<> *rec = iv->getRecordStruct(0x0b); + rec->ts = *mTimestamp; + for (uint8_t i = 0; i < rec->length; i++) { + iv->addValue(i, pay, rec); + yield(); + } + iv->doCalculations(); + notify(0x0b); + }*/ + void zeroYieldDay(Inverter<> *iv) { DPRINTLN(DBG_DEBUG, F("zeroYieldDay")); record_t<> *rec = iv->getRecordStruct(RealTimeRunData_Debug); diff --git a/src/publisher/pubMqttIvData.h b/src/publisher/pubMqttIvData.h index 4c574118..ba4cbbbf 100644 --- a/src/publisher/pubMqttIvData.h +++ b/src/publisher/pubMqttIvData.h @@ -85,6 +85,8 @@ class PubMqttIvData { } } + mLastIvId++; + mPos = 0; if(found) mState = SEND_DATA; @@ -102,8 +104,6 @@ class PubMqttIvData { pubData &= (lastTs != mIvLastRTRpub[mIv->id]); if (pubData) { - mIvLastRTRpub[mIv->id] = lastTs; - //for (uint8_t i = 0; i < rec->length; i++) { if(mPos < rec->length) { bool retained = false; if (mCmd == RealTimeRunData_Debug) { @@ -135,7 +135,8 @@ class PubMqttIvData { break; } } - } + } else + mIvLastRTRpub[mIv->id] = lastTs; snprintf(mSubTopic, 32 + MAX_NAME_LENGTH, "%s/ch%d/%s", mIv->config->name, rec->assign[mPos].ch, fields[rec->assign[mPos].fieldId]); snprintf(mVal, 40, "%g", ah::round3(mIv->getValue(mPos, rec))); @@ -149,7 +150,6 @@ class PubMqttIvData { void stateSendTotals() { uint8_t fieldId; - //for (uint8_t i = 0; i < 4; i++) { if(mPos < 4) { bool retained = true; switch (mPos) {