From 13c88b3626305dd625482630ddb7c3be4174fec0 Mon Sep 17 00:00:00 2001 From: lumapu Date: Sat, 27 Aug 2022 02:27:32 +0200 Subject: [PATCH] * created new API functions * bound html through ajax to parse setup page (not finished now) * added compression option for static html to python module * removed generated h-file from index (redundant information), they will be created on compile time --- .gitignore | 1 + tools/esp8266/api.cpp | 100 +++++++++++++ tools/esp8266/api.h | 32 +++++ tools/esp8266/defines.h | 2 +- tools/esp8266/html/convert.py | 44 ++++-- tools/esp8266/html/h/favicon_ico_gz.h | 100 ------------- tools/esp8266/html/h/index_html.h | 5 - tools/esp8266/html/h/setup_html.h | 5 - tools/esp8266/html/h/style_css.h | 5 - tools/esp8266/html/h/visualization_html.h | 5 - tools/esp8266/html/setup.html | 165 ++++++++++++++++++++-- tools/esp8266/web.cpp | 90 ++++-------- tools/esp8266/web.h | 6 + 13 files changed, 347 insertions(+), 213 deletions(-) create mode 100644 tools/esp8266/api.cpp create mode 100644 tools/esp8266/api.h delete mode 100644 tools/esp8266/html/h/favicon_ico_gz.h delete mode 100644 tools/esp8266/html/h/index_html.h delete mode 100644 tools/esp8266/html/h/setup_html.h delete mode 100644 tools/esp8266/html/h/style_css.h delete mode 100644 tools/esp8266/html/h/visualization_html.h diff --git a/.gitignore b/.gitignore index f9432353..9af41f40 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,4 @@ tools/esp8266/.vscode/extensions.json .DS_Store .vscode tools/esp8266/platformio-device-monitor-*.log +tools/esp8266/html/h/* \ No newline at end of file diff --git a/tools/esp8266/api.cpp b/tools/esp8266/api.cpp new file mode 100644 index 00000000..59f2817e --- /dev/null +++ b/tools/esp8266/api.cpp @@ -0,0 +1,100 @@ +//----------------------------------------------------------------------------- +// 2022 Ahoy, https://www.mikrocontroller.net/topic/525778 +// Creative Commons - http://creativecommons.org/licenses/by-nc-sa/3.0/de/ +//----------------------------------------------------------------------------- + +#if defined(ESP32) && defined(F) + #undef F + #define F(sl) (sl) +#endif + +#include "api.h" +#include "AsyncJson.h" + +//----------------------------------------------------------------------------- +api::api(AsyncWebServer *srv, app *app, sysConfig_t *sysCfg, config_t *config, char version[]) { + mSrv = srv; + mApp = app; + mSysCfg = sysCfg; + mConfig = config; + mVersion = version; +} + + +//----------------------------------------------------------------------------- +void api::setup(void) { + mSrv->on("/api/system", HTTP_GET, std::bind(&api::onSystem, this, std::placeholders::_1)); + mSrv->on("/api/inverter/list", HTTP_GET, std::bind(&api::onInverterList, this, std::placeholders::_1)); + mSrv->on("/api/mqtt", HTTP_GET, std::bind(&api::onMqtt, this, std::placeholders::_1)); +} + + +//----------------------------------------------------------------------------- +void api::loop(void) { + +} + + +//----------------------------------------------------------------------------- +void api::onSystem(AsyncWebServerRequest *request) { + AsyncJsonResponse* response = new AsyncJsonResponse(); + JsonObject root = response->getRoot(); + + root[F("ssid")] = mSysCfg->stationSsid; + root[F("device_name")] = mSysCfg->deviceName; + + response->setLength(); + //response->addHeader("Access-Control-Allow-Origin", "*"); + //response->addHeader("Access-Control-Allow-Headers", "content-type"); + request->send(response); +} + + +//----------------------------------------------------------------------------- +void api::onInverterList(AsyncWebServerRequest *request) { + AsyncJsonResponse* response = new AsyncJsonResponse(); + JsonObject root = response->getRoot(); + JsonArray invArr = root.createNestedArray("inverter"); + + Inverter<> *iv; + for(uint8_t i = 0; i < MAX_NUM_INVERTERS; i ++) { + iv = mApp->mSys->getInverterByPos(i); + if(NULL != iv) { + JsonObject obj = invArr.createNestedObject(); + obj[F("id")] = i; + obj[F("name")] = String(iv->name); + obj[F("serial")] = String(iv->serial.u64, HEX); + obj[F("channels")] = iv->channels; + obj[F("version")] = String(iv->fwVersion); + + for(uint8_t j = 0; j < iv->channels; j ++) { + obj[F("ch_max_power")][j] = iv->chMaxPwr[j]; + obj[F("ch_name")][j] = iv->chName[j]; + } + + obj[F("power_limit")][F("limit")] = iv->powerLimit[0]; + obj[F("power_limit")][F("limit_option")] = iv->powerLimit[1]; + } + } + root[F("interval")] = String(mConfig->sendInterval); + root[F("retries")] = String(mConfig->maxRetransPerPyld); + + response->setLength(); + request->send(response); +} + + +//----------------------------------------------------------------------------- +void api::onMqtt(AsyncWebServerRequest *request) { + AsyncJsonResponse* response = new AsyncJsonResponse(); + JsonObject root = response->getRoot(); + + root[F("broker")] = String(mConfig->mqtt.broker); + root[F("port")] = String(mConfig->mqtt.port); + root[F("user")] = String(mConfig->mqtt.user); + root[F("pwd")] = String(mConfig->mqtt.pwd); // TODO: not that nice! + root[F("topic")] = String(mConfig->mqtt.topic); + + response->setLength(); + request->send(response); +} diff --git a/tools/esp8266/api.h b/tools/esp8266/api.h new file mode 100644 index 00000000..84df8023 --- /dev/null +++ b/tools/esp8266/api.h @@ -0,0 +1,32 @@ +#ifndef __API_H__ +#define __API_H__ + +#include "dbg.h" +#include "ESPAsyncTCP.h" +#include "ESPAsyncWebServer.h" +#include "app.h" + + +class app; + +class api { + public: + api(AsyncWebServer *srv, app *app, sysConfig_t *sysCfg, config_t *config, char version[]); + + void setup(void); + void loop(void); + + private: + void onSystem(AsyncWebServerRequest *request); + void onInverterList(AsyncWebServerRequest *request); + void onMqtt(AsyncWebServerRequest *request); + + AsyncWebServer *mSrv; + app *mApp; + + config_t *mConfig; + sysConfig_t *mSysCfg; + char *mVersion; +}; + +#endif /*__API_H__*/ diff --git a/tools/esp8266/defines.h b/tools/esp8266/defines.h index 33732ff5..210604a5 100644 --- a/tools/esp8266/defines.h +++ b/tools/esp8266/defines.h @@ -13,7 +13,7 @@ //------------------------------------- #define VERSION_MAJOR 0 #define VERSION_MINOR 5 -#define VERSION_PATCH 16 +#define VERSION_PATCH 17 //------------------------------------- diff --git a/tools/esp8266/html/convert.py b/tools/esp8266/html/convert.py index f3156189..d03e3e58 100755 --- a/tools/esp8266/html/convert.py +++ b/tools/esp8266/html/convert.py @@ -1,7 +1,8 @@ import re import os +import gzip -def convert2Header(inFile): +def convert2Header(inFile, compress): fileType = inFile.split(".")[1] define = inFile.split(".")[0].upper() define2 = inFile.split(".")[1].upper() @@ -17,25 +18,42 @@ def convert2Header(inFile): f = open(inFile, "r") data = f.read().replace('\n', '') f.close() - if fileType == "html": + if False == compress: + if fileType == "html": + data = re.sub(r"\>\s+\<", '><', data) # whitespaces between xml tags + data = re.sub(r"(\;|\}|\>|\{)\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 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 f = open(outName, "w") f.write("#ifndef __{}_{}_H__\n".format(define, define2)) f.write("#define __{}_{}_H__\n".format(define, define2)) - f.write("const char {}[] PROGMEM = \"{}\";\n".format(inFileVarName, data)) - f.write("const uint32_t {}_len = {};\n".format(inFileVarName, length)) + if compress: + zipped = gzip.compress(bytes(data, 'utf-8')) + zippedStr = "" + for i in range(len(zipped)): + zippedStr += "0x{:02x}".format(zipped[i]) #hex(zipped[i]) + if (i + 1) != len(zipped): + zippedStr += ", " + if (i + 1) % 16 == 0 and i != 0: + zippedStr += "\n" + f.write("#define {}_len {}\n".format(inFileVarName, len(zipped))) + f.write("const uint8_t {}[] PROGMEM = {{\n{}}};\n".format(inFileVarName, zippedStr)) + else: + f.write("const char {}[] PROGMEM = \"{}\";\n".format(inFileVarName, data)) + f.write("const uint32_t {}_len = {};\n".format(inFileVarName, length)) f.write("#endif /*__{}_{}_H__*/\n".format(define, define2)) f.close() -convert2Header("index.html") -convert2Header("setup.html") -convert2Header("visualization.html") -convert2Header("update.html") -convert2Header("style.css") +convert2Header("index.html", False) +convert2Header("setup.html", True) +convert2Header("visualization.html", False) +convert2Header("update.html", False) +convert2Header("style.css", False) diff --git a/tools/esp8266/html/h/favicon_ico_gz.h b/tools/esp8266/html/h/favicon_ico_gz.h deleted file mode 100644 index b978fb85..00000000 --- a/tools/esp8266/html/h/favicon_ico_gz.h +++ /dev/null @@ -1,100 +0,0 @@ -#ifndef __FAVICON_ICO_GZ_H__ -#define __FAVICON_ICO_GZ_H__ -#define favicon_ico_gz_len 1533 -const uint8_t favicon_ico_gz[] PROGMEM = {0x1f, 0x8b, 0x08, 0x08, 0xf2, 0xc5, 0xd5, 0x62, 0x04, 0x00, 0x66, 0x61, 0x76, 0x69, 0x63, 0x6f, -0x6e, 0x2e, 0x69, 0x63, 0x6f, 0x00, 0xed, 0x5c, 0x49, 0x68, 0x13, 0x51, 0x18, 0xfe, 0x62, 0xa3, -0x51, 0x28, 0xd6, 0x83, 0x82, 0xa0, 0x98, 0xb8, 0x1c, 0xbc, 0x59, 0x11, 0x5c, 0x50, 0xac, 0x88, -0x8a, 0xb8, 0xdd, 0x3c, 0x89, 0xd0, 0x93, 0x7a, 0x53, 0x51, 0x9b, 0x80, 0x4b, 0x46, 0xad, 0xfb, -0xd2, 0xb4, 0x2e, 0xb8, 0xa3, 0xc6, 0xba, 0xe1, 0x02, 0xae, 0xad, 0x0a, 0x26, 0x3d, 0xe8, 0xc5, -0x83, 0x57, 0x31, 0x2d, 0xc1, 0x8b, 0xb7, 0x92, 0x63, 0x0e, 0xa1, 0xcf, 0xff, 0xcf, 0xbc, 0xc9, -0x32, 0xa4, 0x66, 0xcf, 0x4b, 0xf3, 0xfa, 0xc3, 0xc7, 0x97, 0xcc, 0xcc, 0xcb, 0xf7, 0xbe, 0x6f, -0x26, 0x6f, 0x26, 0xf3, 0x92, 0x00, 0x0e, 0x34, 0x61, 0xda, 0x34, 0x66, 0x0f, 0xf6, 0x38, 0x81, -0xa5, 0x00, 0x3c, 0x1e, 0xf3, 0xf9, 0x53, 0x5a, 0x7e, 0x8f, 0x96, 0xad, 0x59, 0x63, 0x3e, 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, 0x1c, 0x93, 0x1c, 0x97, 0x9c, 0x90, 0x3c, 0x22, -0x59, 0x58, 0x7c, 0x46, 0xf2, 0x77, 0xc9, 0x7f, 0x25, 0x8b, 0x82, 0xd8, 0x41, 0x7f, 0x3b, 0x91, -0xec, 0x8f, 0x10, 0x21, 0x66, 0xfe, 0x67, 0x06, 0xe6, 0x16, 0x21, 0x62, 0xcc, 0x6e, 0x21, 0xe2, -0xcc, 0x6d, 0x42, 0x24, 0x98, 0xfd, 0x42, 0x8c, 0x30, 0x0b, 0x2a, 0xf6, 0xcf, 0x7c, 0x87, 0x72, -0x61, 0x4e, 0xe4, 0x67, 0x3f, 0xf3, 0x08, 0x7d, 0x28, 0x4f, 0x16, 0x1c, 0x26, 0x1b, 0x4d, 0xb4, -0x90, 0x56, 0x85, 0x5c, 0xb4, 0x11, 0x6d, 0x1a, 0x6d, 0x21, 0x55, 0x52, 0x8e, 0x31, 0xf8, 0x31, -0x2f, 0xe3, 0x75, 0xff, 0x00, 0xd3, 0x39, 0x74, 0x2c, 0x6e, 0x57, 0x00, 0x00}; -#endif /*__FAVICON_ICO_GZ_H__*/ diff --git a/tools/esp8266/html/h/index_html.h b/tools/esp8266/html/h/index_html.h deleted file mode 100644 index 34098afe..00000000 --- a/tools/esp8266/html/h/index_html.h +++ /dev/null @@ -1,5 +0,0 @@ -#ifndef __INDEX_HTML_H__ -#define __INDEX_HTML_H__ -const char index_html[] PROGMEM = "Index - {DEVICE}

AHOY - {DEVICE}

Visualization

Setup

Uptime:

Statistics:

Every {TS}seconds the values are updated

This project was started from this discussion. (Mikrocontroller.net)
New updates can be found on Github: https://github.com/grindylow/ahoy

Please report issues using the feature provided by Github

Discuss with us on Discord

Creative Commons - https://creativecommons.org/licenses/by-nc-sa/3.0/de/
Check the licenses which are published on https://github.com/grindylow/ahoyas well

© 2022

Update Firmware

AHOY :: {VERSION}

Reboot

Git SHA: {BUILD}

"; -const uint32_t index_html_len = 2317; -#endif /*__INDEX_HTML_H__*/ diff --git a/tools/esp8266/html/h/setup_html.h b/tools/esp8266/html/h/setup_html.h deleted file mode 100644 index 990ab73a..00000000 --- a/tools/esp8266/html/h/setup_html.h +++ /dev/null @@ -1,5 +0,0 @@ -#ifndef __SETUP_HTML_H__ -#define __SETUP_HTML_H__ -const char setup_html[] PROGMEM = "Setup - {#DEVICE}

Setup

ERASE SETTINGS (not WiFi)
Device Host Name
WiFi

Enter the credentials to your prefered WiFi station. After rebooting the device tries to connect with this information.

Inverter{#INVERTERS}

General

NTP Server
MQTT
System Config

Pinout (Wemos)

{#PINOUT}

Radio (NRF24L01+)

Serial Console



Home

Update Firmware

AHOY - {#VERSION}

Factory Reset

Reboot

"; -const uint32_t setup_html_len = 5019; -#endif /*__SETUP_HTML_H__*/ diff --git a/tools/esp8266/html/h/style_css.h b/tools/esp8266/html/h/style_css.h deleted file mode 100644 index dcfb045f..00000000 --- a/tools/esp8266/html/h/style_css.h +++ /dev/null @@ -1,5 +0,0 @@ -#ifndef __STYLE_CSS_H__ -#define __STYLE_CSS_H__ -const char style_css[] PROGMEM = "h1 {margin:0;padding:20pt;font-size:22pt;color:#fff;background-color:#006ec0;display:block;text-transform:uppercase;}html, body {font-family:Arial;margin:0;padding:0;}p {text-align:justify;font-size:13pt;}p.lic, p.lic a {font-size:8pt;color:#999;}.des {margin-top:20px;font-size:13pt;color:#006ec0;}.s_active, .s_collapsible:hover {background-color:#006ec0;}.s_content {display:none;overflow:hidden;}.s_collapsible {background-color:#044e86;color:white;cursor:pointer;padding:18px;width:100%;border:none;text-align:left;outline:none;font-size:15px;margin-bottom:4px;}.subdes {font-size:12pt;color:#006ec0;margin-left:7px;}.subsubdes {font-size:12pt;color:#006ec0;margin:0 0 7px 12px;}.hide {display:none;}a:link, a:visited {text-decoration:none;font-size:13pt;color:#006ec0;}a:hover, a:focus {color:#f00;}a.erase {background-color:#006ec0;color:#fff;padding:7px;display:inline-block;margin-top:30px;}#content {padding:15px 15px 60px 15px;}#footer {position:fixed;bottom:0px;height:45px;background-color:#006ec0;width:100%;border-top:5px solid #fff;}#footer p, #footer a {color:#fff;padding:0 7px 0 7px;font-size:10pt !important;}div.content {background-color:#fff;padding-bottom:65px;overflow:auto;}input, select {padding:7px;font-size:13pt;}input.text, select {width:70%;box-sizing:border-box;margin-bottom:10px;border:1px solid #ccc;}input.sh {max-width:150px !important;margin-right:10px;}input.btn {background-color:#006ec0;color:#fff;border:0px;float:right;margin:10px 0 30px;text-transform:uppercase;}input.cb {margin-bottom:20px;}label {width:20%;display:inline-block;font-size:12pt;padding-right:10px;margin:10px 0px 0px 15px;vertical-align:top;}fieldset {margin-bottom:15px;}.left {float:left;}.right {float:right;}div.ch-iv {width:100%;background-color:#32b004;display:inline-block;margin-bottom:15px;padding-bottom:20px;overflow:auto;}div.ch {width:220px;min-height:350px;background-color:#006ec0;display:inline-block;margin:0 10px 15px 10px;overflow:auto;padding-bottom:20px;}div.ch .value, div.ch .info, div.ch .head, div.ch-iv .value, div.ch-iv .info, div.ch-iv .head {color:#fff;display:block;width:100%;text-align:center;}.subgrp {float:left;width:220px;}div.ch .unit, div.ch-iv .unit {font-size:19px;margin-left:10px;}div.ch .value, div.ch-iv .value {margin-top:20px;font-size:24px;}div.ch .info, div.ch-iv .info {margin-top:3px;font-size:10px;}div.ch .head {background-color:#003c80;padding:10px 0 10px 0;}div.ch-iv .head {background-color:#1c6800;padding:10px 0 10px 0;}div.iv {max-width:960px;margin-bottom:40px;}div.ts {font-size:13px;background-color:#ddd;border-top:7px solid #999;padding:7px;}div.modpwr, div.modname {width:70%;display:inline-block;}#note {margin:50px 10px 10px 10px;padding-top:10px;width:100%;border-top:1px solid #bbb;}@media(max-width:500px) {div.ch .unit, div.ch-iv .unit {font-size:18px;}div.ch {width:170px;min-height:100px }.subgrp {width:180px;}}"; -const uint32_t style_css_len = 2899; -#endif /*__STYLE_CSS_H__*/ diff --git a/tools/esp8266/html/h/visualization_html.h b/tools/esp8266/html/h/visualization_html.h deleted file mode 100644 index 1b05b37c..00000000 --- a/tools/esp8266/html/h/visualization_html.h +++ /dev/null @@ -1,5 +0,0 @@ -#ifndef __VISUALIZATION_HTML_H__ -#define __VISUALIZATION_HTML_H__ -const char visualization_html[] PROGMEM = "Index - {DEVICE}

AHOY - {DEVICE}

Every {TS}seconds the values are updated

© 2022

Home

AHOY :: {VERSION}

"; -const uint32_t visualization_html_len = 922; -#endif /*__VISUALIZATION_HTML_H__*/ diff --git a/tools/esp8266/html/setup.html b/tools/esp8266/html/setup.html index 9d32fedb..309968d0 100644 --- a/tools/esp8266/html/setup.html +++ b/tools/esp8266/html/setup.html @@ -54,11 +54,11 @@
ERASE SETTINGS (not WiFi) -
+
Device Host Name - +
@@ -67,7 +67,7 @@ WiFi

Enter the credentials to your prefered WiFi station. After rebooting the device tries to connect with this information.

- + @@ -77,12 +77,12 @@
Inverter - {#INVERTERS}
+

General

- + - +
@@ -102,15 +102,15 @@
MQTT - + - + - + - + - +
@@ -143,11 +143,11 @@ diff --git a/tools/esp8266/web.cpp b/tools/esp8266/web.cpp index 4ac2b004..6a48d00b 100644 --- a/tools/esp8266/web.cpp +++ b/tools/esp8266/web.cpp @@ -41,6 +41,9 @@ web::web(app *main, sysConfig_t *sysCfg, config_t *config, char version[]) { mConfig = config; mVersion = version; mWeb = new AsyncWebServer(80); + //mEvts = new AsyncEventSource("/events"); + + mApi = new api(mWeb, main, sysCfg, config, version); } @@ -48,7 +51,7 @@ web::web(app *main, sysConfig_t *sysCfg, config_t *config, char version[]) { void web::setup(void) { DPRINTLN(DBG_VERBOSE, F("app::setup-begin")); mWeb->begin(); - DPRINTLN(DBG_VERBOSE, F("app::setup-on")); + DPRINTLN(DBG_VERBOSE, F("app::setup-on")); mWeb->on("/", HTTP_ANY, std::bind(&web::showIndex, this, std::placeholders::_1)); mWeb->on("/style.css", HTTP_ANY, std::bind(&web::showCss, this, std::placeholders::_1)); mWeb->on("/favicon.ico", HTTP_ANY, std::bind(&web::showFavicon, this, std::placeholders::_1)); @@ -71,15 +74,31 @@ void web::setup(void) { mWeb->on("/update", HTTP_GET, std::bind(&web::showUpdateForm, this, std::placeholders::_1)); mWeb->on("/update", HTTP_POST, std::bind(&web::showUpdate, this, std::placeholders::_1), std::bind(&web::showUpdate2, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5, std::placeholders::_6)); + + //mEvts->onConnect(std::bind(&web::onConnect, this, std::placeholders::_1)); + //mWeb->addHandler(mEvts); + + mApi->setup(); } //----------------------------------------------------------------------------- void web::loop(void) { - + mApi->loop(); } +//----------------------------------------------------------------------------- +/*void web::onConnect(AsyncEventSourceClient *client) { + DPRINTLN(DBG_INFO, "onConnect"); + + if(client->lastId()) + DPRINTLN(DBG_INFO, "Client reconnected! Last message ID that it got is: " + String(client->lastId())); + + client->send("hello!", NULL, millis(), 1000); +}*/ + + //----------------------------------------------------------------------------- void web::showIndex(AsyncWebServerRequest *request) { DPRINTLN(DBG_VERBOSE, F("showIndex")); @@ -192,8 +211,11 @@ void web::showFactoryRst(AsyncWebServerRequest *request) { void web::showSetup(AsyncWebServerRequest *request) { DPRINTLN(DBG_VERBOSE, F("app::showSetup")); - tmplProc *proc = new tmplProc(request, 11000); - proc->process(setup_html, setup_html_len, std::bind(&web::showSetupCb, this, std::placeholders::_1)); + //tmplProc *proc = new tmplProc(request, 11000); + //proc->process(setup_html, setup_html_len, std::bind(&web::showSetupCb, this, std::placeholders::_1)); + AsyncWebServerResponse *response = request->beginResponse_P(200, F("text/html"), setup_html, setup_html_len); + response->addHeader(F("Content-Encoding"), "gzip"); + request->send(response); } @@ -391,7 +413,6 @@ void web::showLiveData(AsyncWebServerRequest *request) { } } modHtml += ""; - yield(); } modHtml += F("
Last received data requested at: ") + mMain->getDateTimeStr(iv->ts) + F("
"); modHtml += F(""); @@ -563,64 +584,6 @@ String web::showSetupCb(char* key) { if(generic.length() == 0) { if(0 == strncmp(key, "SSID", 4)) return mSysCfg->stationSsid; else if(0 == strncmp(key, "PWD", 3)) return F("{PWD}"); - else if(0 == strncmp(key, "INVERTERS", 9)) { - String inv = ""; - Inverter<> *iv; - for(uint8_t i = 0; i < MAX_NUM_INVERTERS; i ++) { - iv = mMain->mSys->getInverterByPos(i); - - inv += F("

Inverter ") + String(i) + "

"; - inv += F(""); - inv += F("serial.u64, HEX); - inv += F("\"/ maxlength=\"12\">"); - - inv += F(""); - inv += F("name); - inv += F("\"/ maxlength=\"") + String(MAX_NAME_LENGTH) + "\">"; - - inv += F(""); - inv += F("powerLimit[0]); - inv += F("\"/ maxlength=\"") + String(6) + "\">"; - - inv += F(""); - inv += F(""); - - inv += F("
"); - for(uint8_t j = 0; j < 4; j++) { - inv += F("chMaxPwr[j]); - inv += F("\"/ maxlength=\"4\">"); - } - inv += F("

"); - for(uint8_t j = 0; j < 4; j++) { - inv += F("chName[j]); - inv += F("\"/ maxlength=\"") + String(MAX_NAME_LENGTH) + "\">"; - } - inv += F("
"); - } - DPRINTLN(DBG_INFO, inv); - return inv; - } else if(0 == strncmp(key, "PINOUT", 6)) { String pinout = ""; for(uint8_t i = 0; i < 3; i++) { @@ -661,7 +624,6 @@ String web::showSetupCb(char* key) { else if(0 == strncmp(key, "MQTT_USER", 9)) return String(mConfig->mqtt.user); else if(0 == strncmp(key, "MQTT_PWD", 8)) return String(mConfig->mqtt.pwd); else if(0 == strncmp(key, "MQTT_TOPIC", 10)) return String(mConfig->mqtt.topic); - //else if(0 == strncmp(key, "MQTT_INTVL", 10)) return String(mMqttInterval); } return generic; diff --git a/tools/esp8266/web.h b/tools/esp8266/web.h index 43226304..7f7da316 100644 --- a/tools/esp8266/web.h +++ b/tools/esp8266/web.h @@ -10,9 +10,11 @@ #include "ESPAsyncTCP.h" #include "ESPAsyncWebServer.h" #include "app.h" +#include "api.h" #include "tmplProc.h" class app; +class api; class web { public: @@ -22,6 +24,8 @@ class web { void setup(void); void loop(void); + void onConnect(AsyncEventSourceClient *client); + void showIndex(AsyncWebServerRequest *request); void showCss(AsyncWebServerRequest *request); void showFavicon(AsyncWebServerRequest *request); @@ -49,11 +53,13 @@ class web { String showUpdateFormCb(char* key); AsyncWebServer *mWeb; + AsyncEventSource *mEvts; config_t *mConfig; sysConfig_t *mSysCfg; char *mVersion; app *mMain; + api *mApi; }; #endif /*__WEB_H__*/