Browse Source

update web, moved radio statistics to live view (footer of inverter) as modal

pull/1197/head
lumapu 2 years ago
parent
commit
c3162fd2ed
  1. 30
      src/web/RestApi.h
  2. 9
      src/web/html/api.js
  3. 22
      src/web/html/system.html
  4. 43
      src/web/html/visualization.html

30
src/web/RestApi.h

@ -107,6 +107,8 @@ class RestApi {
getIvAlarms(root, request->url().substring(20).toInt()); getIvAlarms(root, request->url().substring(20).toInt());
else if(path.substring(0, 17) == "inverter/version/") else if(path.substring(0, 17) == "inverter/version/")
getIvVersion(root, request->url().substring(22).toInt()); getIvVersion(root, request->url().substring(22).toInt());
else if(path.substring(0, 17) == "inverter/radiostat/")
getIvStatistis(root, request->url().substring(24).toInt());
else else
getNotFound(root, F("http://") + request->host() + F("/api/")); getNotFound(root, F("http://") + request->host() + F("/api/"));
} }
@ -245,7 +247,6 @@ class RestApi {
getRadioCmtInfo(obj.createNestedObject(F("radioCmt"))); getRadioCmtInfo(obj.createNestedObject(F("radioCmt")));
#endif #endif
getMqttInfo(obj.createNestedObject(F("mqtt"))); getMqttInfo(obj.createNestedObject(F("mqtt")));
getStatistics(obj.createNestedArray(F("statistics")));
#if defined(ESP32) #if defined(ESP32)
obj[F("chip_revision")] = ESP.getChipRevision(); obj[F("chip_revision")] = ESP.getChipRevision();
@ -310,23 +311,18 @@ class RestApi {
obj[F("html")] = F("reboot. Autoreload after 10 seconds"); obj[F("html")] = F("reboot. Autoreload after 10 seconds");
} }
void getStatistics(JsonArray arr) { void getIvStatistis(JsonObject obj, uint8_t id) {
statistics_t *stat; Inverter<> *iv = mSys->getInverterByPos(id);
#if defined(ESP32) if(NULL == iv) {
for(uint8_t i = 0; i < 2; i++) { obj[F("error")] = F("inverter not found!");
stat = (0 == i) ? mApp->getNrfStatistics() : mApp->getCmtStatistics(); return;
#else
{
stat = mApp->getNrfStatistics();
#endif
JsonObject obj = arr.createNestedObject();
obj[F("rx_success")] = stat->rxSuccess;
obj[F("rx_fail")] = stat->rxFail;
obj[F("rx_fail_answer")] = stat->rxFailNoAnser;
obj[F("frame_cnt")] = stat->frmCnt;
obj[F("tx_cnt")] = stat->txCnt;
obj[F("retransmits")] = stat->retransmits;
} }
obj[F("rx_success")] = iv->radioStatistics.rxSuccess;
obj[F("rx_fail")] = iv->radioStatistics.rxFail;
obj[F("rx_fail_answer")] = iv->radioStatistics.rxFailNoAnser;
obj[F("frame_cnt")] = iv->radioStatistics.frmCnt;
obj[F("tx_cnt")] = iv->radioStatistics.txCnt;
obj[F("retransmits")] = iv->radioStatistics.retransmits;
} }
void getInverterList(JsonObject obj) { void getInverterList(JsonObject obj) {

9
src/web/html/api.js

@ -172,6 +172,15 @@ function getAjax(url, ptr, method="GET", json=null) {
* CREATE DOM FUNCTIONS * CREATE DOM FUNCTIONS
*/ */
function tr(val1, val2) {
if(typeof val2 == "number")
val2 = String(val2);
return ml("tr", {}, [
ml("th", {style: "width: 50%"}, val1),
ml("td", {}, val2)
]);
}
function des(val) { function des(val) {
e = document.createElement('p'); e = document.createElement('p');
e.classList.add("subdes"); e.classList.add("subdes");

22
src/web/html/system.html

@ -48,26 +48,6 @@
return ml("div", {class: "head p-2 mt-3"}, ml("div", {class: "row"}, ml("div", {class: "col a-c"}, text))) return ml("div", {class: "head p-2 mt-3"}, ml("div", {class: "row"}, ml("div", {class: "col a-c"}, text)))
} }
function tr(val1, val2) {
if(typeof val2 == "number")
val2 = String(val2);
return ml("tr", {}, [
ml("th", {style: "width: 50%"}, val1),
ml("td", {}, val2)
]);
}
function parseStat(stat) {
return [
tr("TX count", stat.tx_cnt),
tr("RX success", stat.rx_success),
tr("RX fail", stat.rx_fail),
tr("RX no answer", stat.rx_fail_answer),
tr("RX fragments", stat.frame_cnt),
tr("TX retransmits", stat.retransmits)
];
}
function parseRadio(obj) { function parseRadio(obj) {
const pa = ["MIN (recommended)", "LOW", "HIGH", "MAX"]; const pa = ["MIN (recommended)", "LOW", "HIGH", "MAX"];
const dr = ["1 M", "2 M", "250 k"] const dr = ["1 M", "2 M", "250 k"]
@ -78,7 +58,6 @@
tr("NRF24 Power Level", pa[obj.radioNrf.power_level]), tr("NRF24 Power Level", pa[obj.radioNrf.power_level]),
tr("NRF24 Data Rate", dr[obj.radioNrf.dataRate] + "bps") tr("NRF24 Data Rate", dr[obj.radioNrf.dataRate] + "bps")
]; ];
Array.prototype.push.apply(lines, parseStat(obj.statistics[0]));
} else } else
lines = [tr("NRF24L01", badge(false, "not enabled"))]; lines = [tr("NRF24L01", badge(false, "not enabled"))];
@ -92,7 +71,6 @@
/*IF_ESP32*/ /*IF_ESP32*/
if(obj.radioCmt.en) { if(obj.radioCmt.en) {
cmt = [tr("CMT2300A", badge(obj.radioCmt.isconnected, ((obj.radioCmt.isconnected) ? "" : "not ") + "connected"))]; cmt = [tr("CMT2300A", badge(obj.radioCmt.isconnected, ((obj.radioCmt.isconnected) ? "" : "not ") + "connected"))];
Array.prototype.push.apply(cmt, parseStat(obj.statistics[1]));
} else } else
cmt = [tr("CMT2300A", badge(false, "not enabled"))]; cmt = [tr("CMT2300A", badge(false, "not enabled"))];

43
src/web/html/visualization.html

@ -198,7 +198,9 @@
ml("div", {class: "col"}, "") ml("div", {class: "col"}, "")
), ),
ml("div", {class: "row p-2 ts-bg mx-2"}, ml("div", {class: "row p-2 ts-bg mx-2"},
ml("div", {class: "col mx-2"}, ageInfo) ml("div", { class: "pointer col mx-2", onclick: function() {
getAjax("/api/inverter/radiostat/" + obj.id, parseIvRadioStats);
}}, ageInfo)
) )
]); ]);
} }
@ -279,26 +281,25 @@
var html = ml("table", {class: "table"}, [ var html = ml("table", {class: "table"}, [
ml("tbody", {}, [ ml("tbody", {}, [
ml("tr", {}, [ tr("Model", model),
ml("th", {}, "Model"), tr("Firmware Version / Build", String(obj.fw_ver) + " (build: " + String(obj.fw_date) + " " + String(obj.fw_time) + ")"),
ml("td", {}, model) 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)),
ml("tr", {}, [ tr("Bootloader Version", (obj.boot_ver/100).toFixed(2))
ml("th", {}, "Firmware Version / Build"), ])
ml("td", {}, String(obj.fw_ver) + " (build: " + String(obj.fw_date) + " " + String(obj.fw_time) + ")") ]);
]), modal("Info for inverter " + obj.name, ml("div", {}, html));
ml("tr", {}, [ }
ml("th", {}, "Hardware Version / Build"),
ml("td", {}, (obj.hw_ver/100).toFixed(2) + " (build: " + String(obj.prod_cw) + "/" + String(obj.prod_year) + ")") function parseIvRadioStats(obj) {
]), var html = ml("table", {class: "table"}, [
ml("tr", {}, [ ml("tbody", {}, [
ml("th", {}, "Hardware Number"), tr("TX count", obj.tx_cnt),
ml("td", {}, obj.part_num.toString(16)) tr("RX success", obj.rx_success),
]), tr("RX fail", obj.rx_fail),
ml("tr", {}, [ tr("RX no answer", obj.rx_fail_answer),
ml("th", {}, "Bootloader Version"), tr("RX fragments", obj.frame_cnt),
ml("td", {}, (obj.boot_ver/100).toFixed(2)) tr("TX retransmits", obj.retransmits)
])
]) ])
]); ]);
modal("Info for inverter " + obj.name, ml("div", {}, html)); modal("Info for inverter " + obj.name, ml("div", {}, html));

Loading…
Cancel
Save