From 16d0eb204842941a65e38e015a5f5c668a4037f4 Mon Sep 17 00:00:00 2001 From: lumapu Date: Sun, 17 Dec 2023 15:04:09 +0100 Subject: [PATCH] 0.8.26 * read grid profile as HEX (`live` -> click inverter name -> `show grid profile`) --- src/CHANGES.md | 3 +++ src/app.cpp | 2 +- src/config/settings.h | 12 ++++++++++-- src/defines.h | 2 +- src/hm/Communication.h | 8 +++++++- src/hm/hmInverter.h | 23 ++++++++++++++++++++++- src/web/RestApi.h | 14 ++++++++++++++ src/web/html/setup.html | 5 +++++ src/web/html/visualization.html | 10 +++++++++- src/web/web.h | 1 + 10 files changed, 73 insertions(+), 7 deletions(-) diff --git a/src/CHANGES.md b/src/CHANGES.md index a4805fd8a..d57c90d6a 100644 --- a/src/CHANGES.md +++ b/src/CHANGES.md @@ -1,5 +1,8 @@ # Development Changes +## 0.8.26 - 2023-12-17 +* read grid profile as HEX (`live` -> click inverter name -> `show grid profile`) + ## 0.8.25 - 2023-12-17 * RX channel ID starts with fixed value #1277 * fix static IP for Ethernet diff --git a/src/app.cpp b/src/app.cpp index 05ca55634..5a183cf49 100644 --- a/src/app.cpp +++ b/src/app.cpp @@ -336,7 +336,7 @@ void app::tickSend(void) { DBGPRINT(String(fill)); DBGPRINT(F(" of ")); DBGPRINT(String(max)); - DBGPRINTLN(F("entries used")); + DBGPRINTLN(F(" entries used")); } for (uint8_t i = 0; i < MAX_NUM_INVERTERS; i++) { diff --git a/src/config/settings.h b/src/config/settings.h index 31b5cab4f..8acb09422 100644 --- a/src/config/settings.h +++ b/src/config/settings.h @@ -30,7 +30,7 @@ * https://arduino-esp8266.readthedocs.io/en/latest/filesystem.html#flash-layout * */ -#define CONFIG_VERSION 5 +#define CONFIG_VERSION 6 #define PROT_MASK_INDEX 0x0001 @@ -157,6 +157,7 @@ typedef struct { bool startWithoutTime; float yieldEffiency; uint16_t gapMs; + bool readGrid; } cfgInst_t; typedef struct { @@ -440,6 +441,7 @@ class settings { mCfg.inst.rstMaxValsMidNight = false; mCfg.inst.yieldEffiency = 1.0f; mCfg.inst.gapMs = 2000; + mCfg.inst.readGrid = true; for(uint8_t i = 0; i < MAX_NUM_INVERTERS; i++) { mCfg.inst.iv[i].powerLevel = 0xff; // impossible high value @@ -481,12 +483,16 @@ class settings { mCfg.serial.printWholeTrace = false; } if(mCfg.configVersion < 4) { - mCfg.inst.gapMs = 2000; + mCfg.inst.gapMs = 500; } if(mCfg.configVersion < 5) { mCfg.inst.sendInterval = SEND_INTERVAL; mCfg.serial.printWholeTrace = false; } + if(mCfg.configVersion < 6) { + mCfg.inst.gapMs = 500; + mCfg.inst.readGrid = true; + } } } @@ -718,6 +724,7 @@ class settings { obj[F("rstMaxMidNight")] = (bool)mCfg.inst.rstMaxValsMidNight; obj[F("yldEff")] = mCfg.inst.yieldEffiency; obj[F("gap")] = mCfg.inst.gapMs; + obj[F("rdGrid")] = (bool)mCfg.inst.readGrid; } else { getVal(obj, F("intvl"), &mCfg.inst.sendInterval); @@ -729,6 +736,7 @@ class settings { getVal(obj, F("rstMaxMidNight"), &mCfg.inst.rstMaxValsMidNight); getVal(obj, F("yldEff"), &mCfg.inst.yieldEffiency); getVal(obj, F("gap"), &mCfg.inst.gapMs); + getVal(obj, F("rdGrid"), &mCfg.inst.readGrid); if(mCfg.inst.yieldEffiency < 0.5) mCfg.inst.yieldEffiency = 1.0f; diff --git a/src/defines.h b/src/defines.h index b8bb8c644..4d94bc95e 100644 --- a/src/defines.h +++ b/src/defines.h @@ -13,7 +13,7 @@ //------------------------------------- #define VERSION_MAJOR 0 #define VERSION_MINOR 8 -#define VERSION_PATCH 25 +#define VERSION_PATCH 26 //------------------------------------- typedef struct { diff --git a/src/hm/Communication.h b/src/hm/Communication.h index 51db64185..3e95b665b 100644 --- a/src/hm/Communication.h +++ b/src/hm/Communication.h @@ -254,7 +254,7 @@ class Communication : public CommQueue<> { compilePayload(q); - if(NULL != mCbPayload) + if((NULL != mCbPayload) && (GridOnProFilePara != q->cmd)) (mCbPayload)(q->cmd, q->iv); closeRequest(q, true); @@ -440,9 +440,15 @@ class Communication : public CommQueue<> { } else DBGPRINTLN(F(")")); + if(GridOnProFilePara == q->cmd) { + q->iv->addGridProfile(mPayload, len); + return; + } + record_t<> *rec = q->iv->getRecordStruct(q->cmd); if(NULL == rec) { DPRINTLN(DBG_ERROR, F("record is NULL!")); + closeRequest(q, false); return; } if((rec->pyldLen != len) && (0 != rec->pyldLen)) { diff --git a/src/hm/hmInverter.h b/src/hm/hmInverter.h index 3e3e1c086..66496340b 100644 --- a/src/hm/hmInverter.h +++ b/src/hm/hmInverter.h @@ -11,6 +11,8 @@ #define F(sl) (sl) #endif +#define MAX_GRID_LENGTH 150 + #include "hmDefines.h" #include "HeuristicInv.h" #include "../hms/hmsDefines.h" @@ -133,7 +135,7 @@ class Inverter { bool mGotLastMsg; // shows if inverter has already finished transmission cycle Radio *radio; // pointer to associated radio class statistics_t radioStatistics; // information about transmitted, failed, ... packets - HeuristicInv heuristics; + HeuristicInv heuristics; // heuristic information / logic uint8_t curCmtFreq; // current used CMT frequency, used to check if freq. was changed during runtime bool commEnabled; // 'pause night communication' sets this field to false @@ -183,6 +185,8 @@ class Inverter { else if(InitDataState != devControlCmd) { cb(devControlCmd, false); // custom command which was received by API devControlCmd = InitDataState; + } else if((0 == mGridLen) && generalConfig->readGrid) { // read grid profile + cb(GridOnProFilePara, false); } else cb(RealTimeRunData_Debug, false); // get live data } else { @@ -721,6 +725,21 @@ class Inverter { } } + void addGridProfile(uint8_t buf[], uint8_t length) { + mGridLen = (length > MAX_GRID_LENGTH) ? MAX_GRID_LENGTH : length; + std::copy(buf, &buf[mGridLen], mGridProfile); + } + + String getGridProfile(void) { + char buf[MAX_GRID_LENGTH * 3]; + memset(buf, 0, MAX_GRID_LENGTH); + for(uint8_t i = 0; i < mGridLen; i++) { + snprintf(&buf[i*3], 4, "%02X ", mGridProfile[i]); + } + buf[mGridLen*3] = 0; + return String(buf); + } + private: inline void addAlarm(uint16_t code, uint32_t start, uint32_t end) { lastAlarm[alarmNxtWrPos] = alarm_t(code, start, end); @@ -741,6 +760,8 @@ class Inverter { private: float mOffYD[6], mLastYD[6]; bool mDevControlRequest; // true if change needed + uint8_t mGridLen = 0; + uint8_t mGridProfile[MAX_GRID_LENGTH]; }; template diff --git a/src/web/RestApi.h b/src/web/RestApi.h index a60d55b88..e98b00fe0 100644 --- a/src/web/RestApi.h +++ b/src/web/RestApi.h @@ -109,6 +109,8 @@ class RestApi { getIvStatistis(root, request->url().substring(24).toInt()); else if(path.substring(0, 16) == "inverter/pwrack/") getIvPowerLimitAck(root, request->url().substring(21).toInt()); + else if(path.substring(0, 14) == "inverter/grid/") + getGridProfile(root, request->url().substring(19).toInt()); else getNotFound(root, F("http://") + request->host() + F("/api/")); } @@ -395,6 +397,7 @@ class RestApi { obj[F("rstNotAvail")] = (bool)mConfig->inst.rstValsNotAvail; obj[F("rstComStop")] = (bool)mConfig->inst.rstValsCommStop; obj[F("strtWthtTm")] = (bool)mConfig->inst.startWithoutTime; + obj[F("rdGrid")] = (bool)mConfig->inst.readGrid; obj[F("rstMaxMid")] = (bool)mConfig->inst.rstMaxValsMidNight; obj[F("yldEff")] = mConfig->inst.yieldEffiency; obj[F("gap")] = mConfig->inst.gapMs; @@ -452,6 +455,16 @@ class RestApi { } } + void getGridProfile(JsonObject obj, uint8_t id) { + Inverter<> *iv = mSys->getInverterByPos(id); + if(NULL == iv) { + return; + } + + obj[F("name")] = String(iv->config->name); + obj[F("grid")] = iv->getGridProfile(); + } + void getIvAlarms(JsonObject obj, uint8_t id) { Inverter<> *iv = mSys->getInverterByPos(id); if(NULL == iv) { @@ -484,6 +497,7 @@ class RestApi { record_t<> *rec = iv->getRecordStruct(InverterDevInform_Simple); + obj[F("id")] = id; obj[F("name")] = String(iv->config->name); obj[F("serial")] = String(iv->config->serial.u64, HEX); obj[F("generation")] = iv->ivGen; diff --git a/src/web/html/setup.html b/src/web/html/setup.html index fecebd81c..a1e42a5c5 100644 --- a/src/web/html/setup.html +++ b/src/web/html/setup.html @@ -172,6 +172,10 @@
Start without time sync (useful in AP-Only-Mode)
+
+
Read Grid Profile
+
+
Yield Efficiency (Standard 1.0)
@@ -580,6 +584,7 @@ for(var i of ["Mid", "ComStop", "NotAvail", "MaxMid"]) document.getElementsByName("invRst"+i)[0].checked = obj["rst" + i]; document.getElementsByName("strtWthtTm")[0].checked = obj["strtWthtTm"]; + document.getElementsByName("rdGrid")[0].checked = obj["rdGrid"]; } function parseSys(obj) { diff --git a/src/web/html/visualization.html b/src/web/html/visualization.html index bff8b4e3c..faf76432e 100644 --- a/src/web/html/visualization.html +++ b/src/web/html/visualization.html @@ -289,12 +289,20 @@ tr("Firmware Version / Build", String(obj.fw_ver) + " (build: " + String(obj.fw_date) + " " + String(obj.fw_time) + ")"), tr("Hardware Version / Build", (obj.hw_ver/100).toFixed(2) + " (build: " + String(obj.prod_cw) + "/" + String(obj.prod_year) + ")"), tr("Hardware Number", obj.part_num.toString(16)), - tr("Bootloader Version", (obj.boot_ver/100).toFixed(2)) + tr("Bootloader Version", (obj.boot_ver/100).toFixed(2)), + tr("Grid Profile", ml("input", {type: "button", value: "show", class: "btn", onclick: function() { + modalClose(); + getAjax("/api/inverter/grid/" + obj.id, showGridProfile); + }}, null)) ]) ]); modal("Info for inverter " + obj.name, ml("div", {}, html)); } + function showGridProfile(obj) { + var html = ml("pre", {}, obj.grid); + modal("Grid Profile for inverter " + obj.name, ml("div", {}, html)); + } function parseIvRadioStats(obj) { diff --git a/src/web/web.h b/src/web/web.h index 9dc7ca8f8..b104e9fd0 100644 --- a/src/web/web.h +++ b/src/web/web.h @@ -501,6 +501,7 @@ class Web { mConfig->inst.rstValsCommStop = (request->arg("invRstComStop") == "on"); mConfig->inst.rstValsNotAvail = (request->arg("invRstNotAvail") == "on"); mConfig->inst.startWithoutTime = (request->arg("strtWthtTm") == "on"); + mConfig->inst.readGrid = (request->arg("rdGrid") == "on"); mConfig->inst.rstMaxValsMidNight = (request->arg("invRstMaxMid") == "on"); mConfig->inst.yieldEffiency = (request->arg("yldEff")).toFloat(); mConfig->inst.gapMs = (request->arg("invGap")).toInt();