Skip to content

Commit

Permalink
added wifi signal strength information
Browse files Browse the repository at this point in the history
  • Loading branch information
rednblkx committed Oct 16, 2024
1 parent 611f058 commit c767472
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
17 changes: 17 additions & 0 deletions data/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,22 @@
<link rel="icon" type="image/x-icon" href="assets/favicon.ico">
<title>HK Configuration</title>
<script>
async function wifiSignalStrength(){
const data = await fetch("get_wifi_rssi");
const string = await data.text();
const el = document.querySelector("#wifi-rssi-signal");
if(string <= -30 && string >= -70){
el.innerHTML= `${string} (Excellent)`;
} else if(string <= -71 && string >= -80){
el.innerHTML= `${string} (Good)`;
} else if(string <= -81 && string >= -90){
el.innerHTML= `${string} (Fair)`;
} else if(string <= -90){
el.innerHTML= `${string} (Weak)`;
}
}
wifiSignalStrength();
setInterval(wifiSignalStrength, 5000)
async function addComponent(name, button) {
let loaderEl = document.createElement("span")
loaderEl.className = "loader";
Expand Down Expand Up @@ -66,6 +82,7 @@
<img src="assets/logo-white.webp" width="64pxv">
<div>
<h2 style="text-align: center;margin-bottom: 0;margin-top: 0;background: none;padding: 0!important;margin: 0!important;">HomeKey-ESP32</h1>
<p style="text-align: center;margin-top: 0;margin-bottom: 0;">WiFi RSSI: <span id="wifi-rssi-signal"></span></p>
<p style="text-align: center;margin-top: 0;margin-bottom: 0;">version: %VERSION%</p>
</div>
</div>
Expand Down
8 changes: 8 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1317,6 +1317,14 @@ void setupWeb() {
homeSpan.processSerialCommand("X");
});
webServer.addHandler(resetWifiHandle);
auto getWifiRssi = new AsyncCallbackWebHandler();
getWifiRssi->setUri("/get_wifi_rssi");
getWifiRssi->setMethod(HTTP_GET);
getWifiRssi->onRequest([](AsyncWebServerRequest* request) {
std::string rssi_val = std::to_string(WiFi.RSSI());
request->send(200, "text/plain", rssi_val.c_str());
});
webServer.addHandler(getWifiRssi);
if (espConfig::miscConfig.webAuthEnabled) {
LOG(I, "Web Authentication Enabled");
infoHandle->setAuthentication(espConfig::miscConfig.webUsername.c_str(), espConfig::miscConfig.webPassword.c_str());
Expand Down

0 comments on commit c767472

Please sign in to comment.