mirror of
https://github.com/lumapu/ahoy.git
synced 2025-08-03 00:18:24 +02:00
0.8.950001 - zero
Merge branch 'development03' into zero-export
This commit is contained in:
commit
d24c4bdb23
39 changed files with 912 additions and 382 deletions
|
@ -17,11 +17,7 @@
|
|||
#include "../utils/helper.h"
|
||||
#include "lang.h"
|
||||
#include "AsyncJson.h"
|
||||
#if defined(ETHERNET)
|
||||
#include "AsyncWebServer_ESP32_W5500.h"
|
||||
#else
|
||||
#include "ESPAsyncWebServer.h"
|
||||
#endif
|
||||
|
||||
#include "plugins/history.h"
|
||||
|
||||
|
@ -49,6 +45,11 @@ class RestApi {
|
|||
mRadioCmt = (CmtRadio<>*)mApp->getRadioObj(false);
|
||||
#endif
|
||||
mConfig = config;
|
||||
#if defined(ENABLE_HISTORY_LOAD_DATA)
|
||||
mSrv->on("/api/addYDHist",
|
||||
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));
|
||||
#endif
|
||||
mSrv->on("/api", HTTP_POST, std::bind(&RestApi::onApiPost, this, std::placeholders::_1)).onBody(
|
||||
std::bind(&RestApi::onApiPostBody, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5));
|
||||
mSrv->on("/api", HTTP_GET, std::bind(&RestApi::onApi, this, std::placeholders::_1));
|
||||
|
@ -103,6 +104,8 @@ class RestApi {
|
|||
#endif /* !defined(ETHERNET) */
|
||||
else if(path == "live") getLive(request,root);
|
||||
else if (path == "powerHistory") getPowerHistory(request, root);
|
||||
else if (path == "powerHistoryDay") getPowerHistoryDay(request, root);
|
||||
else if (path == "yieldDayHistory") getYieldDayHistory(request, root);
|
||||
else {
|
||||
if(path.substring(0, 12) == "inverter/id/")
|
||||
getInverter(root, request->url().substring(17).toInt());
|
||||
|
@ -137,7 +140,94 @@ class RestApi {
|
|||
#endif
|
||||
}
|
||||
|
||||
void onApiPostBody(AsyncWebServerRequest *request, const uint8_t *data, size_t len, size_t index, size_t total) {
|
||||
#if defined(ENABLE_HISTORY_LOAD_DATA)
|
||||
// VArt67: For debugging history graph. Loading data into graph
|
||||
void onApiPostYDHist(AsyncWebServerRequest *request, String filename, size_t index, uint8_t *data, size_t len, size_t final) {
|
||||
uint32_t total = request->contentLength();
|
||||
DPRINTLN(DBG_DEBUG, "[onApiPostYieldDHistory ] " + filename + " index:" + index + " len:" + len + " total:" + total + " final:" + final);
|
||||
|
||||
if (0 == index) {
|
||||
if (NULL != mTmpBuf)
|
||||
delete[] mTmpBuf;
|
||||
mTmpBuf = new uint8_t[total + 1];
|
||||
mTmpSize = total;
|
||||
}
|
||||
if (mTmpSize >= (len + index))
|
||||
memcpy(&mTmpBuf[index], data, len);
|
||||
|
||||
if (!final)
|
||||
return; // not last frame - nothing to do
|
||||
|
||||
mTmpSize = len + index; // correct the total size
|
||||
mTmpBuf[mTmpSize] = 0;
|
||||
|
||||
#ifndef ESP32
|
||||
DynamicJsonDocument json(ESP.getMaxFreeBlockSize() - 512); // need some memory on heap
|
||||
#else
|
||||
DynamicJsonDocument json(12000); // does this work? I have no ESP32 :-(
|
||||
#endif
|
||||
DeserializationError err = deserializeJson(json, (const char *)mTmpBuf, mTmpSize);
|
||||
json.shrinkToFit();
|
||||
JsonObject obj = json.as<JsonObject>();
|
||||
|
||||
// Debugging
|
||||
// mTmpBuf[mTmpSize] = 0;
|
||||
// DPRINTLN(DBG_DEBUG, (const char *)mTmpBuf);
|
||||
|
||||
if (!err && obj) {
|
||||
// insert data into yieldDayHistory object
|
||||
HistoryStorageType dataType;
|
||||
if (obj["maxDay"] > 0) // this is power history data
|
||||
{
|
||||
dataType = HistoryStorageType::POWER;
|
||||
if (obj["refresh"] > 60)
|
||||
dataType = HistoryStorageType::POWER_DAY;
|
||||
|
||||
}
|
||||
else
|
||||
dataType = HistoryStorageType::YIELD;
|
||||
|
||||
size_t cnt = obj[F("value")].size();
|
||||
DPRINTLN(DBG_DEBUG, "ArraySize: " + String(cnt));
|
||||
|
||||
for (uint16_t i = 0; i < cnt; i++) {
|
||||
uint16_t val = obj[F("value")][i];
|
||||
mApp->addValueToHistory((uint8_t)dataType, 0, val);
|
||||
// DPRINT(DBG_VERBOSE, "value " + String(i) + ": " + String(val) + ", ");
|
||||
}
|
||||
uint32_t refresh = obj[F("refresh")];
|
||||
mApp->addValueToHistory((uint8_t)dataType, 1, refresh);
|
||||
if (dataType != HistoryStorageType::YIELD) {
|
||||
uint32_t ts = obj[F("lastValueTs")];
|
||||
mApp->addValueToHistory((uint8_t)dataType, 2, ts);
|
||||
}
|
||||
|
||||
} else {
|
||||
switch (err.code()) {
|
||||
case DeserializationError::Ok:
|
||||
break;
|
||||
case DeserializationError::IncompleteInput:
|
||||
DPRINTLN(DBG_DEBUG, F("Incomplete input"));
|
||||
break;
|
||||
case DeserializationError::InvalidInput:
|
||||
DPRINTLN(DBG_DEBUG, F("Invalid input"));
|
||||
break;
|
||||
case DeserializationError::NoMemory:
|
||||
DPRINTLN(DBG_DEBUG, F("Not enough memory ") + String(json.capacity()) + " bytes");
|
||||
break;
|
||||
default:
|
||||
DPRINTLN(DBG_DEBUG, F("Deserialization failed"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
request->send(204); // Success with no page load
|
||||
delete[] mTmpBuf;
|
||||
mTmpBuf = NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
void onApiPostBody(AsyncWebServerRequest *request, uint8_t *data, size_t len, size_t index, size_t total) {
|
||||
DPRINTLN(DBG_VERBOSE, "onApiPostBody");
|
||||
|
||||
if(0 == index) {
|
||||
|
@ -207,6 +297,8 @@ class RestApi {
|
|||
ep[F("live")] = url + F("live");
|
||||
#if defined(ENABLE_HISTORY)
|
||||
ep[F("powerHistory")] = url + F("powerHistory");
|
||||
ep[F("powerHistoryDay")] = url + F("powerHistoryDay");
|
||||
ep[F("yieldDayHistory")] = url + F("yieldDayHistory");
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -258,8 +350,9 @@ class RestApi {
|
|||
|
||||
void getGeneric(AsyncWebServerRequest *request, JsonObject obj) {
|
||||
mApp->resetLockTimeout();
|
||||
|
||||
#if !defined(ETHERNET)
|
||||
obj[F("wifi_rssi")] = (WiFi.status() != WL_CONNECTED) ? 0 : WiFi.RSSI();
|
||||
#endif
|
||||
obj[F("ts_uptime")] = mApp->getUptime();
|
||||
obj[F("ts_now")] = mApp->getTimestamp();
|
||||
obj[F("version")] = String(mApp->getVersion());
|
||||
|
@ -286,12 +379,13 @@ class RestApi {
|
|||
obj[F("ssid")] = mConfig->sys.stationSsid;
|
||||
obj[F("ap_pwd")] = mConfig->sys.apPwd;
|
||||
obj[F("hidd")] = mConfig->sys.isHidden;
|
||||
obj[F("mac")] = WiFi.macAddress();
|
||||
obj[F("wifi_channel")] = WiFi.channel();
|
||||
#endif /* !defined(ETHERNET) */
|
||||
obj[F("device_name")] = mConfig->sys.deviceName;
|
||||
obj[F("dark_mode")] = (bool)mConfig->sys.darkMode;
|
||||
obj[F("sched_reboot")] = (bool)mConfig->sys.schedReboot;
|
||||
|
||||
obj[F("mac")] = WiFi.macAddress();
|
||||
obj[F("hostname")] = mConfig->sys.deviceName;
|
||||
obj[F("pwd_set")] = (strlen(mConfig->sys.adminPwd) > 0);
|
||||
obj[F("prot_mask")] = mConfig->sys.protectionMask;
|
||||
|
@ -333,9 +427,9 @@ class RestApi {
|
|||
//obj[F("littlefs_total")] = LittleFS.totalBytes();
|
||||
//obj[F("littlefs_used")] = LittleFS.usedBytes();
|
||||
|
||||
uint8_t max;
|
||||
/*uint8_t max;
|
||||
mApp->getSchedulerInfo(&max);
|
||||
obj[F("schMax")] = max;
|
||||
obj[F("schMax")] = max;*/
|
||||
}
|
||||
|
||||
void getHtmlSystem(AsyncWebServerRequest *request, JsonObject obj) {
|
||||
|
@ -499,7 +593,7 @@ class RestApi {
|
|||
obj[F("name")] = String(iv->config->name);
|
||||
obj[F("serial")] = String(iv->config->serial.u64, HEX);
|
||||
obj[F("version")] = String(iv->getFwVersion());
|
||||
obj[F("power_limit_read")] = iv->actPowerLimit;
|
||||
obj[F("power_limit_read")] = ah::round1(iv->getChannelFieldValue(CH0, FLD_ACT_ACTIVE_PWR_LIMIT, iv->getRecordStruct(SystemConfigPara)));
|
||||
obj[F("power_limit_ack")] = iv->powerLimitAck;
|
||||
obj[F("max_pwr")] = iv->getMaxPower();
|
||||
obj[F("ts_last_success")] = rec->ts;
|
||||
|
@ -873,7 +967,7 @@ class RestApi {
|
|||
void getPowerHistory(AsyncWebServerRequest *request, JsonObject obj) {
|
||||
getGeneric(request, obj.createNestedObject(F("generic")));
|
||||
#if defined(ENABLE_HISTORY)
|
||||
obj[F("refresh")] = mConfig->inst.sendInterval;
|
||||
obj[F("refresh")] = mApp->getHistoryPeriod((uint8_t)HistoryStorageType::POWER);
|
||||
uint16_t max = 0;
|
||||
for (uint16_t fld = 0; fld < HISTORY_DATA_ARR_LENGTH; fld++) {
|
||||
uint16_t value = mApp->getHistoryValue((uint8_t)HistoryStorageType::POWER, fld);
|
||||
|
@ -882,9 +976,39 @@ class RestApi {
|
|||
max = value;
|
||||
}
|
||||
obj[F("max")] = max;
|
||||
obj[F("maxDay")] = mApp->getHistoryMaxDay();
|
||||
#else
|
||||
obj[F("refresh")] = 86400; // 1 day;
|
||||
obj[F("lastValueTs")] = mApp->getHistoryLastValueTs((uint8_t)HistoryStorageType::POWER);
|
||||
#endif /*ENABLE_HISTORY*/
|
||||
}
|
||||
|
||||
void getPowerHistoryDay(AsyncWebServerRequest *request, JsonObject obj){
|
||||
//getGeneric(request, obj.createNestedObject(F("generic")));
|
||||
#if defined(ENABLE_HISTORY)
|
||||
obj[F("refresh")] = mApp->getHistoryPeriod((uint8_t)HistoryStorageType::POWER_DAY);
|
||||
uint16_t max = 0;
|
||||
for (uint16_t fld = 0; fld < HISTORY_DATA_ARR_LENGTH; fld++) {
|
||||
uint16_t value = mApp->getHistoryValue((uint8_t)HistoryStorageType::POWER_DAY, fld);
|
||||
obj[F("value")][fld] = value;
|
||||
if (value > max)
|
||||
max = value;
|
||||
}
|
||||
obj[F("max")] = max;
|
||||
obj[F("lastValueTs")] = mApp->getHistoryLastValueTs((uint8_t)HistoryStorageType::POWER_DAY);
|
||||
#endif /*ENABLE_HISTORY*/
|
||||
}
|
||||
|
||||
|
||||
void getYieldDayHistory(AsyncWebServerRequest *request, JsonObject obj) {
|
||||
//getGeneric(request, obj.createNestedObject(F("generic")));
|
||||
#if defined(ENABLE_HISTORY) && defined(ENABLE_HISTORY_YIELD_PER_DAY)
|
||||
obj[F("refresh")] = mApp->getHistoryPeriod((uint8_t)HistoryStorageType::YIELD);
|
||||
uint16_t max = 0;
|
||||
for (uint16_t fld = 0; fld < HISTORY_DATA_ARR_LENGTH; fld++) {
|
||||
uint16_t value = mApp->getHistoryValue((uint8_t)HistoryStorageType::YIELD, fld);
|
||||
obj[F("value")][fld] = value;
|
||||
if (value > max)
|
||||
max = value;
|
||||
}
|
||||
obj[F("max")] = max;
|
||||
#endif /*ENABLE_HISTORY*/
|
||||
}
|
||||
|
||||
|
|
|
@ -61,6 +61,23 @@ function ml(tagName, ...args) {
|
|||
return nester(el, args[1])
|
||||
}
|
||||
|
||||
function mlNs(tagName, ...args) {
|
||||
var el = document.createElementNS("http://www.w3.org/2000/svg", tagName);
|
||||
if(args[0]) {
|
||||
for(var name in args[0]) {
|
||||
if(name.indexOf("on") === 0) {
|
||||
el.addEventListener(name.substr(2).toLowerCase(), args[0][name], false)
|
||||
} else {
|
||||
el.setAttribute(name, args[0][name]);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!args[1]) {
|
||||
return el;
|
||||
}
|
||||
return nester(el, args[1])
|
||||
}
|
||||
|
||||
function nester(el, n) {
|
||||
if (typeof n === "string") {
|
||||
el.innerHTML = n;
|
||||
|
|
|
@ -30,4 +30,8 @@
|
|||
--ch-head-bg: #006ec0;
|
||||
--ts-head: #333;
|
||||
--ts-bg: #555;
|
||||
|
||||
--chart-cont: #fbfbfb;
|
||||
--chart-bg: #f9f9f9;
|
||||
--chart-text: #000000;
|
||||
}
|
||||
|
|
|
@ -30,4 +30,8 @@
|
|||
--ch-head-bg: #236;
|
||||
--ts-head: #333;
|
||||
--ts-bg: #555;
|
||||
|
||||
--chart-cont: #0b0b0b;
|
||||
--chart-bg: #090909;
|
||||
--chart-text: #FFFFFF;
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
{"0x0d04": "NF_EN_50549-1:2019"},
|
||||
{"0x1000": "ES_RD1699"},
|
||||
{"0x1200": "EU_EN50438"},
|
||||
{"0x1300": "MEX_NOM_220V"},
|
||||
{"0x2600": "BE_C10_26"},
|
||||
{"0x2900": "NL_NEN-EN50549-1_2019"},
|
||||
{"0x2a00": "PL_PN-EN 50549-1:2019"},
|
||||
|
@ -35,6 +36,44 @@
|
|||
{"0xb0": "Watt Power Factor"}
|
||||
],
|
||||
"group": [
|
||||
{
|
||||
"0x0000": [
|
||||
{
|
||||
"name": "Nominal Voltage",
|
||||
"div": 10,
|
||||
"def": 220,
|
||||
"unit": "V"
|
||||
},
|
||||
{
|
||||
"name": "Low Voltage 1",
|
||||
"div": 10,
|
||||
"min": 170,
|
||||
"max": 195.5,
|
||||
"def": 184,
|
||||
"unit": "V"
|
||||
},
|
||||
{
|
||||
"name": "LV1 Maximum Trip Time",
|
||||
"div": 10,
|
||||
"def": 0.1,
|
||||
"unit": "s"
|
||||
},
|
||||
{
|
||||
"name": "High Voltage 1",
|
||||
"div": 10,
|
||||
"min": 253,
|
||||
"max": 275,
|
||||
"def": 270,
|
||||
"unit": "V"
|
||||
},
|
||||
{
|
||||
"name": "HV1 Maximum Trip Time",
|
||||
"div": 10,
|
||||
"def": 0.1,
|
||||
"unit": "s"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"0x0003": [
|
||||
{
|
||||
|
|
|
@ -13,84 +13,177 @@
|
|||
<div id="wrapper">
|
||||
<div id="content">
|
||||
<h3>{#TOTAL_POWER}</h3>
|
||||
<div>
|
||||
<div class="chartDiv" id="pwrChart"> </div>
|
||||
<p>
|
||||
{#MAX_DAY}: <span id="pwrMaxDay"></span> W. {#LAST_VALUE}: <span id="pwrLast"></span> W.<br />
|
||||
{#MAXIMUM}: <span id="pwrMax"></span> W. {#UPDATED} <span id="pwrRefresh"></span> {#SECONDS}
|
||||
</p>
|
||||
</div>
|
||||
<div class="chartDiv" id="pwrChart"></div>
|
||||
<h3>{#TOTAL_POWER_DAY}</h3>
|
||||
<div class="chartDiv" id="pwrDayChart"></div>
|
||||
<!--IF_ENABLE_HISTORY_YIELD_PER_DAY-->
|
||||
<h3>{#TOTAL_YIELD_PER_DAY}</h3>
|
||||
<div class="chartDiv" id="ydChart"></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>
|
||||
<fieldset style="padding: 1px;">
|
||||
<legend class="des" style="margin-top: 0px;">Insert data (*.json) i.e. from a saved "/api/yieldDayHistory" call
|
||||
</legend>
|
||||
<form id="form" method="POST" action="/api/addYDHist" enctype="multipart/form-data"
|
||||
accept-charset="utf-8">
|
||||
<input type="button" class="btn my-4" style="padding: 3px;margin: 3px;" value="Insert" onclick="submit()">
|
||||
<input type="file" name="insert" style="width: 80%;">
|
||||
</form>
|
||||
</fieldset>
|
||||
<!--ENDIF_ENABLE_HISTORY_LOAD_DATA-->
|
||||
</div>
|
||||
</div>
|
||||
{#HTML_FOOTER}
|
||||
|
||||
<script type="text/javascript">
|
||||
const svgns = "http://www.w3.org/2000/svg";
|
||||
var pwrExeOnce = true;
|
||||
var ydExeOnce = true;
|
||||
// make a simple rectangle
|
||||
var mRefresh = 60;
|
||||
var mLastValue = 0;
|
||||
const mChartHeight = 250;
|
||||
const height = 250
|
||||
var once = true
|
||||
|
||||
function parseHistory(obj, namePrefix, execOnce) {
|
||||
mRefresh = obj.refresh
|
||||
var data = Object.assign({}, obj.value)
|
||||
numDataPts = Object.keys(data).length
|
||||
function calcScale(obj) {
|
||||
let s = {}
|
||||
s.x_mul = 60
|
||||
s.ts_start = obj.lastValueTs - (obj.refresh * obj.value.length)
|
||||
s.ts_dur = obj.lastValueTs - s.ts_start
|
||||
s.ts_pad = (s.ts_dur < 1800) ? s.ts_start % 300 : s.ts_start % 1800
|
||||
s.ts_dur -= s.ts_pad
|
||||
while(s.x_mul * 10 <= s.ts_dur)
|
||||
s.x_mul += (s.x_mul == 60) ? 240 : ((s.x_mul < 1800) ? 300 : 1800)
|
||||
s.x_step = Math.ceil(s.ts_dur / s.x_mul)
|
||||
s.x_max = s.x_mul * s.x_step
|
||||
|
||||
if (true == execOnce) {
|
||||
let s = document.createElementNS(svgns, "svg");
|
||||
s.setAttribute("class", "chart");
|
||||
s.setAttribute("width", (numDataPts + 2) * 2);
|
||||
s.setAttribute("height", mChartHeight);
|
||||
s.setAttribute("role", "img");
|
||||
|
||||
let g = document.createElementNS(svgns, "g");
|
||||
s.appendChild(g);
|
||||
for (var i = 0; i < numDataPts; i++) {
|
||||
val = data[i];
|
||||
let rect = document.createElementNS(svgns, "rect");
|
||||
rect.setAttribute("id", namePrefix+"Rect" + i);
|
||||
rect.setAttribute("x", i * 2);
|
||||
rect.setAttribute("width", 2);
|
||||
g.appendChild(rect);
|
||||
}
|
||||
document.getElementById(namePrefix+"Chart").appendChild(s);
|
||||
}
|
||||
|
||||
// normalize data to chart
|
||||
let divider = obj.max / mChartHeight;
|
||||
if (divider == 0)
|
||||
divider = 1;
|
||||
for (var i = 0; i < numDataPts; i++) {
|
||||
val = data[i];
|
||||
if (val > 0)
|
||||
mLastValue = val
|
||||
val = val / divider
|
||||
rect = document.getElementById(namePrefix+"Rect" + i);
|
||||
rect.setAttribute("height", val);
|
||||
rect.setAttribute("y", mChartHeight - val);
|
||||
}
|
||||
document.getElementById(namePrefix + "Max").innerHTML = obj.max;
|
||||
if (mRefresh < 5)
|
||||
mRefresh = 5;
|
||||
document.getElementById(namePrefix + "Refresh").innerHTML = mRefresh;
|
||||
s.y_mul = 10
|
||||
while(s.y_mul * 10 <= obj.max)
|
||||
s.y_mul += (s.y_mul < 100) ? 10 : 100
|
||||
s.y_step = Math.ceil(obj.max / s.y_mul)
|
||||
s.y_max = s.y_mul * s.y_step
|
||||
return s
|
||||
}
|
||||
|
||||
function setupSvg(id, obj) {
|
||||
let scale = calcScale(obj)
|
||||
let n = obj.value.length
|
||||
return mlNs("svg", {class: "container", id: id+"_svg", viewBox: "0 0 "+String(n*2+50)+" "+String(height+20), width: "100%", height: "100%"}, [
|
||||
mlNs("defs", {}, [
|
||||
mlNs("linearGradient", {id: "gLine", x1: 0, y1: 0, x2: 0, y2: "100%"}, [
|
||||
mlNs("stop", {offset: 0, "stop-color": "#006ec0"}),
|
||||
mlNs("stop", {offset: "80%", "stop-color": "#5050ff"}),
|
||||
mlNs("stop", {offset: "100%", "stop-color": "gray"})
|
||||
]),
|
||||
mlNs("linearGradient", {id: "gFill", x1: 0, y1: 0, x2: 0, y2: "100%"}, [
|
||||
mlNs("stop", {offset: 0, "stop-color": "#006ec0"}),
|
||||
mlNs("stop", {offset: "50%", "stop-color": "#0034c0"}),
|
||||
mlNs("stop", {offset: "100%", "stop-color": "#e0e0e0"})
|
||||
])
|
||||
]),
|
||||
...gridText(n*2, scale),
|
||||
mlNs("g", {transform: "translate(30, 5)"}, [
|
||||
...grid(n*2, scale),
|
||||
...poly(obj, scale)
|
||||
])
|
||||
])
|
||||
}
|
||||
|
||||
function gridText(x2, scale) {
|
||||
let g = []
|
||||
let div = height / scale.y_max
|
||||
for(let i = 0; i <= scale.y_max; i += scale.y_mul) {
|
||||
g.push(mlNs("text", {x: 0, y: height-(i*div)+9}, String(i)))
|
||||
}
|
||||
div = x2 / scale.x_max
|
||||
for(let i = 0; i < scale.x_max; i++) {
|
||||
if((i + scale.ts_pad) % scale.x_mul == 0) {
|
||||
let d = new Date((scale.ts_start + i) * 1000)
|
||||
g.push(mlNs("text", {x: (i*div)+17, y: height+20}, ("0"+d.getHours()).slice(-2) + ":" + ("0"+d.getMinutes()).slice(-2)))
|
||||
}
|
||||
}
|
||||
return g
|
||||
}
|
||||
|
||||
function grid(x2, scale) {
|
||||
let g = []
|
||||
let div = height / scale.y_max
|
||||
for(let i = 0; i <= scale.y_max; i += scale.y_mul) {
|
||||
g.push(mlNs("line", {x1: 0, x2: x2, y1: height-i*div, y2: height-i*div, "stroke-width": 1, "stroke-dasharray": "1,3", stroke: "#aaa"}))
|
||||
}
|
||||
div = x2 / scale.x_max
|
||||
for(let i = 0; i <= scale.x_max; i++) {
|
||||
if((i + scale.ts_pad) % scale.x_mul == 0) {
|
||||
g.push(mlNs("line", {x1: (i*div), x2: (i*div), y1: 0, y2: height, "stroke-width": 1, "stroke-dasharray": "1,3", stroke: "#aaa"}))
|
||||
}
|
||||
}
|
||||
return g
|
||||
}
|
||||
|
||||
function poly(obj, scale) {
|
||||
let pts = ""
|
||||
let i = 0, first = -1, last = -1, lastVal = 0
|
||||
let div = scale.y_max / height
|
||||
if(div == 0)
|
||||
div = 1
|
||||
for (val of obj.value) {
|
||||
if(val > 0) {
|
||||
lastVal = val
|
||||
pts += " " + String(i) + "," + String(height - val / div)
|
||||
if(first < 0)
|
||||
first = i
|
||||
last = i
|
||||
}
|
||||
i += 2
|
||||
}
|
||||
let pts2 = pts + " " + String(last) + "," + String(height)
|
||||
pts2 += " " + String(first) + "," + String(height)
|
||||
return [
|
||||
mlNs("polyline", {stroke: "url(#gLine)", fill: "none", points: pts}),
|
||||
mlNs("polyline", {stroke: "none", fill: "url(#gFill)", points: pts2}),
|
||||
mlNs("text", {x: i*.8, y: 10}, "{#MAX_DAY}: " + String(obj.max) + "W"),
|
||||
mlNs("text", {x: i*.8, y: 25}, "{#LAST_VALUE}: " + String(lastVal) + "W")
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
function parsePowerHistory(obj){
|
||||
if (null != obj) {
|
||||
parseNav(obj.generic);
|
||||
parseESP(obj.generic);
|
||||
parseHistory(obj,"pwr", pwrExeOnce)
|
||||
document.getElementById("pwrLast").innerHTML = mLastValue
|
||||
document.getElementById("pwrMaxDay").innerHTML = obj.maxDay
|
||||
if(once) {
|
||||
once = false
|
||||
parseNav(obj.generic)
|
||||
parseESP(obj.generic)
|
||||
parseRssi(obj.generic)
|
||||
window.setInterval("getAjax('/api/powerHistory', parsePowerHistory)", obj.refresh * 1000)
|
||||
setTimeout(() => {
|
||||
window.setInterval("getAjax('/api/powerHistoryDay', parsePowerHistoryDay)", refresh * 1000)
|
||||
}, 200)
|
||||
/*IF_ENABLE_HISTORY_YIELD_PER_DAY*/
|
||||
setTimeout(() => {
|
||||
window.setInterval("getAjax('/api/yieldDayHistory', parseYieldDayHistory)", refresh * 1000)
|
||||
}, 400)
|
||||
/*ENDIF_ENABLE_HISTORY_YIELD_PER_DAY*/
|
||||
}
|
||||
if (pwrExeOnce) {
|
||||
pwrExeOnce = false;
|
||||
window.setInterval("getAjax('/api/powerHistory', parsePowerHistory)", mRefresh * 1000);
|
||||
if (null != obj) {
|
||||
let svg = setupSvg("ph", obj);
|
||||
document.getElementById("pwrChart").replaceChildren(svg);
|
||||
setTimeout(() => { getAjax("/api/powerHistoryDay", parsePowerHistoryDay) }, 50);
|
||||
}
|
||||
}
|
||||
|
||||
function parsePowerHistoryDay(obj) {
|
||||
if (null != obj) {
|
||||
let svg = setupSvg("phDay", obj);
|
||||
document.getElementById("pwrDayChart").replaceChildren(svg);
|
||||
/*IF_ENABLE_HISTORY_YIELD_PER_DAY*/
|
||||
setTimeout(() => { getAjax("/api/yieldDayHistory", parseYieldDayHistory) }, 50);
|
||||
/*ENDIF_ENABLE_HISTORY_YIELD_PER_DAY*/
|
||||
}
|
||||
}
|
||||
|
||||
/*IF_ENABLE_HISTORY_YIELD_PER_DAY*/
|
||||
function parseYieldDayHistory(obj) {
|
||||
if (null != obj) {
|
||||
let svg = setupSvg("phDay", obj);
|
||||
document.getElementById("pwrDayChart").replaceChildren(svg);
|
||||
}
|
||||
}
|
||||
/*ENDIF_ENABLE_HISTORY_YIELD_PER_DAY*/
|
||||
|
||||
getAjax("/api/powerHistory", parsePowerHistory);
|
||||
</script>
|
||||
</body>
|
||||
|
|
|
@ -33,13 +33,17 @@ textarea {
|
|||
color: var(--fg2);
|
||||
}
|
||||
|
||||
svg rect {fill: #00A;}
|
||||
svg.chart {
|
||||
background: #f2f2f2;
|
||||
border: 2px solid gray;
|
||||
padding: 1px;
|
||||
svg polyline {
|
||||
fill-opacity: .5;
|
||||
stroke-width: 1;
|
||||
}
|
||||
|
||||
svg text {
|
||||
font-size: x-small;
|
||||
fill: var(--chart-text);
|
||||
}
|
||||
|
||||
|
||||
div.chartDivContainer {
|
||||
padding: 1px;
|
||||
margin: 1px;
|
||||
|
|
|
@ -21,8 +21,8 @@
|
|||
}
|
||||
|
||||
function parseSysInfo(obj) {
|
||||
const data = ["sdk", "cpu_freq", "chip_revision",
|
||||
"chip_model", "chip_cores", "esp_type", "mac", "wifi_rssi", "ts_uptime",
|
||||
const data = ["sdk", "cpu_freq", "chip_revision", "device_name",
|
||||
"chip_model", "chip_cores", "esp_type", "mac", "wifi_rssi", "wifi_channel", "ts_uptime",
|
||||
"flash_size", "sketch_used", "heap_total", "heap_free", "heap_frag",
|
||||
"max_free_blk", "version", "modules", "env", "core_version", "reboot_reason"];
|
||||
|
||||
|
@ -49,7 +49,7 @@
|
|||
case 0: return badge(false, "{#UNKNOWN}", "warning"); break;
|
||||
case 1: return badge(true, "{#TRUE}"); break;
|
||||
default: return badge(false, "{#FALSE}"); break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function parseRadio(obj) {
|
||||
|
|
|
@ -118,7 +118,7 @@
|
|||
if(65535 != obj.power_limit_read) {
|
||||
pwrLimit = obj.power_limit_read + " %";
|
||||
if(0 != obj.max_pwr)
|
||||
pwrLimit += ", " + Math.round(obj.max_pwr * obj.power_limit_read / 100) + " W";
|
||||
pwrLimit += ", " + (obj.max_pwr * obj.power_limit_read / 100) + " W";
|
||||
}
|
||||
|
||||
var maxAcPwr = toIsoDateStr(new Date(obj.ts_max_ac_pwr * 1000));
|
||||
|
|
|
@ -1753,6 +1753,11 @@
|
|||
"en": "Total Power",
|
||||
"de": "Gesamtleistung"
|
||||
},
|
||||
{
|
||||
"token": "TOTAL_POWER_DAY",
|
||||
"en": "Total Power Today",
|
||||
"de": "Gesamtleistung heute"
|
||||
},
|
||||
{
|
||||
"token": "TOTAL_YIELD_PER_DAY",
|
||||
"en": "Total Yield per day",
|
||||
|
@ -1760,28 +1765,13 @@
|
|||
},
|
||||
{
|
||||
"token": "MAX_DAY",
|
||||
"en": "maximum day",
|
||||
"en": "Maximum day",
|
||||
"de": "Tagesmaximum"
|
||||
},
|
||||
{
|
||||
"token": "LAST_VALUE",
|
||||
"en": "last value",
|
||||
"de": "letzter Wert"
|
||||
},
|
||||
{
|
||||
"token": "MAXIMUM",
|
||||
"en": "maximum value",
|
||||
"de": "Maximalwert"
|
||||
},
|
||||
{
|
||||
"token": "UPDATED",
|
||||
"en": "Updated every",
|
||||
"de": "aktualisiert alle"
|
||||
},
|
||||
{
|
||||
"token": "SECONDS",
|
||||
"en": "seconds",
|
||||
"de": "Sekunden"
|
||||
"en": "Last value",
|
||||
"de": "Letzter Wert"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
@ -16,11 +16,7 @@
|
|||
#include "../appInterface.h"
|
||||
#include "../hm/hmSystem.h"
|
||||
#include "../utils/helper.h"
|
||||
#if defined(ETHERNET)
|
||||
#include "AsyncWebServer_ESP32_W5500.h"
|
||||
#else /* defined(ETHERNET) */
|
||||
#include "ESPAsyncWebServer.h"
|
||||
#endif /* defined(ETHERNET) */
|
||||
#include "html/h/api_js.h"
|
||||
#include "html/h/colorBright_css.h"
|
||||
#include "html/h/colorDark_css.h"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue