Browse Source

small improvements, not functional

main
lumapu 8 months ago
parent
commit
f47f031887
  1. 2
      src/network/AhoyEthernet.h
  2. 21
      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);
ETH.setHostname(mConfig->sys.deviceName);
AhoyWifi::begin();
}
void OnEvent(WiFiEvent_t event) {

21
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<const char*>());
snprintf(mConfig->sys.stationPwd, PWD_LEN, "%s", jsonIn[F("pwd")].as<const char*>());
mApp->saveSettings(false); // without reboot
mApp->setupStation();
}
#else
else if(F("save_eth") == jsonIn[F("cmd")]) {
mConfig->sys.eth.enabled = jsonIn[F("en")].as<bool>();
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>();
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")];

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-9"><input type="text" name="ap_pwd" minlength="8" /></div>
</div>
<!--IF_ETHERNET-->
<!--ELSE-->
<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-9">
@ -73,7 +71,6 @@
<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>
<!--ENDIF_ETHERNET-->
</fieldset>
<fieldset class="mb-4">
<legend class="des">{#STATIC_IP}</legend>
@ -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];

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}")))
])
}
/*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*/
}
</script>

Loading…
Cancel
Save