Browse Source

optimizing ...

pull/1512/head
lumapu 10 months ago
parent
commit
1e5d788914
  1. 4
      src/app.h
  2. 4
      src/appInterface.h
  3. 14
      src/plugins/Display/Display_Mono.h
  4. 55
      src/plugins/history.h
  5. 11
      src/web/RestApi.h
  6. 18
      src/web/html/history.html
  7. 19
      src/web/html/style.css

4
src/app.h

@ -314,9 +314,9 @@ class app : public IApp, public ah::Scheduler {
#endif #endif
} }
uint32_t getHistoryPeriode(uint8_t type) override { uint32_t getHistoryPeriod(uint8_t type) override {
#if defined(ENABLE_HISTORY) #if defined(ENABLE_HISTORY)
return mHistory.getPeriode((HistoryStorageType)type); return mHistory.getPeriod((HistoryStorageType)type);
#else #else
return 0; return 0;
#endif #endif

4
src/appInterface.h

@ -67,11 +67,11 @@ class IApp {
virtual bool isProtected(const char *clientIp, const char *token, bool askedFromWeb) const = 0; virtual bool isProtected(const char *clientIp, const char *token, bool askedFromWeb) const = 0;
virtual uint16_t getHistoryValue(uint8_t type, uint16_t i) = 0; virtual uint16_t getHistoryValue(uint8_t type, uint16_t i) = 0;
virtual uint32_t getHistoryPeriode(uint8_t type) = 0; virtual uint32_t getHistoryPeriod(uint8_t type) = 0;
virtual uint16_t getHistoryMaxDay() = 0; virtual uint16_t getHistoryMaxDay() = 0;
virtual uint32_t getHistoryLastValueTs(uint8_t type) = 0; virtual uint32_t getHistoryLastValueTs(uint8_t type) = 0;
#if defined(ENABLE_HISTORY_LOAD_DATA) #if defined(ENABLE_HISTORY_LOAD_DATA)
virtual void addValueToHistory(uint8_t historyType, uint8_t valueType, uint32_t value) = 0; virtual void addValueToHistory(uint8_t historyType, uint8_t valueType, uint32_t value) = 0;
#endif #endif
virtual void* getRadioObj(bool nrf) = 0; virtual void* getRadioObj(bool nrf) = 0;
}; };

14
src/plugins/Display/Display_Mono.h

@ -110,7 +110,7 @@ class DisplayMono {
} }
// add new value to power graph and maintain state engine for period times // add new value to power graph and maintain state engine for period times
void addPowerGraphEntry(float val) { /*void addPowerGraphEntry(float val) {
if (nullptr == mPgData) // power graph not initialized if (nullptr == mPgData) // power graph not initialized
return; return;
@ -163,7 +163,7 @@ class DisplayMono {
mPgData[mPgLastPos] = std::max(mPgData[mPgLastPos], val); // update current datapoint to maximum of all seen values (= envelope curve) mPgData[mPgLastPos] = std::max(mPgData[mPgLastPos], val); // update current datapoint to maximum of all seen values (= envelope curve)
mPgMaxPwr = std::max(mPgMaxPwr, val); // update max value of stored data for scaling of y-axis mPgMaxPwr = std::max(mPgMaxPwr, val); // update max value of stored data for scaling of y-axis
} }
} }*/
// plot power graph to given display offset // plot power graph to given display offset
void plotPowerGraph(uint8_t xoff, uint8_t yoff) { void plotPowerGraph(uint8_t xoff, uint8_t yoff) {
@ -296,15 +296,15 @@ class DisplayMono {
uint8_t mPgWidth = 0; uint8_t mPgWidth = 0;
private: private:
float *mPgData = nullptr; //float *mPgData = nullptr;
uint8_t mPgHeight = 0; uint8_t mPgHeight = 0;
float mPgMaxPwr = 0.0; float mPgMaxPwr = 0.0;
uint32_t mPgStartTime = 0; //uint32_t mPgStartTime = 0;
uint32_t mPgEndTime = 0; //uint32_t mPgEndTime = 0;
uint32_t mPgPeriod = 0; // seconds //uint32_t mPgPeriod = 0; // seconds
uint8_t mPgLastPos = 0; uint8_t mPgLastPos = 0;
uint32_t mPgLastTime = 0; uint32_t mPgLastTime = 0;
PowerGraphState mPgState = PowerGraphState::NO_TIME_SYNC; //PowerGraphState mPgState = PowerGraphState::NO_TIME_SYNC;
uint16_t mDispHeight = 0; uint16_t mDispHeight = 0;
uint8_t mLuminance = 0; uint8_t mLuminance = 0;

55
src/plugins/history.h

@ -26,8 +26,8 @@ class HistoryData {
private: private:
struct storage_t { struct storage_t {
uint16_t refreshCycle = 0; uint16_t refreshCycle = 0;
uint16_t loopCnt; uint16_t loopCnt = 0;
uint16_t listIdx; // index for next Element to write into WattArr uint16_t listIdx = 0; // index for next Element to write into WattArr
// ring buffer for watt history // ring buffer for watt history
std::array<uint16_t, (HISTORY_DATA_ARR_LENGTH + 1)> data; std::array<uint16_t, (HISTORY_DATA_ARR_LENGTH + 1)> data;
@ -45,13 +45,12 @@ class HistoryData {
mConfig = config; mConfig = config;
mTs = ts; mTs = ts;
mCurPwr.reset();
mCurPwr.refreshCycle = mConfig->inst.sendInterval; mCurPwr.refreshCycle = mConfig->inst.sendInterval;
mCurPwrDay.reset();
mCurPwrDay.refreshCycle = mConfig->inst.sendInterval; mCurPwrDay.refreshCycle = mConfig->inst.sendInterval;
mYieldDay.reset(); #if defined(ENABLE_HISTORY_YIELD_PER_DAY)
mYieldDay.refreshCycle = 60; mYieldDay.refreshCycle = 60;
mLastValueTs = 0; #endif
mLastValueTs = 0;
mPgPeriod=0; mPgPeriod=0;
mMaximumDay = 0; mMaximumDay = 0;
} }
@ -60,7 +59,7 @@ class HistoryData {
float curPwr = 0; float curPwr = 0;
//float maxPwr = 0; //float maxPwr = 0;
float yldDay = -0.1; float yldDay = -0.1;
uint32_t ts = 0; uint32_t ts = 0;
for (uint8_t i = 0; i < mSys->getNumInverters(); i++) { for (uint8_t i = 0; i < mSys->getNumInverters(); i++) {
Inverter<> *iv = mSys->getInverterByPos(i); Inverter<> *iv = mSys->getInverterByPos(i);
@ -70,14 +69,14 @@ class HistoryData {
curPwr += iv->getChannelFieldValue(CH0, FLD_PAC, rec); curPwr += iv->getChannelFieldValue(CH0, FLD_PAC, rec);
//maxPwr += iv->getChannelFieldValue(CH0, FLD_MP, rec); //maxPwr += iv->getChannelFieldValue(CH0, FLD_MP, rec);
yldDay += iv->getChannelFieldValue(CH0, FLD_YD, rec); yldDay += iv->getChannelFieldValue(CH0, FLD_YD, rec);
if (rec->ts > ts) if (rec->ts > ts)
ts = rec->ts; ts = rec->ts;
} }
if ((++mCurPwr.loopCnt % mCurPwr.refreshCycle) == 0) { if ((++mCurPwr.loopCnt % mCurPwr.refreshCycle) == 0) {
mCurPwr.loopCnt = 0; mCurPwr.loopCnt = 0;
if (curPwr > 0) { if (curPwr > 0) {
mLastValueTs = ts; mLastValueTs = ts;
addValue(&mCurPwr, roundf(curPwr)); addValue(&mCurPwr, roundf(curPwr));
if (curPwr > mMaximumDay) if (curPwr > mMaximumDay)
mMaximumDay = roundf(curPwr); mMaximumDay = roundf(curPwr);
@ -94,18 +93,18 @@ class HistoryData {
} }
} }
#if defined(ENABLE_HISTORY_YIELD_PER_DAY)
if((++mYieldDay.loopCnt % mYieldDay.refreshCycle) == 0) { if((++mYieldDay.loopCnt % mYieldDay.refreshCycle) == 0) {
mYieldDay.loopCnt = 0; mYieldDay.loopCnt = 0;
if (*mTs > mApp->getSunset()) if (*mTs > mApp->getSunset()) {
{
if ((!mDayStored) && (yldDay > 0)) { if ((!mDayStored) && (yldDay > 0)) {
addValue(&mYieldDay, roundf(yldDay)); addValue(&mYieldDay, roundf(yldDay));
mDayStored = true; mDayStored = true;
} }
} } else if (*mTs > mApp->getSunrise())
else if (*mTs > mApp->getSunrise())
mDayStored = false; mDayStored = false;
} }
#endif
} }
uint16_t valueAt(HistoryStorageType type, uint16_t i) { uint16_t valueAt(HistoryStorageType type, uint16_t i) {
@ -113,10 +112,12 @@ class HistoryData {
uint16_t idx=i; uint16_t idx=i;
DPRINTLN(DBG_VERBOSE, F("valueAt ") + String((uint8_t)type) + " i=" + String(i)); DPRINTLN(DBG_VERBOSE, F("valueAt ") + String((uint8_t)type) + " i=" + String(i));
idx = (s->listIdx + i) % HISTORY_DATA_ARR_LENGTH;
switch (type) { switch (type) {
default:
[[fallthrough]];
case HistoryStorageType::POWER: case HistoryStorageType::POWER:
s = &mCurPwr; s = &mCurPwr;
idx = (s->listIdx + i) % HISTORY_DATA_ARR_LENGTH;
break; break;
case HistoryStorageType::POWER_DAY: case HistoryStorageType::POWER_DAY:
s = &mCurPwrDay; s = &mCurPwrDay;
@ -124,12 +125,10 @@ class HistoryData {
break; break;
case HistoryStorageType::YIELD: case HistoryStorageType::YIELD:
s = &mYieldDay; s = &mYieldDay;
idx = (s->listIdx + i) % HISTORY_DATA_ARR_LENGTH;
break; break;
} }
if (s)
return s->data[idx]; return s->data[idx];
return 0;
} }
uint16_t getMaximumDay() { uint16_t getMaximumDay() {
@ -150,8 +149,8 @@ class HistoryData {
return mCurPwr.refreshCycle; return mCurPwr.refreshCycle;
break; break;
case HistoryStorageType::POWER_DAY: case HistoryStorageType::POWER_DAY:
return mPgPeriod / HISTORY_DATA_ARR_LENGTH; return mPgPeriod / HISTORY_DATA_ARR_LENGTH;
break; break;
case HistoryStorageType::YIELD: case HistoryStorageType::YIELD:
return (60 * 60 * 24); // 1 day return (60 * 60 * 24); // 1 day
break; break;
@ -159,21 +158,29 @@ class HistoryData {
return 0; return 0;
} }
bool isDataValid(void) {
return ((0 != mPgStartTime) && (0 != mPgEndTime));
}
#if defined(ENABLE_HISTORY_LOAD_DATA) #if defined(ENABLE_HISTORY_LOAD_DATA)
/* For filling data from outside */ /* For filling data from outside */
void addValue(HistoryStorageType historyType, uint8_t valueType, uint32_t value) { void addValue(HistoryStorageType historyType, uint8_t valueType, uint32_t value) {
if (valueType<2) { if (valueType<2) {
storage_t *s=NULL; storage_t *s=NULL;
switch (historyType) { switch (historyType) {
default:
[[fallthrough]];
case HistoryStorageType::POWER: case HistoryStorageType::POWER:
s = &mCurPwr; s = &mCurPwr;
break; break;
case HistoryStorageType::POWER_DAY: case HistoryStorageType::POWER_DAY:
s = &mCurPwrDay; s = &mCurPwrDay;
break; break;
#if defined(ENABLE_HISTORY_YIELD_PER_DAY)
case HistoryStorageType::YIELD: case HistoryStorageType::YIELD:
s = &mYieldDay; s = &mYieldDay;
break; break;
#endif
} }
if (s) if (s)
{ {
@ -275,10 +282,12 @@ class HistoryData {
storage_t mCurPwr; storage_t mCurPwr;
storage_t mCurPwrDay; storage_t mCurPwrDay;
#if defined(ENABLE_HISTORY_YIELD_PER_DAY)
storage_t mYieldDay; storage_t mYieldDay;
#endif
bool mDayStored = false; bool mDayStored = false;
uint16_t mMaximumDay = 0; uint16_t mMaximumDay = 0;
uint32_t mLastValueTs = 0; uint32_t mLastValueTs = 0;
enum class PowerGraphState { enum class PowerGraphState {
NO_TIME_SYNC, NO_TIME_SYNC,
IN_PERIOD, IN_PERIOD,

11
src/web/RestApi.h

@ -50,9 +50,8 @@ class RestApi {
#endif #endif
mConfig = config; mConfig = config;
#if defined(ENABLE_HISTORY_LOAD_DATA) #if defined(ENABLE_HISTORY_LOAD_DATA)
//Vart67: Debugging history graph (loading data into graph storage
mSrv->on("/api/addYDHist", mSrv->on("/api/addYDHist",
HTTP_POST, std::bind(&RestApi::onApiPost, this, std::placeholders::_1), HTTP_POST, std::bind(&RestApi::onApiPost, this, std::placeholders::_1),
std::bind(&RestApi::onApiPostYDHist,this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5, std::placeholders::_6)); std::bind(&RestApi::onApiPostYDHist,this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5, std::placeholders::_6));
#endif #endif
mSrv->on("/api", HTTP_POST, std::bind(&RestApi::onApiPost, this, std::placeholders::_1)).onBody( mSrv->on("/api", HTTP_POST, std::bind(&RestApi::onApiPost, this, std::placeholders::_1)).onBody(
@ -913,7 +912,7 @@ class RestApi {
void getPowerHistory(AsyncWebServerRequest *request, JsonObject obj) { void getPowerHistory(AsyncWebServerRequest *request, JsonObject obj) {
getGeneric(request, obj.createNestedObject(F("generic"))); getGeneric(request, obj.createNestedObject(F("generic")));
#if defined(ENABLE_HISTORY) #if defined(ENABLE_HISTORY)
obj[F("refresh")] = mApp->getHistoryPeriode((uint8_t)HistoryStorageType::POWER); obj[F("refresh")] = mApp->getHistoryPeriod((uint8_t)HistoryStorageType::POWER);
uint16_t max = 0; uint16_t max = 0;
for (uint16_t fld = 0; fld < HISTORY_DATA_ARR_LENGTH; fld++) { for (uint16_t fld = 0; fld < HISTORY_DATA_ARR_LENGTH; fld++) {
uint16_t value = mApp->getHistoryValue((uint8_t)HistoryStorageType::POWER, fld); uint16_t value = mApp->getHistoryValue((uint8_t)HistoryStorageType::POWER, fld);
@ -930,7 +929,7 @@ class RestApi {
void getPowerHistoryDay(AsyncWebServerRequest *request, JsonObject obj){ void getPowerHistoryDay(AsyncWebServerRequest *request, JsonObject obj){
getGeneric(request, obj.createNestedObject(F("generic"))); getGeneric(request, obj.createNestedObject(F("generic")));
#if defined(ENABLE_HISTORY) #if defined(ENABLE_HISTORY)
obj[F("refresh")] = mApp->getHistoryPeriode((uint8_t)HistoryStorageType::POWER_DAY); obj[F("refresh")] = mApp->getHistoryPeriod((uint8_t)HistoryStorageType::POWER_DAY);
uint16_t max = 0; uint16_t max = 0;
for (uint16_t fld = 0; fld < HISTORY_DATA_ARR_LENGTH; fld++) { for (uint16_t fld = 0; fld < HISTORY_DATA_ARR_LENGTH; fld++) {
uint16_t value = mApp->getHistoryValue((uint8_t)HistoryStorageType::POWER_DAY, fld); uint16_t value = mApp->getHistoryValue((uint8_t)HistoryStorageType::POWER_DAY, fld);
@ -947,8 +946,8 @@ class RestApi {
void getYieldDayHistory(AsyncWebServerRequest *request, JsonObject obj) { void getYieldDayHistory(AsyncWebServerRequest *request, JsonObject obj) {
getGeneric(request, obj.createNestedObject(F("generic"))); getGeneric(request, obj.createNestedObject(F("generic")));
#if defined(ENABLE_HISTORY) #if defined(ENABLE_HISTORY) && defined(ENABLE_HISTORY_YIELD_PER_DAY)
obj[F("refresh")] = mApp->getHistoryPeriode((uint8_t)HistoryStorageType::YIELD); obj[F("refresh")] = mApp->getHistoryPeriod((uint8_t)HistoryStorageType::YIELD);
uint16_t max = 0; uint16_t max = 0;
for (uint16_t fld = 0; fld < HISTORY_DATA_ARR_LENGTH; fld++) { for (uint16_t fld = 0; fld < HISTORY_DATA_ARR_LENGTH; fld++) {
uint16_t value = mApp->getHistoryValue((uint8_t)HistoryStorageType::YIELD, fld); uint16_t value = mApp->getHistoryValue((uint8_t)HistoryStorageType::YIELD, fld);

18
src/web/html/history.html

@ -30,8 +30,7 @@
{#UPDATED} <span id="pwrDayRefresh"></span> {#SECONDS} {#UPDATED} <span id="pwrDayRefresh"></span> {#SECONDS}
</p> </p>
</div> </div>
<!--IF_ENABLE_HISTORY_YIELD_PER_DAY-->
<!--
<h3>{#TOTAL_YIELD_PER_DAY}</h3> <h3>{#TOTAL_YIELD_PER_DAY}</h3>
<div class="chartDivContainer"> <div class="chartDivContainer">
<div class="chartDiv" id="ydChart"> </div> <div class="chartDiv" id="ydChart"> </div>
@ -39,7 +38,8 @@
{#MAXIMUM}: <span id="ydMax"></span> Wh<br /> {#MAXIMUM}: <span id="ydMax"></span> Wh<br />
</p> </p>
</div> </div>
<!--ENDIF_ENABLE_HISTORY_YIELD_PER_DAY-->
<!--IF_ENABLE_HISTORY_LOAD_DATA-->
<h4 style="margin-bottom:0px;">Insert data into Yield per day history</h4> <h4 style="margin-bottom:0px;">Insert data into Yield per day history</h4>
<fieldset style="padding: 1px;"> <fieldset style="padding: 1px;">
<legend class="des" style="margin-top: 0px;">Insert data (*.json) i.e. from a saved "/api/yieldDayHistory" call <legend class="des" style="margin-top: 0px;">Insert data (*.json) i.e. from a saved "/api/yieldDayHistory" call
@ -50,7 +50,7 @@
<input type="file" name="insert" style="width: 80%;"> <input type="file" name="insert" style="width: 80%;">
</form> </form>
</fieldset> </fieldset>
--> <!--ENDIF_ENABLE_HISTORY_LOAD_DATA-->
</div> </div>
</div> </div>
{#HTML_FOOTER} {#HTML_FOOTER}
@ -151,19 +151,9 @@
} }
this.svg.appendChild(defLg); this.svg.appendChild(defLg);
let chartFrame = document.createElementNS(svgns, "rect");
chartFrame.setAttribute("id", this.namePrefix + "_chartFrame");
chartFrame.setAttribute("class", "chartFrame");
chartFrame.setAttribute("x", "0");
chartFrame.setAttribute("y", "0");
chartFrame.setAttribute("width", String(this.datapoints * 2));
chartFrame.setAttribute("height", String(this.mChartHight));
this.svg.appendChild(chartFrame);
// Group chart content // Group chart content
let chartContent = document.createElementNS(svgns, "g"); let chartContent = document.createElementNS(svgns, "g");
chartContent.setAttribute("id", this.namePrefix + "_svgChartContent"); chartContent.setAttribute("id", this.namePrefix + "_svgChartContent");
chartFrame.setAttribute("transform", "translate(29, 5)");
chartContent.setAttribute("transform", "translate(30, 5)"); chartContent.setAttribute("transform", "translate(30, 5)");
// Graph values in a polyline // Graph values in a polyline

19
src/web/html/style.css

@ -33,27 +33,16 @@ textarea {
color: var(--fg2); color: var(--fg2);
} }
svg.container {
background:var(--chart-cont);
}
rect.chartFrame {
fill: var(--chart-bg);
stroke: gray;
stroke-width: 1px;
}
svg polyline { svg polyline {
fill-opacity: .5; fill-opacity: .5;
stroke-width: 1; stroke-width: 1;
} }
svg text { svg text {
font-size: x-small; font-size: x-small;
fill: var(--chart-text); fill: var(--chart-text);
} }
div.chartDivContainer { div.chartDivContainer {
padding: 1px; padding: 1px;
margin: 1px; margin: 1px;

Loading…
Cancel
Save