From f47f0318875f6c0ed253c284b15753229ddc03dd Mon Sep 17 00:00:00 2001 From: lumapu Date: Fri, 31 May 2024 01:45:36 +0200 Subject: [PATCH] small improvements, not functional --- src/network/AhoyEthernet.h | 2 ++ src/web/RestApi.h | 21 +++------------------ src/web/html/setup.html | 9 +-------- src/web/html/wizard.html | 13 +++++-------- 4 files changed, 11 insertions(+), 34 deletions(-) diff --git a/src/network/AhoyEthernet.h b/src/network/AhoyEthernet.h index 24204004..8d623444 100644 --- a/src/network/AhoyEthernet.h +++ b/src/network/AhoyEthernet.h @@ -31,6 +31,8 @@ class AhoyEthernet : public AhoyWifi { mEthSpi.begin(mConfig->sys.eth.pinMiso, mConfig->sys.eth.pinMosi, mConfig->sys.eth.pinSclk, mConfig->sys.eth.pinCs, mConfig->sys.eth.pinIrq, mConfig->sys.eth.pinRst); ETH.setHostname(mConfig->sys.deviceName); + + AhoyWifi::begin(); } void OnEvent(WiFiEvent_t event) { diff --git a/src/web/RestApi.h b/src/web/RestApi.h index e7f23055..0d27c165 100644 --- a/src/web/RestApi.h +++ b/src/web/RestApi.h @@ -101,10 +101,8 @@ class RestApi { else if(path == "inverter/list") getInverterList(root); else if(path == "index") getIndex(request, root); else if(path == "setup") getSetup(request, root); - #if !defined(ETHERNET) else if(path == "setup/networks") getNetworks(root); else if(path == "setup/getip") getIp(root); - #endif /* !defined(ETHERNET) */ else if(path == "live") getLive(request,root); #if defined(ENABLE_HISTORY) else if (path == "powerHistory") getPowerHistory(request, root, HistoryStorageType::POWER); @@ -293,10 +291,8 @@ class RestApi { ep[F("generic")] = url + F("generic"); ep[F("index")] = url + F("index"); ep[F("setup")] = url + F("setup"); - #if !defined(ETHERNET) ep[F("setup/networks")] = url + F("setup/networks"); ep[F("setup/getip")] = url + F("setup/getip"); - #endif /* !defined(ETHERNET) */ ep[F("system")] = url + F("system"); ep[F("live")] = url + F("live"); #if defined(ENABLE_HISTORY) @@ -383,9 +379,7 @@ 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()); @@ -410,12 +404,10 @@ class RestApi { void getSysInfo(AsyncWebServerRequest *request, JsonObject obj) { obj[F("ap_pwd")] = mConfig->sys.apPwd; - #if !defined(ETHERNET) obj[F("ssid")] = mConfig->sys.stationSsid; 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; @@ -905,11 +897,9 @@ class RestApi { warn.add(F(REBOOT_ESP_APPLY_CHANGES)); if(0 == mApp->getTimestamp()) warn.add(F(TIME_NOT_SET)); - #if !defined(ETHERNET) - #if !defined(ESP32) - if(mApp->getWasInCh12to14()) - warn.add(F(WAS_IN_CH_12_TO_14)); - #endif + #if !defined(ESP32) + if(mApp->getWasInCh12to14()) + warn.add(F(WAS_IN_CH_12_TO_14)); #endif } @@ -933,12 +923,10 @@ class RestApi { getDisplay(obj.createNestedObject(F("display"))); } - #if !defined(ETHERNET) void getNetworks(JsonObject obj) { obj[F("success")] = mApp->getAvailNetworks(obj); obj[F("ip")] = mApp->getIp(); } - #endif /* !defined(ETHERNET) */ void getIp(JsonObject obj) { obj[F("ip")] = mApp->getIp(); @@ -1081,14 +1069,12 @@ class RestApi { mTimezoneOffset = jsonIn[F("val")]; else if(F("discovery_cfg") == jsonIn[F("cmd")]) mApp->setMqttDiscoveryFlag(); // for homeassistant - #if !defined(ETHERNET) else if(F("save_wifi") == jsonIn[F("cmd")]) { snprintf(mConfig->sys.stationSsid, SSID_LEN, "%s", jsonIn[F("ssid")].as()); snprintf(mConfig->sys.stationPwd, PWD_LEN, "%s", jsonIn[F("pwd")].as()); mApp->saveSettings(false); // without reboot mApp->setupStation(); } - #else else if(F("save_eth") == jsonIn[F("cmd")]) { mConfig->sys.eth.enabled = jsonIn[F("en")].as(); mConfig->sys.eth.pinCs = jsonIn[F("cs")].as(); @@ -1099,7 +1085,6 @@ class RestApi { mConfig->sys.eth.pinRst = jsonIn[F("reset")].as(); mApp->saveSettings(true); } - #endif /* !defined(ETHERNET */ else if(F("save_iv") == jsonIn[F("cmd")]) { Inverter<> *iv = mSys->getInverterByPos(jsonIn[F("id")], false); iv->config->enabled = jsonIn[F("en")]; diff --git a/src/web/html/setup.html b/src/web/html/setup.html index 26b7100c..13f18061 100644 --- a/src/web/html/setup.html +++ b/src/web/html/setup.html @@ -56,8 +56,6 @@
{#AP_PWD}
- -
SSID
@@ -73,7 +71,6 @@
{#PASSWORD}
-
{#STATIC_IP} @@ -685,14 +682,10 @@ } function parseSys(obj) { - /*IF_ETHERNET*/ - for(var i of [["device", "device_name"], ["ap_pwd", "ap_pwd"]]) - document.getElementsByName(i[0])[0].value = obj[i[1]]; - /*ELSE*/ for(var i of [["device", "device_name"], ["ssid", "ssid"], ["ap_pwd", "ap_pwd"]]) document.getElementsByName(i[0])[0].value = obj[i[1]]; document.getElementsByName("hidd")[0].checked = obj["hidd"]; - /*ENDIF_ETHERNET*/ + document.getElementsByName("darkMode")[0].checked = obj["dark_mode"]; document.getElementsByName("schedReboot")[0].checked = obj["sched_reboot"]; e = document.getElementsByName("adminpwd")[0]; diff --git a/src/web/html/wizard.html b/src/web/html/wizard.html index 98333c12..199f66db 100644 --- a/src/web/html/wizard.html +++ b/src/web/html/wizard.html @@ -210,8 +210,8 @@ ml("div", {class: "row mt-5"}, ml("div", {class: "col a-c"}, ml("a", {onclick: () => {redirect()}}, "{#STOP_WIZARD}"))) ]) } - /*ELSE*/ - function step1() { + /*ENDIF_ETHERNET*/ + function step1Wifi() { return ml("div", {}, [ ml("div", {class: "row my-5"}, ml("div", {class: "col"}, ml("span", {class: "fs-1"}, "{#WELCOME}"))), ml("div", {class: "row"}, ml("div", {class: "col"}, ml("span", {class: "fs-5"}, "{#NETWORK_SETUP}"))), @@ -222,7 +222,6 @@ ml("div", {class: "row mt-5"}, ml("div", {class: "col a-c"}, ml("a", {onclick: () => {redirect()}}, "{#STOP_WIZARD}"))) ]) } - /*ENDIF_ETHERNET*/ function checkWifi() { c.replaceChildren( @@ -258,19 +257,18 @@ } getAjax("/api/setup", ((o) => {}), "POST", JSON.stringify(o)); } - /*ELSE*/ + /*ENDIF_ETHERNET*/ function saveWifi() { var ssid = document.getElementById("net").value; if(-1 == ssid) ssid = document.getElementById("man").value; getAjax("/api/setup", ((o) => {if(!o.error) checkWifi()}), "POST", JSON.stringify({cmd: "save_wifi", ssid: ssid, pwd: document.getElementById("pwd").value})); } - /*ENDIF_ETHERNET*/ function init() { /*IF_ETHERNET*/ getAjax("/api/setup", ((o) => c.append(step1(o.eth)))); - /*ELSE*/ + /*ENDIF_ETHERNET*/ function nets(obj) { clearInterval(v) v = setInterval(() => {getAjax('/api/setup/networks', nets)}, 4000) @@ -293,9 +291,8 @@ redirIp = "http://" + obj.ip + "/index" } - c.append(step1()) + c.append(step1Wifi()) getAjax('/api/setup/networks', nets) - /*ENDIF_ETHERNET*/ }