Browse Source

Minor optimisation in history chart

More stable HM transfer (removed Frequencies 2461, 2475MH)
pull/1321/head
VArt67 2 years ago
parent
commit
a4dac8201d
  1. 11
      README.md
  2. 8
      src/hm/hmRadio.h
  3. 8
      src/plugins/history.cpp
  4. 3
      src/plugins/history.h
  5. 1
      src/web/RestApi.h
  6. 25
      src/web/html/history.html

11
README.md

@ -29,11 +29,14 @@ This fork adds the following features:
### Added chart to Display128x64 ### Added chart to Display128x64
### Added a History menu ### Added a History menu
This menu displays a bar-chart of the last 256 total power values This menu displays
and a bar chart of the last 256 Yield-Day values. - 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! Note: The history of the values gets lost after rebbot!
### Changed WiFi reconnect behaviour ### Changed WiFi reconnect behaviour
For me the original reconnect did not work. I always lost connection after some time. For me the original reconnect did not work. I always lost connection after some time.
Now it is much more stable. Now it is more stable.
### Reduced frequency channels
Removed frequencies 2461, 2475MHz. Now the transfers are much more stable

8
src/hm/hmRadio.h

@ -48,6 +48,9 @@ class HmRadio {
mRfChLst[2] = 40; mRfChLst[2] = 40;
mRfChLst[3] = 61; mRfChLst[3] = 61;
mRfChLst[4] = 75; mRfChLst[4] = 75;
// VArt: Overwriting 61/75 so I got much more stable responses
mRfChLst[3] = 23;
mRfChLst[4] = 40;
// default channels // default channels
mTxChIdx = 2; // Start TX with 40 mTxChIdx = 2; // Start TX with 40
@ -134,10 +137,10 @@ class HmRadio {
mNrf24.setChannel(mRfChLst[mRxChIdx]); mNrf24.setChannel(mRfChLst[mRxChIdx]);
mNrf24.startListening(); mNrf24.startListening();
uint32_t startMicros = micros();
uint32_t loopMillis = millis(); uint32_t loopMillis = millis();
while (millis()-loopMillis < 400) { 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) { if (mIrqRcvd) {
mIrqRcvd = false; mIrqRcvd = false;
if (getReceived()) { // everything received if (getReceived()) { // everything received
@ -147,7 +150,6 @@ class HmRadio {
yield(); yield();
} }
// switch to next RX channel // switch to next RX channel
startMicros = micros();
if(++mRxChIdx >= RF_CHANNELS) if(++mRxChIdx >= RF_CHANNELS)
mRxChIdx = 0; mRxChIdx = 0;
mNrf24.setChannel(mRfChLst[mRxChIdx]); mNrf24.setChannel(mRfChLst[mRxChIdx]);

8
src/plugins/history.cpp

@ -11,6 +11,7 @@ void TotalPowerHistory::setup(IApp *app, HmSystemType *sys, settings_t *config)
mConfig = config; mConfig = config;
mRefreshCycle = 0; mRefreshCycle = 0;
mRefreshCycle = mConfig->nrf.sendInterval; mRefreshCycle = mConfig->nrf.sendInterval;
mMaximumDay = 0;
} }
void TotalPowerHistory::tickerSecond() { void TotalPowerHistory::tickerSecond() {
@ -18,7 +19,8 @@ void TotalPowerHistory::tickerSecond() {
if ((mLoopCnt % mRefreshCycle) == 0) { if ((mLoopCnt % mRefreshCycle) == 0) {
//DPRINTLN(DBG_DEBUG,F("TotalPowerHistory::tickerSecond > refreshCycle" + String(mRefreshCycle) + "|" + String(mLoopCnt) + "|" + String(mRefreshCycle % mLoopCnt)); //DPRINTLN(DBG_DEBUG,F("TotalPowerHistory::tickerSecond > refreshCycle" + String(mRefreshCycle) + "|" + String(mLoopCnt) + "|" + String(mRefreshCycle % mLoopCnt));
mLoopCnt = 0; mLoopCnt = 0;
float totalPower = -0.1; float totalPower = 0;
float totalPowerDay = 0;
Inverter<> *iv; Inverter<> *iv;
record_t<> *rec; record_t<> *rec;
for (uint8_t i = 0; i < mSys->getNumInverters(); i++) { for (uint8_t i = 0; i < mSys->getNumInverters(); i++) {
@ -27,12 +29,16 @@ void TotalPowerHistory::tickerSecond() {
if (iv == NULL) if (iv == NULL)
continue; continue;
totalPower += iv->getChannelFieldValue(CH0, FLD_PAC, rec); totalPower += iv->getChannelFieldValue(CH0, FLD_PAC, rec);
totalPowerDay += iv->getChannelFieldValue(CH0, FLD_MP, rec);
} }
if (totalPower > 0) { if (totalPower > 0) {
uint16_t iTotalPower = roundf(totalPower); uint16_t iTotalPower = roundf(totalPower);
DPRINTLN(DBG_DEBUG, F("addValue(iTotalPower)=") + String(iTotalPower)); DPRINTLN(DBG_DEBUG, F("addValue(iTotalPower)=") + String(iTotalPower));
addValue(iTotalPower); addValue(iTotalPower);
} }
if (totalPowerDay > 0) {
mMaximumDay = roundf(totalPowerDay);
}
} }
} }

3
src/plugins/history.h

@ -52,6 +52,7 @@ class TotalPowerHistory : public HistoryData {
void setup(IApp *app, HmSystemType *sys, settings_t *config); void setup(IApp *app, HmSystemType *sys, settings_t *config);
void tickerSecond(); void tickerSecond();
uint16_t getMaximumDay() { return mMaximumDay; }
private: private:
IApp *mApp; IApp *mApp;
@ -60,6 +61,8 @@ class TotalPowerHistory : public HistoryData {
settings_t *mConfig; settings_t *mConfig;
uint16_t mRefreshCycle; uint16_t mRefreshCycle;
uint16_t mLoopCnt; uint16_t mLoopCnt;
uint16_t mMaximumDay;
}; };
class YieldDayHistory : public HistoryData { class YieldDayHistory : public HistoryData {

1
src/web/RestApi.h

@ -610,6 +610,7 @@ class RestApi {
maximum = value; maximum = value;
} }
obj[F("maximum")] = maximum; obj[F("maximum")] = maximum;
obj[F("maximumDay")] = p->getMaximumDay();
obj[F("dispIndex")] = p->getDisplIdx(); obj[F("dispIndex")] = p->getDisplIdx();
} }

25
src/web/html/history.html

@ -17,15 +17,15 @@
<div class="chartDivContainer"> <div class="chartDivContainer">
<div class="chartDiv" id="phHistoryChart"> </div> <div class="chartDiv" id="phHistoryChart"> </div>
<p class="center" style="margin:0px;border:0px;"> <p class="center" style="margin:0px;border:0px;">
Maximum value: <span id="phMaximum"></span> Watt<br /> Maximum day: <span id="phMaximumDay"></span> W. Last measured value: <span id="phActual"></span> W.<br />
Updated every <span id="phRefresh"></span> seconds </p> Maximum graphics: <span id="phMaximum"></span> W. Updated every <span id="phRefresh"></span> seconds </p>
</div> </div>
<h3>Yield per day history</h3> <h3>Yield per day history</h3>
<div class="chartDivContainer"> <div class="chartDivContainer">
<div class="chartDiv" id="ydHistoryChart"> </div> <div class="chartDiv" id="ydHistoryChart"> </div>
<p class="center" style="margin:0px;border:0px;"> <p class="center" style="margin:0px;border:0px;">
Maximum value: <span id="ydMaximum"></span> Watt<br /> Maximum value: <span id="ydMaximum"></span> Wh<br />
Updated every <span id="ydRefresh"></span> seconds </p> Updated every <span id="ydRefresh"></span> seconds </p>
</div> </div>
</div> </div>
@ -40,6 +40,7 @@
var mRefresh = 60; var mRefresh = 60;
var phDatapoints = 512; var phDatapoints = 512;
var mMaximum = 0; var mMaximum = 0;
var mLastValue = 0;
var mDispIdx = 0 var mDispIdx = 0
var mDataValues = []; var mDataValues = [];
const mChartHight = 250; const mChartHight = 250;
@ -79,12 +80,14 @@
if (divider == 0) if (divider == 0)
divider = 1; divider = 1;
for (var i = 0; i < phDatapoints; i++) { for (var i = 0; i < phDatapoints; i++) {
val = mDataValues[i]; val = mDataValues[idx];
idx = (idx + 1) % phDatapoints; if (val>0)
mLastValue = val
val = val / divider val = val / divider
rect = document.getElementById(namePrefix+"Rect" + i); rect = document.getElementById(namePrefix+"Rect" + i);
rect.setAttribute("height", val); rect.setAttribute("height", val);
rect.setAttribute("y", mChartHight - val); rect.setAttribute("y", mChartHight - val);
idx = (idx + 1) % phDatapoints;
} }
document.getElementById(namePrefix + "Maximum").innerHTML = mMaximum; document.getElementById(namePrefix + "Maximum").innerHTML = mMaximum;
if (mRefresh < 5) if (mRefresh < 5)
@ -95,10 +98,17 @@
if (null != obj) { if (null != obj) {
parseNav(obj["generic"]); parseNav(obj["generic"]);
parseHistory(obj,"ph", phExeOnce) parseHistory(obj,"ph", phExeOnce)
let maximumDay = obj["maximumDay"];
document.getElementById("phActual").innerHTML = mLastValue;
document.getElementById("phMaximumDay").innerHTML = maximumDay;
} }
if (true == phExeOnce) { if (true == phExeOnce) {
window.setInterval("getAjax('/api/powerHistory', parsePowerHistory)", mRefresh * 1000);
phExeOnce = false; phExeOnce = false;
window.setInterval("getAjax('/api/powerHistory', parsePowerHistory)", mRefresh * 1000);
// one after the other
setTimeout(() => {
getAjax("/api/yieldDayHistory", parseYieldDayHistory);
} , 20);
} }
} }
function parseYieldDayHistory(obj) { function parseYieldDayHistory(obj) {
@ -107,13 +117,12 @@
parseHistory(obj, "yd", ydExeOnce) parseHistory(obj, "yd", ydExeOnce)
} }
if (true == ydExeOnce) { if (true == ydExeOnce) {
window.setInterval("getAjax('/api/yieldDayHistory', parseYieldDayHistory)", mRefresh * 1000);
ydExeOnce = false; ydExeOnce = false;
window.setInterval("getAjax('/api/yieldDayHistory', parseYieldDayHistory)", mRefresh * 500);
} }
} }
getAjax("/api/powerHistory", parsePowerHistory); getAjax("/api/powerHistory", parsePowerHistory);
getAjax("/api/yieldDayHistory", parseYieldDayHistory);
</script> </script>
</body> </body>

Loading…
Cancel
Save