Browse Source

added wifi scan to setup

fixed issues on index.html
pull/372/head
lumapu 2 years ago
parent
commit
dbbfe25a44
  1. 20
      tools/esp8266/ahoywifi.cpp
  2. 1
      tools/esp8266/ahoywifi.h
  3. 6
      tools/esp8266/app.cpp
  4. 2
      tools/esp8266/app.h
  5. 2
      tools/esp8266/defines.h
  6. 8
      tools/esp8266/html/api.js
  7. 14
      tools/esp8266/html/index.html
  8. 27
      tools/esp8266/html/setup.html
  9. 27
      tools/esp8266/webApi.cpp
  10. 1
      tools/esp8266/webApi.h

20
tools/esp8266/ahoywifi.cpp

@ -209,6 +209,26 @@ time_t ahoywifi::getNtpTime(void) {
}
//-----------------------------------------------------------------------------
void ahoywifi::getAvailNetworks(JsonObject obj) {
JsonArray nets = obj.createNestedArray("networks");
int n = WiFi.scanComplete();
if(n == -2) {
WiFi.scanNetworks(true);
} else if(n) {
for (int i = 0; i < n; ++i) {
nets[i]["ssid"] = WiFi.SSID(i);
nets[i]["rssi"] = WiFi.RSSI(i);
nets[i]["hidden"] = WiFi.isHidden(i) ? true : false;
}
WiFi.scanDelete();
if(WiFi.scanComplete() == -2)
WiFi.scanNetworks(true);
}
}
//-----------------------------------------------------------------------------
void ahoywifi::sendNTPpacket(IPAddress& address) {
//DPRINTLN(DBG_VERBOSE, F("wifi::sendNTPpacket"));

1
tools/esp8266/ahoywifi.h

@ -30,6 +30,7 @@ class ahoywifi {
bool setupStation(uint32_t timeout);
bool getApActive(void);
time_t getNtpTime(void);
void getAvailNetworks(JsonObject obj);
private:
void sendNTPpacket(IPAddress& address);

6
tools/esp8266/app.cpp

@ -604,6 +604,12 @@ bool app::getWifiApActive(void) {
}
//-----------------------------------------------------------------------------
void app::getAvailNetworks(JsonObject obj) {
mWifi->getAvailNetworks(obj);
}
//-----------------------------------------------------------------------------
void app::sendMqttDiscoveryConfig(void) {
DPRINTLN(DBG_VERBOSE, F("app::sendMqttDiscoveryConfig"));

2
tools/esp8266/app.h

@ -68,6 +68,7 @@ class app {
void saveValues(void);
void resetPayload(Inverter<>* iv);
bool getWifiApActive(void);
void getAvailNetworks(JsonObject obj);
uint8_t getIrqPin(void) {
return mConfig.pinIrq;
@ -171,7 +172,6 @@ class app {
inline bool getSettingsValid(void) { return mSettingsValid; }
inline bool getRebootRequestState(void) { return mShowRebootRequest; }
HmSystemType *mSys;
bool mShouldReboot;
bool mFlagSendDiscoveryConfig;

2
tools/esp8266/defines.h

@ -13,7 +13,7 @@
//-------------------------------------
#define VERSION_MAJOR 0
#define VERSION_MINOR 5
#define VERSION_PATCH 21
#define VERSION_PATCH 22
//-------------------------------------

8
tools/esp8266/html/api.js

@ -68,6 +68,14 @@ function sel(name, opt, selId) {
return e;
}
function opt(val, html) {
o = document.createElement('option');
o.value = val;
o.innerHTML = html;
e.appendChild(o);
return o;
}
function div(cl) {
e = document.createElement('div');
e.classList.add(...cl);

14
tools/esp8266/html/index.html

@ -104,22 +104,26 @@
+ ("0"+hrs).substr(-2) + ":"
+ ("0"+min).substr(-2) + ":"
+ ("0"+sec).substr(-2);
var dSpan = document.getElementById("date")
var dSpan = document.getElementById("date");
if(0 != obj["ts_now"])
dSpan.innerHTML = date.toLocaleString('de-DE');
else {
dSpan.innerHTML = "";
var e = inp("set", "sync from browser", 0, ["btn"], "set", "button");
dSpan.appendChild(span("NTP timeserver unreachable. "));
dSpan.appendChild(e);
dSpan.appendChild(span("", ["span"], "apiResult"));
e.addEventListener("click", setTime);
}
document.getElementById("sunrise").innerHTML = sunrise.toLocaleString('de-DE');
document.getElementById("sunset").innerHTML = sunset.toLocaleString('de-DE');
if(!obj["ts_sun_upd"]) {
var elem = document.getElementById("sun");
elem.parentNode.removeChild(elem);
var e = document.getElementById("sun");
if(null != e)
e.parentNode.removeChild(e);
}
else {
document.getElementById("sunrise").innerHTML = sunrise.toLocaleString('de-DE');
document.getElementById("sunset").innerHTML = sunset.toLocaleString('de-DE');
}
}

27
tools/esp8266/html/setup.html

@ -36,6 +36,10 @@
<fieldset>
<legend class="des">WiFi</legend>
<p>Enter the credentials to your prefered WiFi station. After rebooting the device tries to connect with this information.</p>
<label for="networks">Avail Networks</label>
<select name="networks" id="networks" onChange="selNet()">
<option value="-1">scanning ...</option>
</select>
<label for="ssid">SSID</label>
<input type="text" name="ssid" class="text"/>
<label for="pwd">Password</label>
@ -377,12 +381,35 @@
parseRadio(root["radio"]);
parseSerial(root["serial"]);
}
getAjax('/api/setup/networks', listNetworks);
window.setInterval("getAjax('/api/setup/networks', listNetworks)", 7000);
}
function listNetworks(root) {
if(root["networks"].length > 0) {
var s = document.getElementById("networks");
var i, l = s.options.length - 1;
for(i = l; i >= 0; i--) {
s.remove(i);
}
for(i = 0; i < root["networks"].length; i++) {
s.appendChild(opt(root["networks"][i]["ssid"], root["networks"][i]["ssid"] + " (" + root["networks"][i]["rssi"] + " dBm)"));
}
}
}
function selNet() {
var s = document.getElementById("networks");
var e = document.getElementsByName("ssid")[0];
e.value = s.value;
}
hiddenInput = document.getElementById("disclaimer")
hiddenInput.value = sessionStorage.getItem("gDisclaimer");
getAjax("/api/setup", parse);
</script>
</body>
</html>

27
tools/esp8266/webApi.cpp

@ -45,16 +45,17 @@ void webApi::onApi(AsyncWebServerRequest *request) {
Inverter<> *iv = mApp->mSys->getInverterByPos(0, false);
String path = request->url().substring(5);
if(path == "system") getSystem(root);
else if(path == "statistics") getStatistics(root);
else if(path == "inverter/list") getInverterList(root);
else if(path == "index") getIndex(root);
else if(path == "setup") getSetup(root);
else if(path == "live") getLive(root);
else if(path == "record/info") getRecord(root, iv->getRecordStruct(InverterDevInform_All));
else if(path == "record/alarm") getRecord(root, iv->getRecordStruct(AlarmData));
else if(path == "record/config") getRecord(root, iv->getRecordStruct(SystemConfigPara));
else if(path == "record/live") getRecord(root, iv->getRecordStruct(RealTimeRunData_Debug));
if(path == "system") getSystem(root);
else if(path == "statistics") getStatistics(root);
else if(path == "inverter/list") getInverterList(root);
else if(path == "index") getIndex(root);
else if(path == "setup") getSetup(root);
else if(path == "setup/networks") getNetworks(root);
else if(path == "live") getLive(root);
else if(path == "record/info") getRecord(root, iv->getRecordStruct(InverterDevInform_All));
else if(path == "record/alarm") getRecord(root, iv->getRecordStruct(AlarmData));
else if(path == "record/config") getRecord(root, iv->getRecordStruct(SystemConfigPara));
else if(path == "record/live") getRecord(root, iv->getRecordStruct(RealTimeRunData_Debug));
else
getNotFound(root, F("http://") + request->host() + F("/api/"));
@ -291,6 +292,12 @@ void webApi::getSetup(JsonObject obj) {
}
//-----------------------------------------------------------------------------
void webApi::getNetworks(JsonObject obj) {
mApp->getAvailNetworks(obj);
}
//-----------------------------------------------------------------------------
void webApi::getLive(JsonObject obj) {
getSystem(obj.createNestedObject(F("system")));

1
tools/esp8266/webApi.h

@ -44,6 +44,7 @@ class webApi {
void getIndex(JsonObject obj);
void getSetup(JsonObject obj);
void getNetworks(JsonObject obj);
void getLive(JsonObject obj);
void getRecord(JsonObject obj, record_t<> *rec);

Loading…
Cancel
Save