Browse Source

small improvements, not functional

main
lumapu 8 months ago
parent
commit
f47f031887
  1. 2
      src/network/AhoyEthernet.h
  2. 15
      src/web/RestApi.h
  3. 9
      src/web/html/setup.html
  4. 13
      src/web/html/wizard.html

2
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); 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); ETH.setHostname(mConfig->sys.deviceName);
AhoyWifi::begin();
} }
void OnEvent(WiFiEvent_t event) { void OnEvent(WiFiEvent_t event) {

15
src/web/RestApi.h

@ -101,10 +101,8 @@ class RestApi {
else if(path == "inverter/list") getInverterList(root); else if(path == "inverter/list") getInverterList(root);
else if(path == "index") getIndex(request, root); else if(path == "index") getIndex(request, root);
else if(path == "setup") getSetup(request, root); else if(path == "setup") getSetup(request, root);
#if !defined(ETHERNET)
else if(path == "setup/networks") getNetworks(root); else if(path == "setup/networks") getNetworks(root);
else if(path == "setup/getip") getIp(root); else if(path == "setup/getip") getIp(root);
#endif /* !defined(ETHERNET) */
else if(path == "live") getLive(request,root); else if(path == "live") getLive(request,root);
#if defined(ENABLE_HISTORY) #if defined(ENABLE_HISTORY)
else if (path == "powerHistory") getPowerHistory(request, root, HistoryStorageType::POWER); else if (path == "powerHistory") getPowerHistory(request, root, HistoryStorageType::POWER);
@ -293,10 +291,8 @@ class RestApi {
ep[F("generic")] = url + F("generic"); ep[F("generic")] = url + F("generic");
ep[F("index")] = url + F("index"); ep[F("index")] = url + F("index");
ep[F("setup")] = url + F("setup"); ep[F("setup")] = url + F("setup");
#if !defined(ETHERNET)
ep[F("setup/networks")] = url + F("setup/networks"); ep[F("setup/networks")] = url + F("setup/networks");
ep[F("setup/getip")] = url + F("setup/getip"); ep[F("setup/getip")] = url + F("setup/getip");
#endif /* !defined(ETHERNET) */
ep[F("system")] = url + F("system"); ep[F("system")] = url + F("system");
ep[F("live")] = url + F("live"); ep[F("live")] = url + F("live");
#if defined(ENABLE_HISTORY) #if defined(ENABLE_HISTORY)
@ -383,9 +379,7 @@ class RestApi {
void getGeneric(AsyncWebServerRequest *request, JsonObject obj) { void getGeneric(AsyncWebServerRequest *request, JsonObject obj) {
mApp->resetLockTimeout(); mApp->resetLockTimeout();
#if !defined(ETHERNET)
obj[F("wifi_rssi")] = (WiFi.status() != WL_CONNECTED) ? 0 : WiFi.RSSI(); obj[F("wifi_rssi")] = (WiFi.status() != WL_CONNECTED) ? 0 : WiFi.RSSI();
#endif
obj[F("ts_uptime")] = mApp->getUptime(); obj[F("ts_uptime")] = mApp->getUptime();
obj[F("ts_now")] = mApp->getTimestamp(); obj[F("ts_now")] = mApp->getTimestamp();
obj[F("version")] = String(mApp->getVersion()); obj[F("version")] = String(mApp->getVersion());
@ -410,12 +404,10 @@ class RestApi {
void getSysInfo(AsyncWebServerRequest *request, JsonObject obj) { void getSysInfo(AsyncWebServerRequest *request, JsonObject obj) {
obj[F("ap_pwd")] = mConfig->sys.apPwd; obj[F("ap_pwd")] = mConfig->sys.apPwd;
#if !defined(ETHERNET)
obj[F("ssid")] = mConfig->sys.stationSsid; obj[F("ssid")] = mConfig->sys.stationSsid;
obj[F("hidd")] = mConfig->sys.isHidden; obj[F("hidd")] = mConfig->sys.isHidden;
obj[F("mac")] = WiFi.macAddress(); obj[F("mac")] = WiFi.macAddress();
obj[F("wifi_channel")] = WiFi.channel(); obj[F("wifi_channel")] = WiFi.channel();
#endif /* !defined(ETHERNET) */
obj[F("device_name")] = mConfig->sys.deviceName; obj[F("device_name")] = mConfig->sys.deviceName;
obj[F("dark_mode")] = (bool)mConfig->sys.darkMode; obj[F("dark_mode")] = (bool)mConfig->sys.darkMode;
obj[F("sched_reboot")] = (bool)mConfig->sys.schedReboot; obj[F("sched_reboot")] = (bool)mConfig->sys.schedReboot;
@ -905,12 +897,10 @@ class RestApi {
warn.add(F(REBOOT_ESP_APPLY_CHANGES)); warn.add(F(REBOOT_ESP_APPLY_CHANGES));
if(0 == mApp->getTimestamp()) if(0 == mApp->getTimestamp())
warn.add(F(TIME_NOT_SET)); warn.add(F(TIME_NOT_SET));
#if !defined(ETHERNET)
#if !defined(ESP32) #if !defined(ESP32)
if(mApp->getWasInCh12to14()) if(mApp->getWasInCh12to14())
warn.add(F(WAS_IN_CH_12_TO_14)); warn.add(F(WAS_IN_CH_12_TO_14));
#endif #endif
#endif
} }
void getSetup(AsyncWebServerRequest *request, JsonObject obj) { void getSetup(AsyncWebServerRequest *request, JsonObject obj) {
@ -933,12 +923,10 @@ class RestApi {
getDisplay(obj.createNestedObject(F("display"))); getDisplay(obj.createNestedObject(F("display")));
} }
#if !defined(ETHERNET)
void getNetworks(JsonObject obj) { void getNetworks(JsonObject obj) {
obj[F("success")] = mApp->getAvailNetworks(obj); obj[F("success")] = mApp->getAvailNetworks(obj);
obj[F("ip")] = mApp->getIp(); obj[F("ip")] = mApp->getIp();
} }
#endif /* !defined(ETHERNET) */
void getIp(JsonObject obj) { void getIp(JsonObject obj) {
obj[F("ip")] = mApp->getIp(); obj[F("ip")] = mApp->getIp();
@ -1081,14 +1069,12 @@ class RestApi {
mTimezoneOffset = jsonIn[F("val")]; mTimezoneOffset = jsonIn[F("val")];
else if(F("discovery_cfg") == jsonIn[F("cmd")]) else if(F("discovery_cfg") == jsonIn[F("cmd")])
mApp->setMqttDiscoveryFlag(); // for homeassistant mApp->setMqttDiscoveryFlag(); // for homeassistant
#if !defined(ETHERNET)
else if(F("save_wifi") == jsonIn[F("cmd")]) { else if(F("save_wifi") == jsonIn[F("cmd")]) {
snprintf(mConfig->sys.stationSsid, SSID_LEN, "%s", jsonIn[F("ssid")].as<const char*>()); snprintf(mConfig->sys.stationSsid, SSID_LEN, "%s", jsonIn[F("ssid")].as<const char*>());
snprintf(mConfig->sys.stationPwd, PWD_LEN, "%s", jsonIn[F("pwd")].as<const char*>()); snprintf(mConfig->sys.stationPwd, PWD_LEN, "%s", jsonIn[F("pwd")].as<const char*>());
mApp->saveSettings(false); // without reboot mApp->saveSettings(false); // without reboot
mApp->setupStation(); mApp->setupStation();
} }
#else
else if(F("save_eth") == jsonIn[F("cmd")]) { else if(F("save_eth") == jsonIn[F("cmd")]) {
mConfig->sys.eth.enabled = jsonIn[F("en")].as<bool>(); mConfig->sys.eth.enabled = jsonIn[F("en")].as<bool>();
mConfig->sys.eth.pinCs = jsonIn[F("cs")].as<uint8_t>(); mConfig->sys.eth.pinCs = jsonIn[F("cs")].as<uint8_t>();
@ -1099,7 +1085,6 @@ class RestApi {
mConfig->sys.eth.pinRst = jsonIn[F("reset")].as<uint8_t>(); mConfig->sys.eth.pinRst = jsonIn[F("reset")].as<uint8_t>();
mApp->saveSettings(true); mApp->saveSettings(true);
} }
#endif /* !defined(ETHERNET */
else if(F("save_iv") == jsonIn[F("cmd")]) { else if(F("save_iv") == jsonIn[F("cmd")]) {
Inverter<> *iv = mSys->getInverterByPos(jsonIn[F("id")], false); Inverter<> *iv = mSys->getInverterByPos(jsonIn[F("id")], false);
iv->config->enabled = jsonIn[F("en")]; iv->config->enabled = jsonIn[F("en")];

9
src/web/html/setup.html

@ -56,8 +56,6 @@
<div class="col-12 col-sm-3 my-2">{#AP_PWD}</div> <div class="col-12 col-sm-3 my-2">{#AP_PWD}</div>
<div class="col-12 col-sm-9"><input type="text" name="ap_pwd" minlength="8" /></div> <div class="col-12 col-sm-9"><input type="text" name="ap_pwd" minlength="8" /></div>
</div> </div>
<!--IF_ETHERNET-->
<!--ELSE-->
<div class="row mb-2 mb-sm-3"> <div class="row mb-2 mb-sm-3">
<div class="col-12 col-sm-3 my-2">SSID</div> <div class="col-12 col-sm-3 my-2">SSID</div>
<div class="col-12 col-sm-9"> <div class="col-12 col-sm-9">
@ -73,7 +71,6 @@
<div class="col-12 col-sm-3 my-2">{#PASSWORD}</div> <div class="col-12 col-sm-3 my-2">{#PASSWORD}</div>
<div class="col-12 col-sm-9"><input type="password" name="pwd" value="{PWD}"/></div> <div class="col-12 col-sm-9"><input type="password" name="pwd" value="{PWD}"/></div>
</div> </div>
<!--ENDIF_ETHERNET-->
</fieldset> </fieldset>
<fieldset class="mb-4"> <fieldset class="mb-4">
<legend class="des">{#STATIC_IP}</legend> <legend class="des">{#STATIC_IP}</legend>
@ -685,14 +682,10 @@
} }
function parseSys(obj) { 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"]]) for(var i of [["device", "device_name"], ["ssid", "ssid"], ["ap_pwd", "ap_pwd"]])
document.getElementsByName(i[0])[0].value = obj[i[1]]; document.getElementsByName(i[0])[0].value = obj[i[1]];
document.getElementsByName("hidd")[0].checked = obj["hidd"]; document.getElementsByName("hidd")[0].checked = obj["hidd"];
/*ENDIF_ETHERNET*/
document.getElementsByName("darkMode")[0].checked = obj["dark_mode"]; document.getElementsByName("darkMode")[0].checked = obj["dark_mode"];
document.getElementsByName("schedReboot")[0].checked = obj["sched_reboot"]; document.getElementsByName("schedReboot")[0].checked = obj["sched_reboot"];
e = document.getElementsByName("adminpwd")[0]; e = document.getElementsByName("adminpwd")[0];

13
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}"))) ml("div", {class: "row mt-5"}, ml("div", {class: "col a-c"}, ml("a", {onclick: () => {redirect()}}, "{#STOP_WIZARD}")))
]) ])
} }
/*ELSE*/ /*ENDIF_ETHERNET*/
function step1() { function step1Wifi() {
return ml("div", {}, [ return ml("div", {}, [
ml("div", {class: "row my-5"}, ml("div", {class: "col"}, ml("span", {class: "fs-1"}, "{#WELCOME}"))), 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}"))), 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}"))) ml("div", {class: "row mt-5"}, ml("div", {class: "col a-c"}, ml("a", {onclick: () => {redirect()}}, "{#STOP_WIZARD}")))
]) ])
} }
/*ENDIF_ETHERNET*/
function checkWifi() { function checkWifi() {
c.replaceChildren( c.replaceChildren(
@ -258,19 +257,18 @@
} }
getAjax("/api/setup", ((o) => {}), "POST", JSON.stringify(o)); getAjax("/api/setup", ((o) => {}), "POST", JSON.stringify(o));
} }
/*ELSE*/ /*ENDIF_ETHERNET*/
function saveWifi() { function saveWifi() {
var ssid = document.getElementById("net").value; var ssid = document.getElementById("net").value;
if(-1 == ssid) if(-1 == ssid)
ssid = document.getElementById("man").value; 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})); 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() { function init() {
/*IF_ETHERNET*/ /*IF_ETHERNET*/
getAjax("/api/setup", ((o) => c.append(step1(o.eth)))); getAjax("/api/setup", ((o) => c.append(step1(o.eth))));
/*ELSE*/ /*ENDIF_ETHERNET*/
function nets(obj) { function nets(obj) {
clearInterval(v) clearInterval(v)
v = setInterval(() => {getAjax('/api/setup/networks', nets)}, 4000) v = setInterval(() => {getAjax('/api/setup/networks', nets)}, 4000)
@ -293,9 +291,8 @@
redirIp = "http://" + obj.ip + "/index" redirIp = "http://" + obj.ip + "/index"
} }
c.append(step1()) c.append(step1Wifi())
getAjax('/api/setup/networks', nets) getAjax('/api/setup/networks', nets)
/*ENDIF_ETHERNET*/
} }
</script> </script>

Loading…
Cancel
Save