From a4dac8201dcf43c33d1fe0fc41ad9cacfd171334 Mon Sep 17 00:00:00 2001 From: VArt67 Date: Wed, 3 Jan 2024 22:50:51 +0100 Subject: [PATCH] Minor optimisation in history chart More stable HM transfer (removed Frequencies 2461, 2475MH) --- README.md | 11 +++++++---- src/hm/hmRadio.h | 8 +++++--- src/plugins/history.cpp | 8 +++++++- src/plugins/history.h | 3 +++ src/web/RestApi.h | 7 ++++--- src/web/html/history.html | 25 +++++++++++++++++-------- 6 files changed, 43 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index d8d245b2..07556d2f 100644 --- a/README.md +++ b/README.md @@ -29,11 +29,14 @@ This fork adds the following features: ### Added chart to Display128x64 ### Added a History menu -This menu displays a bar-chart of the last 256 total power values -and a bar chart of the last 256 Yield-Day values. - +This menu displays +- a bar-chart of the last 256 Total-Power values +- a bar chart of the last 256 Yield-Day values. Note: The history of the values gets lost after rebbot! ### Changed WiFi reconnect behaviour For me the original reconnect did not work. I always lost connection after some time. -Now it is much more stable. \ No newline at end of file +Now it is more stable. + +### Reduced frequency channels +Removed frequencies 2461, 2475MHz. Now the transfers are much more stable \ No newline at end of file diff --git a/src/hm/hmRadio.h b/src/hm/hmRadio.h index 07bb8c00..a9f24776 100644 --- a/src/hm/hmRadio.h +++ b/src/hm/hmRadio.h @@ -48,6 +48,9 @@ class HmRadio { mRfChLst[2] = 40; mRfChLst[3] = 61; mRfChLst[4] = 75; + // VArt: Overwriting 61/75 so I got much more stable responses + mRfChLst[3] = 23; + mRfChLst[4] = 40; // default channels mTxChIdx = 2; // Start TX with 40 @@ -134,10 +137,10 @@ class HmRadio { mNrf24.setChannel(mRfChLst[mRxChIdx]); mNrf24.startListening(); - uint32_t startMicros = micros(); uint32_t loopMillis = millis(); while (millis()-loopMillis < 400) { - while (micros()-startMicros < 5110) { // listen (4088us or?) 5110us to each channel + uint32_t startMicros = micros(); + while (micros()-startMicros < 5111) { // listen (4088us or?) 5110us to each channel if (mIrqRcvd) { mIrqRcvd = false; if (getReceived()) { // everything received @@ -147,7 +150,6 @@ class HmRadio { yield(); } // switch to next RX channel - startMicros = micros(); if(++mRxChIdx >= RF_CHANNELS) mRxChIdx = 0; mNrf24.setChannel(mRfChLst[mRxChIdx]); diff --git a/src/plugins/history.cpp b/src/plugins/history.cpp index 720d5689..ad7cac77 100644 --- a/src/plugins/history.cpp +++ b/src/plugins/history.cpp @@ -11,6 +11,7 @@ void TotalPowerHistory::setup(IApp *app, HmSystemType *sys, settings_t *config) mConfig = config; mRefreshCycle = 0; mRefreshCycle = mConfig->nrf.sendInterval; + mMaximumDay = 0; } void TotalPowerHistory::tickerSecond() { @@ -18,7 +19,8 @@ void TotalPowerHistory::tickerSecond() { if ((mLoopCnt % mRefreshCycle) == 0) { //DPRINTLN(DBG_DEBUG,F("TotalPowerHistory::tickerSecond > refreshCycle" + String(mRefreshCycle) + "|" + String(mLoopCnt) + "|" + String(mRefreshCycle % mLoopCnt)); mLoopCnt = 0; - float totalPower = -0.1; + float totalPower = 0; + float totalPowerDay = 0; Inverter<> *iv; record_t<> *rec; for (uint8_t i = 0; i < mSys->getNumInverters(); i++) { @@ -27,12 +29,16 @@ void TotalPowerHistory::tickerSecond() { if (iv == NULL) continue; totalPower += iv->getChannelFieldValue(CH0, FLD_PAC, rec); + totalPowerDay += iv->getChannelFieldValue(CH0, FLD_MP, rec); } if (totalPower > 0) { uint16_t iTotalPower = roundf(totalPower); DPRINTLN(DBG_DEBUG, F("addValue(iTotalPower)=") + String(iTotalPower)); addValue(iTotalPower); } + if (totalPowerDay > 0) { + mMaximumDay = roundf(totalPowerDay); + } } } diff --git a/src/plugins/history.h b/src/plugins/history.h index 46a8d7b9..27bfe0f5 100644 --- a/src/plugins/history.h +++ b/src/plugins/history.h @@ -52,6 +52,7 @@ class TotalPowerHistory : public HistoryData { void setup(IApp *app, HmSystemType *sys, settings_t *config); void tickerSecond(); + uint16_t getMaximumDay() { return mMaximumDay; } private: IApp *mApp; @@ -60,6 +61,8 @@ class TotalPowerHistory : public HistoryData { settings_t *mConfig; uint16_t mRefreshCycle; uint16_t mLoopCnt; + + uint16_t mMaximumDay; }; class YieldDayHistory : public HistoryData { diff --git a/src/web/RestApi.h b/src/web/RestApi.h index 9ea3511d..6e48c401 100644 --- a/src/web/RestApi.h +++ b/src/web/RestApi.h @@ -608,9 +608,10 @@ class RestApi { obj[F("value")][fld] = value; if (value > maximum) maximum = value; - } - obj[F("maximum")] = maximum; - obj[F("dispIndex")] = p->getDisplIdx(); + } + obj[F("maximum")] = maximum; + obj[F("maximumDay")] = p->getMaximumDay(); + obj[F("dispIndex")] = p->getDisplIdx(); } void getYieldDayHistory(AsyncWebServerRequest *request, JsonObject obj) { diff --git a/src/web/html/history.html b/src/web/html/history.html index a182b4c0..4466f430 100644 --- a/src/web/html/history.html +++ b/src/web/html/history.html @@ -17,15 +17,15 @@

- Maximum value: Watt
- Updated every seconds

+ Maximum day: W. Last measured value: W.
+ Maximum graphics: W. Updated every seconds

Yield per day history

- Maximum value: Watt
+ Maximum value: Wh
Updated every seconds

@@ -40,6 +40,7 @@ var mRefresh = 60; var phDatapoints = 512; var mMaximum = 0; + var mLastValue = 0; var mDispIdx = 0 var mDataValues = []; const mChartHight = 250; @@ -79,12 +80,14 @@ if (divider == 0) divider = 1; for (var i = 0; i < phDatapoints; i++) { - val = mDataValues[i]; - idx = (idx + 1) % phDatapoints; + val = mDataValues[idx]; + if (val>0) + mLastValue = val val = val / divider rect = document.getElementById(namePrefix+"Rect" + i); rect.setAttribute("height", val); rect.setAttribute("y", mChartHight - val); + idx = (idx + 1) % phDatapoints; } document.getElementById(namePrefix + "Maximum").innerHTML = mMaximum; if (mRefresh < 5) @@ -95,10 +98,17 @@ if (null != obj) { parseNav(obj["generic"]); parseHistory(obj,"ph", phExeOnce) + let maximumDay = obj["maximumDay"]; + document.getElementById("phActual").innerHTML = mLastValue; + document.getElementById("phMaximumDay").innerHTML = maximumDay; } if (true == phExeOnce) { - window.setInterval("getAjax('/api/powerHistory', parsePowerHistory)", mRefresh * 1000); phExeOnce = false; + window.setInterval("getAjax('/api/powerHistory', parsePowerHistory)", mRefresh * 1000); + // one after the other + setTimeout(() => { + getAjax("/api/yieldDayHistory", parseYieldDayHistory); + } , 20); } } function parseYieldDayHistory(obj) { @@ -107,13 +117,12 @@ parseHistory(obj, "yd", ydExeOnce) } if (true == ydExeOnce) { - window.setInterval("getAjax('/api/yieldDayHistory', parseYieldDayHistory)", mRefresh * 1000); ydExeOnce = false; + window.setInterval("getAjax('/api/yieldDayHistory', parseYieldDayHistory)", mRefresh * 500); } } getAjax("/api/powerHistory", parsePowerHistory); - getAjax("/api/yieldDayHistory", parseYieldDayHistory);