diff --git a/tools/esp8266/api.cpp b/tools/esp8266/api.cpp index 59f2817e..8270797f 100644 --- a/tools/esp8266/api.cpp +++ b/tools/esp8266/api.cpp @@ -26,6 +26,10 @@ 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)); + mSrv->on("/api/ntp", HTTP_GET, std::bind(&api::onNtp, this, std::placeholders::_1)); + mSrv->on("/api/pinout", HTTP_GET, std::bind(&api::onPinout, this, std::placeholders::_1)); + mSrv->on("/api/radio", HTTP_GET, std::bind(&api::onRadio, this, std::placeholders::_1)); + mSrv->on("/api/serial", HTTP_GET, std::bind(&api::onSerial, this, std::placeholders::_1)); } @@ -72,12 +76,13 @@ void api::onInverterList(AsyncWebServerRequest *request) { 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]; + obj[F("power_limit")] = iv->powerLimit[0]; + obj[F("power_limit_option")] = iv->powerLimit[1]; } } root[F("interval")] = String(mConfig->sendInterval); root[F("retries")] = String(mConfig->maxRetransPerPyld); + root[F("max_num_inverters")] = MAX_NUM_INVERTERS; response->setLength(); request->send(response); @@ -92,9 +97,64 @@ void api::onMqtt(AsyncWebServerRequest *request) { 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("pwd")] = (strlen(mConfig->mqtt.pwd) > 0) ? F("{PWD}") : String(""); root[F("topic")] = String(mConfig->mqtt.topic); response->setLength(); request->send(response); } + + +//----------------------------------------------------------------------------- +void api::onNtp(AsyncWebServerRequest *request) { + AsyncJsonResponse* response = new AsyncJsonResponse(); + JsonObject root = response->getRoot(); + + root[F("addr")] = String(mConfig->ntpAddr); + root[F("port")] = String(mConfig->ntpPort); + + response->setLength(); + request->send(response); +} + + +//----------------------------------------------------------------------------- +void api::onPinout(AsyncWebServerRequest *request) { + AsyncJsonResponse* response = new AsyncJsonResponse(); + JsonObject root = response->getRoot(); + + root[F("cs")] = mConfig->pinCs; + root[F("ce")] = mConfig->pinCe; + root[F("irq")] = mConfig->pinIrq; + + response->setLength(); + request->send(response); +} + + +//----------------------------------------------------------------------------- +void api::onRadio(AsyncWebServerRequest *request) { + AsyncJsonResponse* response = new AsyncJsonResponse(); + JsonObject root = response->getRoot(); + + root[F("power_level")] = mConfig->amplifierPower; + + response->setLength(); + request->send(response); +} + + + +//----------------------------------------------------------------------------- +void api::onSerial(AsyncWebServerRequest *request) { + AsyncJsonResponse* response = new AsyncJsonResponse(); + JsonObject root = response->getRoot(); + + // next line cause a chrash but why? + //root[F("interval")] = mConfig->serialInterval; + root[F("show_live_data")] = mConfig->serialShowIv; + root[F("debug")] = mConfig->serialDebug; + + response->setLength(); + request->send(response); +} diff --git a/tools/esp8266/api.h b/tools/esp8266/api.h index 84df8023..03e3a164 100644 --- a/tools/esp8266/api.h +++ b/tools/esp8266/api.h @@ -20,6 +20,10 @@ class api { void onSystem(AsyncWebServerRequest *request); void onInverterList(AsyncWebServerRequest *request); void onMqtt(AsyncWebServerRequest *request); + void onNtp(AsyncWebServerRequest *request); + void onPinout(AsyncWebServerRequest *request); + void onRadio(AsyncWebServerRequest *request); + void onSerial(AsyncWebServerRequest *request); AsyncWebServer *mSrv; app *mApp; diff --git a/tools/esp8266/app.h b/tools/esp8266/app.h index 9e66fcd3..a3a33d20 100644 --- a/tools/esp8266/app.h +++ b/tools/esp8266/app.h @@ -36,13 +36,6 @@ typedef HmRadio RadioType; typedef Inverter InverterType; typedef HmSystem HmSystemType; -const char* const wemosPins[] = {"D3 (GPIO0)", "TX (GPIO1)", "D4 (GPIO2)", "RX (GPIO3)", - "D2 (GPIO4)", "D1 (GPIO5)", "GPIO6", "GPIO7", "GPIO8", - "GPIO9", "GPIO10", "GPIO11", "D6 (GPIO12)", "D7 (GPIO13)", - "D5 (GPIO14)", "D8 (GPIO15)", "D0 (GPIO16 - no IRQ!)"}; -const char* const pinNames[] = {"CS", "CE", "IRQ"}; -const char* const pinArgNames[] = {"pinCs", "pinCe", "pinIrq"}; - typedef struct { uint8_t invId; diff --git a/tools/esp8266/html/convert.py b/tools/esp8266/html/convert.py index d03e3e58..953dafca 100755 --- a/tools/esp8266/html/convert.py +++ b/tools/esp8266/html/convert.py @@ -21,7 +21,7 @@ def convert2Header(inFile, compress): 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 + 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: diff --git a/tools/esp8266/html/setup.html b/tools/esp8266/html/setup.html index 309968d0..bf1e3b1c 100644 --- a/tools/esp8266/html/setup.html +++ b/tools/esp8266/html/setup.html @@ -1,7 +1,7 @@ - Setup - {#DEVICE} + Setup diff --git a/tools/esp8266/html/style.css b/tools/esp8266/html/style.css index 8ce9c570..eea5db06 100644 --- a/tools/esp8266/html/style.css +++ b/tools/esp8266/html/style.css @@ -231,7 +231,7 @@ div.ts { padding: 7px; } -div.modpwr, div.modname { +div.ModPwr, div.ModName { width:70%; display: inline-block; } diff --git a/tools/esp8266/web.cpp b/tools/esp8266/web.cpp index 6a48d00b..b4510e9f 100644 --- a/tools/esp8266/web.cpp +++ b/tools/esp8266/web.cpp @@ -17,22 +17,7 @@ #include "html/h/visualization_html.h" #include "html/h/update_html.h" - -const uint16_t pwrLimitOptionValues[] { - NoPowerLimit, - AbsolutNonPersistent, - AbsolutPersistent, - RelativNonPersistent, - RelativPersistent -}; - -const char* const pwrLimitOptions[] { - "no power limit", - "absolute in Watt non persistent", - "absolute in Watt persistent", - "relativ in percent non persistent", - "relativ in percent persistent" -}; +const char* const pinArgNames[] = {"pinCs", "pinCe", "pinIrq"}; //----------------------------------------------------------------------------- web::web(app *main, sysConfig_t *sysCfg, config_t *config, char version[]) { @@ -211,8 +196,6 @@ 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)); AsyncWebServerResponse *response = request->beginResponse_P(200, F("text/html"), setup_html, setup_html_len); response->addHeader(F("Content-Encoding"), "gzip"); request->send(response); @@ -306,7 +289,8 @@ void web::showSave(AsyncWebServerRequest *request) { if(request->arg("mqttAddr") != "") { request->arg("mqttAddr").toCharArray(mConfig->mqtt.broker, MQTT_ADDR_LEN); request->arg("mqttUser").toCharArray(mConfig->mqtt.user, MQTT_USER_LEN); - request->arg("mqttPwd").toCharArray(mConfig->mqtt.pwd, MQTT_PWD_LEN); + if(request->arg("mqttPwd") != "{PWD}") + request->arg("mqttPwd").toCharArray(mConfig->mqtt.pwd, MQTT_PWD_LEN); request->arg("mqttTopic").toCharArray(mConfig->mqtt.topic, MQTT_TOPIC_LEN); mConfig->mqtt.port = request->arg("mqttPort").toInt(); } @@ -575,61 +559,6 @@ String web::replaceHtmlGenericKeys(char *key) { } -//----------------------------------------------------------------------------- -String web::showSetupCb(char* key) { - // PWD will be left at the default value (for protection) - // -> the PWD will only be changed if it does not match the placeholder "{PWD}" - - String generic = replaceHtmlGenericKeys(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, "PINOUT", 6)) { - String pinout = ""; - for(uint8_t i = 0; i < 3; i++) { - pinout += F(""); - pinout += F(""); - } - return pinout; - } - else if(0 == strncmp(key, "RF24", 4)) { - String rf24 = ""; - for(uint8_t i = 0; i <= 3; i++) { - rf24 += F(""); - } - return rf24; - } - else if(0 == strncmp(key, "INV_INTVL", 9)) return String(mConfig->sendInterval); - else if(0 == strncmp(key, "INV_RETRIES", 11)) return String(mConfig->maxRetransPerPyld); - else if(0 == strncmp(key, "SER_INTVL", 9)) return String(mConfig->serialInterval); - else if(0 == strncmp(key, "SER_VAL_CB", 10)) return (mConfig->serialShowIv) ? "checked" : ""; - else if(0 == strncmp(key, "SER_DBG_CB", 10)) return (mConfig->serialDebug) ? "checked" : ""; - else if(0 == strncmp(key, "NTP_ADDR", 8)) return String(mConfig->ntpAddr); - else if(0 == strncmp(key, "NTP_PORT", 8)) return String(mConfig->ntpPort); - else if(0 == strncmp(key, "MQTT_ADDR", 9)) return String(mConfig->mqtt.broker); - else if(0 == strncmp(key, "MQTT_PORT", 9)) return String(mConfig->mqtt.port); - 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); - } - - return generic; -} - - //----------------------------------------------------------------------------- String web::showUpdateFormCb(char *key) { String generic = replaceHtmlGenericKeys(key); diff --git a/tools/esp8266/web.h b/tools/esp8266/web.h index 7f7da316..0d8fe760 100644 --- a/tools/esp8266/web.h +++ b/tools/esp8266/web.h @@ -49,7 +49,6 @@ class web { private: String replaceHtmlGenericKeys(char *key); - String showSetupCb(char* key); String showUpdateFormCb(char* key); AsyncWebServer *mWeb;