Visualization
@@ -46,7 +15,7 @@
Setup
Uptime:
-Statistics:
+Statistics:
Every {TS}seconds the values are updated
diff --git a/tools/esp8266/app.cpp b/tools/esp8266/app.cpp index 2bdb29ec..0685dcb4 100644 --- a/tools/esp8266/app.cpp +++ b/tools/esp8266/app.cpp @@ -42,7 +42,7 @@ void app::setup(uint32_t timeout) { #endif mSys->setup(&mConfig); - mWebInst = new web(this, &mSysConfig, &mConfig, mVersion); + mWebInst = new web(this, &mSysConfig, &mConfig, &mStat, mVersion); mWebInst->setup(); } @@ -88,7 +88,7 @@ void app::loop(void) { DPRINT(DBG_INFO, "RX " + String(len) + "B Ch" + String(p->rxCh) + " | "); mSys->Radio.dumpBuf(NULL, p->packet, len); } - mFrameCnt++; + mStat.frmCnt++; if(0 != len) { Inverter<> *iv = mSys->findInverter(&p->packet[1]); @@ -231,7 +231,7 @@ void app::loop(void) { processPayload(false); if(!mPayload[iv->id].complete) { - mRxFailed++; + mStat.rxFail++; iv->setQueuedCmdFinished(); // command failed if(mConfig.serialDebug) { DPRINTLN(DBG_INFO, F("enqueued cmd failed/timeout")); @@ -358,7 +358,7 @@ void app::processPayload(bool retransmit) { DPRINT(DBG_INFO, F("Payload (") + String(offs) + "): "); mSys->Radio.dumpBuf(NULL, payload, offs); } - mRxSuccess++; + mStat.rxSuccess++; iv->getAssignment(); // choose the parser for(uint8_t i = 0; i < iv->listLen; i++) { @@ -498,9 +498,9 @@ void app::cbMqtt(char* topic, byte* payload, unsigned int length) { //----------------------------------------------------------------------------- String app::getStatistics(void) { - String content = F("Receive success: ") + String(mRxSuccess) + "\n"; - content += F("Receive fail: ") + String(mRxFailed) + "\n"; - content += F("Frames received: ") + String(mFrameCnt) + "\n"; + String content = F("Receive success: ") + String(mStat.rxSuccess) + "\n"; + content += F("Receive fail: ") + String(mStat.rxFail) + "\n"; + content += F("Frames received: ") + String(mStat.frmCnt) + "\n"; content += F("Send Cnt: ") + String(mSys->Radio.mSendCnt) + String("\n\n"); Inverter<> *iv; @@ -686,9 +686,7 @@ void app::resetSystem(void) { memset(mPayload, 0, (MAX_NUM_INVERTERS * sizeof(invPayload_t))); - mRxFailed = 0; - mRxSuccess = 0; - mFrameCnt = 0; + memset(&mStat, 0, sizeof(statistics_t)); mLastPacketId = 0x00; } diff --git a/tools/esp8266/app.h b/tools/esp8266/app.h index a3a33d20..1fd3b5db 100644 --- a/tools/esp8266/app.h +++ b/tools/esp8266/app.h @@ -48,7 +48,6 @@ typedef struct { bool requested; } invPayload_t; - class ahoywifi; class web; @@ -239,9 +238,7 @@ class app { uint8_t mSendLastIvId; invPayload_t mPayload[MAX_NUM_INVERTERS]; - uint32_t mRxFailed; - uint32_t mRxSuccess; - uint32_t mFrameCnt; + statistics_t mStat; uint8_t mLastPacketId; // timer diff --git a/tools/esp8266/defines.h b/tools/esp8266/defines.h index 210604a5..867b3cb5 100644 --- a/tools/esp8266/defines.h +++ b/tools/esp8266/defines.h @@ -154,6 +154,12 @@ typedef struct { } /*__attribute__((__packed__))*/ config_t; #pragma pack(pop) // restore original alignment from stack +typedef struct { + uint32_t rxFail; + uint32_t rxSuccess; + uint32_t frmCnt; +} statistics_t; + #define CFG_MQTT_LEN MQTT_ADDR_LEN + 2 + MQTT_USER_LEN + MQTT_PWD_LEN +MQTT_TOPIC_LEN #define CFG_SYS_LEN DEVNAME_LEN + SSID_LEN + PWD_LEN + 1 diff --git a/tools/esp8266/html/api.js b/tools/esp8266/html/api.js new file mode 100644 index 00000000..f8b002a9 --- /dev/null +++ b/tools/esp8266/html/api.js @@ -0,0 +1,65 @@ +function toggle(name, hide) { + var elm = document.getElementsByName(name)[0]; + if(hide) { + if(!elm.classList.contains("hide")) + elm.classList.add("hide"); + } + else + elm.classList.remove('hide'); +} + +function getAjax(url, ptr) { + var http = new XMLHttpRequest(); + if(http != null) { + http.open("GET", url, true); + http.onreadystatechange = p; + http.send(null); + } + function p() { + if(http.readyState == 4) + ptr(JSON.parse(http.responseText)); + } +} + +function des(val) { + e = document.createElement('p'); + e.classList.add("subdes"); + e.innerHTML = val; + return e; +} + +function lbl(id, val) { + e = document.createElement('label'); + e.htmlFor = id; + e.innerHTML = val; + return e; +} + +function inp(name, val, max=32, cl=["text"]) { + e = document.createElement('input'); + e.classList.add(...cl); + e.name = name; + e.value = val; + e.maxLength = max; + return e; +} + +function sel(name, opt, selId) { + e = document.createElement('select'); + e.name = name; + for(it of opt) { + o = document.createElement('option'); + o.value = it[0]; + o.innerHTML = it[1]; + if(it[0] == selId) + o.selected = true; + e.appendChild(o); + } + return e; +} + +function div(cl) { + e = document.createElement('div'); + e.classList.add(cl); + return e; +} diff --git a/tools/esp8266/html/convert.py b/tools/esp8266/html/convert.py index 953dafca..333cf61e 100755 --- a/tools/esp8266/html/convert.py +++ b/tools/esp8266/html/convert.py @@ -7,30 +7,36 @@ def convert2Header(inFile, compress): define = inFile.split(".")[0].upper() define2 = inFile.split(".")[1].upper() inFileVarName = inFile.replace(".", "_") + print(inFile + ", compress: " + str(compress)) if os.getcwd()[-4:] != "html": - print("ok") outName = "html/" + "h/" + inFileVarName + ".h" inFile = "html/" + inFile else: outName = "h/" + inFileVarName + ".h" f = open(inFile, "r") - data = f.read().replace('\n', '') + data = f.read() f.close() - if False == compress: - if fileType == "html": + + if fileType == "html": + if False == compress: + data = data.replace('\n', '') data = re.sub(r"\>\s+\<", '><', data) # whitespaces between xml tags - data = re.sub(r"(\s?\;|\}|\>|\{|\=)\s+", r'\1', data) # whitespaces inner javascript - length = len(data) # get unescaped length - data = re.sub(r"\"", '\\\"', data) # escape quotation marks - else: - data = re.sub(r"(\;|\}|\:|\{)\s+", r'\1', data) # whitespaces inner css - length = len(data) # get unescaped length - else: - data = re.sub(r"\>\s+\<", '><', data) # whitespaces between xml tags - data = re.sub(r"(\;|\}|\>|\{)\s+", r'\1', data) # whitespaces inner javascript + data = re.sub(r"(\r\n|\r|\n)(\s+|\s?)", '', data) # whitespaces inner javascript length = len(data) # get unescaped length + if False == compress: + data = re.sub(r"\"", '\\\"', data) # escape quotation marks + elif fileType == "js": + #data = re.sub(r"(\r\n|\r|\n)(\s+|\s?)", '', data) # whitespaces inner javascript + #data = re.sub(r"\s?(\=|\!\=|\{|,)+\s?", r'\1', data) # whitespaces inner javascript + length = len(data) # get unescaped length + if False == compress: + data = re.sub(r"\"", '\\\"', data) # escape quotation marks + else: + data = data.replace('\n', '') + data = re.sub(r"(\;|\}|\:|\{)\s+", r'\1', data) # whitespaces inner css + length = len(data) # get unescaped length # get unescaped length f = open(outName, "w") f.write("#ifndef __{}_{}_H__\n".format(define, define2)) @@ -52,8 +58,9 @@ def convert2Header(inFile, compress): f.write("#endif /*__{}_{}_H__*/\n".format(define, define2)) f.close() -convert2Header("index.html", False) +convert2Header("index.html", True) convert2Header("setup.html", True) convert2Header("visualization.html", False) convert2Header("update.html", False) -convert2Header("style.css", False) +convert2Header("style.css", True) +convert2Header("api.js", True) diff --git a/tools/esp8266/html/index.html b/tools/esp8266/html/index.html index de381281..73e53b34 100644 --- a/tools/esp8266/html/index.html +++ b/tools/esp8266/html/index.html @@ -1,44 +1,13 @@
-
Visualization
@@ -46,7 +15,7 @@
Setup
Uptime:
-Statistics:
+Statistics:
Every {TS}seconds the values are updated