mirror of
https://github.com/lumapu/ahoy.git
synced 2025-04-30 10:46:24 +02:00
added wifi scan to setup
fixed issues on index.html
This commit is contained in:
parent
8b8deded9a
commit
dbbfe25a44
10 changed files with 91 additions and 17 deletions
|
@ -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) {
|
void ahoywifi::sendNTPpacket(IPAddress& address) {
|
||||||
//DPRINTLN(DBG_VERBOSE, F("wifi::sendNTPpacket"));
|
//DPRINTLN(DBG_VERBOSE, F("wifi::sendNTPpacket"));
|
||||||
|
|
|
@ -30,6 +30,7 @@ class ahoywifi {
|
||||||
bool setupStation(uint32_t timeout);
|
bool setupStation(uint32_t timeout);
|
||||||
bool getApActive(void);
|
bool getApActive(void);
|
||||||
time_t getNtpTime(void);
|
time_t getNtpTime(void);
|
||||||
|
void getAvailNetworks(JsonObject obj);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void sendNTPpacket(IPAddress& address);
|
void sendNTPpacket(IPAddress& address);
|
||||||
|
|
|
@ -604,6 +604,12 @@ bool app::getWifiApActive(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
void app::getAvailNetworks(JsonObject obj) {
|
||||||
|
mWifi->getAvailNetworks(obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
void app::sendMqttDiscoveryConfig(void) {
|
void app::sendMqttDiscoveryConfig(void) {
|
||||||
DPRINTLN(DBG_VERBOSE, F("app::sendMqttDiscoveryConfig"));
|
DPRINTLN(DBG_VERBOSE, F("app::sendMqttDiscoveryConfig"));
|
||||||
|
|
|
@ -68,6 +68,7 @@ class app {
|
||||||
void saveValues(void);
|
void saveValues(void);
|
||||||
void resetPayload(Inverter<>* iv);
|
void resetPayload(Inverter<>* iv);
|
||||||
bool getWifiApActive(void);
|
bool getWifiApActive(void);
|
||||||
|
void getAvailNetworks(JsonObject obj);
|
||||||
|
|
||||||
uint8_t getIrqPin(void) {
|
uint8_t getIrqPin(void) {
|
||||||
return mConfig.pinIrq;
|
return mConfig.pinIrq;
|
||||||
|
@ -171,7 +172,6 @@ class app {
|
||||||
inline bool getSettingsValid(void) { return mSettingsValid; }
|
inline bool getSettingsValid(void) { return mSettingsValid; }
|
||||||
inline bool getRebootRequestState(void) { return mShowRebootRequest; }
|
inline bool getRebootRequestState(void) { return mShowRebootRequest; }
|
||||||
|
|
||||||
|
|
||||||
HmSystemType *mSys;
|
HmSystemType *mSys;
|
||||||
bool mShouldReboot;
|
bool mShouldReboot;
|
||||||
bool mFlagSendDiscoveryConfig;
|
bool mFlagSendDiscoveryConfig;
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
//-------------------------------------
|
//-------------------------------------
|
||||||
#define VERSION_MAJOR 0
|
#define VERSION_MAJOR 0
|
||||||
#define VERSION_MINOR 5
|
#define VERSION_MINOR 5
|
||||||
#define VERSION_PATCH 21
|
#define VERSION_PATCH 22
|
||||||
|
|
||||||
|
|
||||||
//-------------------------------------
|
//-------------------------------------
|
||||||
|
|
|
@ -68,6 +68,14 @@ function sel(name, opt, selId) {
|
||||||
return e;
|
return e;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function opt(val, html) {
|
||||||
|
o = document.createElement('option');
|
||||||
|
o.value = val;
|
||||||
|
o.innerHTML = html;
|
||||||
|
e.appendChild(o);
|
||||||
|
return o;
|
||||||
|
}
|
||||||
|
|
||||||
function div(cl) {
|
function div(cl) {
|
||||||
e = document.createElement('div');
|
e = document.createElement('div');
|
||||||
e.classList.add(...cl);
|
e.classList.add(...cl);
|
||||||
|
|
|
@ -104,22 +104,26 @@
|
||||||
+ ("0"+hrs).substr(-2) + ":"
|
+ ("0"+hrs).substr(-2) + ":"
|
||||||
+ ("0"+min).substr(-2) + ":"
|
+ ("0"+min).substr(-2) + ":"
|
||||||
+ ("0"+sec).substr(-2);
|
+ ("0"+sec).substr(-2);
|
||||||
var dSpan = document.getElementById("date")
|
var dSpan = document.getElementById("date");
|
||||||
if(0 != obj["ts_now"])
|
if(0 != obj["ts_now"])
|
||||||
dSpan.innerHTML = date.toLocaleString('de-DE');
|
dSpan.innerHTML = date.toLocaleString('de-DE');
|
||||||
else {
|
else {
|
||||||
|
dSpan.innerHTML = "";
|
||||||
var e = inp("set", "sync from browser", 0, ["btn"], "set", "button");
|
var e = inp("set", "sync from browser", 0, ["btn"], "set", "button");
|
||||||
dSpan.appendChild(span("NTP timeserver unreachable. "));
|
dSpan.appendChild(span("NTP timeserver unreachable. "));
|
||||||
dSpan.appendChild(e);
|
dSpan.appendChild(e);
|
||||||
dSpan.appendChild(span("", ["span"], "apiResult"));
|
dSpan.appendChild(span("", ["span"], "apiResult"));
|
||||||
e.addEventListener("click", setTime);
|
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"]) {
|
if(!obj["ts_sun_upd"]) {
|
||||||
var elem = document.getElementById("sun");
|
var e = document.getElementById("sun");
|
||||||
elem.parentNode.removeChild(elem);
|
if(null != e)
|
||||||
|
e.parentNode.removeChild(e);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
document.getElementById("sunrise").innerHTML = sunrise.toLocaleString('de-DE');
|
||||||
|
document.getElementById("sunset").innerHTML = sunset.toLocaleString('de-DE');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,6 +36,10 @@
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<legend class="des">WiFi</legend>
|
<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>
|
<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>
|
<label for="ssid">SSID</label>
|
||||||
<input type="text" name="ssid" class="text"/>
|
<input type="text" name="ssid" class="text"/>
|
||||||
<label for="pwd">Password</label>
|
<label for="pwd">Password</label>
|
||||||
|
@ -377,12 +381,35 @@
|
||||||
parseRadio(root["radio"]);
|
parseRadio(root["radio"]);
|
||||||
parseSerial(root["serial"]);
|
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 = document.getElementById("disclaimer")
|
||||||
hiddenInput.value = sessionStorage.getItem("gDisclaimer");
|
hiddenInput.value = sessionStorage.getItem("gDisclaimer");
|
||||||
|
|
||||||
getAjax("/api/setup", parse);
|
getAjax("/api/setup", parse);
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -45,16 +45,17 @@ void webApi::onApi(AsyncWebServerRequest *request) {
|
||||||
|
|
||||||
Inverter<> *iv = mApp->mSys->getInverterByPos(0, false);
|
Inverter<> *iv = mApp->mSys->getInverterByPos(0, false);
|
||||||
String path = request->url().substring(5);
|
String path = request->url().substring(5);
|
||||||
if(path == "system") getSystem(root);
|
if(path == "system") getSystem(root);
|
||||||
else if(path == "statistics") getStatistics(root);
|
else if(path == "statistics") getStatistics(root);
|
||||||
else if(path == "inverter/list") getInverterList(root);
|
else if(path == "inverter/list") getInverterList(root);
|
||||||
else if(path == "index") getIndex(root);
|
else if(path == "index") getIndex(root);
|
||||||
else if(path == "setup") getSetup(root);
|
else if(path == "setup") getSetup(root);
|
||||||
else if(path == "live") getLive(root);
|
else if(path == "setup/networks") getNetworks(root);
|
||||||
else if(path == "record/info") getRecord(root, iv->getRecordStruct(InverterDevInform_All));
|
else if(path == "live") getLive(root);
|
||||||
else if(path == "record/alarm") getRecord(root, iv->getRecordStruct(AlarmData));
|
else if(path == "record/info") getRecord(root, iv->getRecordStruct(InverterDevInform_All));
|
||||||
else if(path == "record/config") getRecord(root, iv->getRecordStruct(SystemConfigPara));
|
else if(path == "record/alarm") getRecord(root, iv->getRecordStruct(AlarmData));
|
||||||
else if(path == "record/live") getRecord(root, iv->getRecordStruct(RealTimeRunData_Debug));
|
else if(path == "record/config") getRecord(root, iv->getRecordStruct(SystemConfigPara));
|
||||||
|
else if(path == "record/live") getRecord(root, iv->getRecordStruct(RealTimeRunData_Debug));
|
||||||
else
|
else
|
||||||
getNotFound(root, F("http://") + request->host() + F("/api/"));
|
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) {
|
void webApi::getLive(JsonObject obj) {
|
||||||
getSystem(obj.createNestedObject(F("system")));
|
getSystem(obj.createNestedObject(F("system")));
|
||||||
|
|
|
@ -44,6 +44,7 @@ class webApi {
|
||||||
|
|
||||||
void getIndex(JsonObject obj);
|
void getIndex(JsonObject obj);
|
||||||
void getSetup(JsonObject obj);
|
void getSetup(JsonObject obj);
|
||||||
|
void getNetworks(JsonObject obj);
|
||||||
void getLive(JsonObject obj);
|
void getLive(JsonObject obj);
|
||||||
void getRecord(JsonObject obj, record_t<> *rec);
|
void getRecord(JsonObject obj, record_t<> *rec);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue