Skip to content

Commit

Permalink
WiFi signal strength added
Browse files Browse the repository at this point in the history
  • Loading branch information
Thorsten Ludewig committed Apr 22, 2021
1 parent 151025d commit cdc260f
Show file tree
Hide file tree
Showing 2 changed files with 118 additions and 16 deletions.
73 changes: 73 additions & 0 deletions include/css/wifi_logo_gz.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#ifndef __WIFI_LOGO_GZ_H__
#define __WIFI_LOGO_GZ_H__

#include <Arduino.h>

const unsigned char wifi_logo_css_gz[] PROGMEM = {
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x03, 0xd3, 0x2b,
0xcf, 0x4c, 0xcb, 0x34, 0xac, 0x4e, 0x4a, 0x4c, 0xce, 0x4e, 0x2f, 0xca,
0x2f, 0xcd, 0x4b, 0xb1, 0x2a, 0x2d, 0xca, 0xd1, 0x50, 0x4a, 0x49, 0x2c,
0x49, 0xb4, 0xca, 0xcc, 0x4d, 0x4c, 0x4f, 0xd5, 0x2f, 0x2e, 0x4b, 0xd7,
0xae, 0xc8, 0xcd, 0xb1, 0x2e, 0x2d, 0x49, 0xb3, 0xd0, 0xb1, 0x01, 0xf2,
0x14, 0xca, 0x32, 0x53, 0xcb, 0x9d, 0xf2, 0x2b, 0x6c, 0xd5, 0x0d, 0x14,
0x0c, 0x14, 0x0c, 0x0d, 0xc0, 0x58, 0x5d, 0x01, 0xa8, 0x26, 0xaf, 0xd8,
0x56, 0x3d, 0xa3, 0xa4, 0xa4, 0xc0, 0x4a, 0x5f, 0xbf, 0xbc, 0xbc, 0x5c,
0xaf, 0xdc, 0x58, 0x2f, 0xbf, 0x28, 0x5d, 0xdf, 0xc8, 0xc0, 0xc0, 0x00,
0x64, 0x8a, 0xba, 0x42, 0x5a, 0x66, 0x4e, 0x8e, 0x6e, 0x51, 0x69, 0x4e,
0xaa, 0xad, 0x7a, 0x6a, 0x59, 0x6a, 0x5e, 0x7e, 0x4a, 0x8a, 0xba, 0x42,
0x72, 0x4e, 0x66, 0x01, 0xba, 0x58, 0x71, 0x49, 0x51, 0x7e, 0x76, 0xaa,
0x6e, 0x4e, 0x66, 0x5e, 0x6a, 0x56, 0x7e, 0x66, 0x9e, 0xad, 0x3a, 0xd8,
0x65, 0xea, 0x0a, 0x50, 0xf1, 0xdc, 0xcc, 0x92, 0xd4, 0xa2, 0x9c, 0x4c,
0x20, 0x65, 0xab, 0x6e, 0xa4, 0x6e, 0x67, 0x53, 0x90, 0x58, 0x92, 0xa1,
0x90, 0x62, 0xab, 0xee, 0x6b, 0x69, 0xac, 0x67, 0x66, 0x66, 0xae, 0x60,
0x61, 0xa8, 0x67, 0x64, 0x68, 0x99, 0x6c, 0xa0, 0x60, 0xa4, 0x67, 0x61,
0x69, 0xa1, 0x6b, 0xa4, 0x67, 0x66, 0x6a, 0xa6, 0x60, 0xaa, 0x67, 0x64,
0x62, 0xa1, 0x6b, 0xaa, 0x67, 0x69, 0x6c, 0x0c, 0x61, 0x67, 0x00, 0x39,
0x26, 0xc6, 0x16, 0xc9, 0xba, 0xc6, 0x7a, 0x46, 0xe6, 0xe6, 0x0a, 0x06,
0x40, 0xae, 0xa5, 0xb1, 0x09, 0x50, 0xb5, 0xb1, 0x29, 0x94, 0x09, 0xd6,
0x12, 0x66, 0x68, 0x01, 0x94, 0x37, 0x4c, 0x36, 0x00, 0xca, 0x58, 0x58,
0x9a, 0x01, 0xcd, 0x04, 0x9a, 0x06, 0x54, 0x60, 0x64, 0x02, 0x32, 0x13,
0xa4, 0x03, 0xa4, 0xcc, 0x2c, 0xc3, 0x54, 0x0f, 0x64, 0x18, 0xc8, 0x2c,
0x33, 0x60, 0xa8, 0x40, 0xec, 0x31, 0xd2, 0x33, 0x36, 0xb1, 0x04, 0xda,
0x06, 0xb3, 0xd3, 0xac, 0xcc, 0xcc, 0x48, 0xcf, 0xd2, 0xc4, 0xa2, 0xca,
0xd7, 0xdc, 0x40, 0xcf, 0xc0, 0xd8, 0x10, 0xe4, 0x52, 0x63, 0x43, 0x0b,
0x88, 0x4b, 0x4d, 0x8c, 0x80, 0x36, 0x18, 0x1b, 0x81, 0x4c, 0x35, 0x04,
0xbb, 0xd4, 0xd0, 0xd2, 0x14, 0xa8, 0x17, 0xc8, 0xce, 0xd0, 0x35, 0xd3,
0x33, 0xb1, 0x34, 0x4e, 0x06, 0xca, 0x5b, 0x98, 0x59, 0x80, 0x5d, 0x6a,
0x68, 0x09, 0x76, 0xa9, 0x81, 0x39, 0xd0, 0x25, 0x20, 0xb6, 0xa9, 0x1e,
0x50, 0x5d, 0x98, 0xb1, 0x25, 0xd0, 0xa9, 0xe6, 0x10, 0xa7, 0x9a, 0x18,
0x03, 0x9d, 0x0a, 0x34, 0x0e, 0xa4, 0xc0, 0xc4, 0x02, 0x64, 0x10, 0x50,
0x0b, 0x58, 0x59, 0x06, 0xc4, 0x34, 0x60, 0xe0, 0x98, 0x59, 0x82, 0x9d,
0x0a, 0xb2, 0x08, 0xe8, 0x54, 0x03, 0xb0, 0x75, 0x30, 0x4b, 0xcb, 0x4c,
0x8c, 0xf4, 0x0c, 0x4c, 0x0c, 0xab, 0x7c, 0x4d, 0xcc, 0xf4, 0x2c, 0x0c,
0xc1, 0x81, 0x6a, 0x92, 0x68, 0xaa, 0x67, 0x60, 0x06, 0x52, 0x05, 0x22,
0x81, 0x91, 0x6f, 0x08, 0x34, 0x1c, 0xc4, 0x04, 0x09, 0x9b, 0x65, 0xe8,
0x9a, 0xeb, 0x19, 0x9a, 0x9b, 0x62, 0x57, 0x63, 0x02, 0x56, 0x69, 0x16,
0x66, 0x6a, 0xa1, 0x67, 0x66, 0x60, 0x09, 0x56, 0x63, 0x02, 0x74, 0x93,
0x81, 0x99, 0x09, 0xd0, 0x05, 0x06, 0x86, 0x20, 0x03, 0x20, 0x4a, 0x4c,
0x32, 0xb0, 0x9b, 0x02, 0x52, 0x01, 0xb1, 0xd9, 0x24, 0x0c, 0x18, 0xbf,
0x26, 0x55, 0x90, 0xd4, 0x64, 0xab, 0x5e, 0x9c, 0x99, 0x53, 0x96, 0x5a,
0x04, 0xe1, 0xe9, 0x42, 0xd2, 0x56, 0x5e, 0x7e, 0x5e, 0x55, 0x6a, 0x51,
0xbe, 0xba, 0x3e, 0x52, 0xd2, 0x30, 0x32, 0xd6, 0x33, 0x31, 0x33, 0x56,
0xb0, 0x30, 0xd6, 0x33, 0x30, 0x32, 0x06, 0x07, 0xb8, 0x21, 0x30, 0x9e,
0x8d, 0xf4, 0x8c, 0x80, 0x01, 0x6a, 0xac, 0x67, 0x61, 0x06, 0x8a, 0x73,
0x90, 0x6b, 0xc0, 0x6c, 0x90, 0x57, 0x0c, 0x8c, 0x4d, 0x41, 0x01, 0x6e,
0x6e, 0x09, 0x49, 0x1a, 0x40, 0x6f, 0xea, 0x1a, 0xea, 0x99, 0x1b, 0x83,
0xfd, 0x61, 0x0a, 0x4c, 0x33, 0x40, 0x2d, 0x61, 0xe6, 0x16, 0x7a, 0xe6,
0x90, 0x94, 0x61, 0x08, 0x4c, 0x55, 0x60, 0xc3, 0x74, 0x4d, 0xf4, 0x4c,
0x2c, 0x20, 0x5e, 0x33, 0x85, 0xb0, 0x81, 0x1e, 0x02, 0x99, 0x65, 0xa4,
0x07, 0x36, 0x0a, 0xea, 0x69, 0x60, 0x70, 0x9b, 0x1a, 0x41, 0xd9, 0x60,
0x1d, 0x65, 0x26, 0x7a, 0xc6, 0x86, 0xc6, 0x50, 0x5f, 0x61, 0xfa, 0x03,
0x94, 0x7f, 0xec, 0x94, 0x34, 0x6b, 0xc1, 0xd9, 0xd5, 0x68, 0x34, 0xbb,
0x82, 0x33, 0x01, 0x28, 0xf3, 0x81, 0x02, 0x12, 0x18, 0x27, 0x20, 0x26,
0x28, 0x1f, 0x5a, 0x8c, 0xf4, 0xec, 0x0a, 0xc9, 0x08, 0x44, 0x67, 0x8b,
0x41, 0x9a, 0xb9, 0x7d, 0x87, 0x53, 0x76, 0x35, 0x1e, 0xcd, 0xae, 0xf4,
0xcd, 0xae, 0x24, 0xe6, 0x81, 0xd1, 0xba, 0x18, 0x58, 0x0b, 0x83, 0xea,
0x57, 0xb2, 0xeb, 0xe2, 0x61, 0x95, 0x5d, 0x4d, 0x46, 0xb3, 0x2b, 0x7d,
0xb3, 0xeb, 0x68, 0x63, 0x18, 0xd4, 0xf0, 0x1c, 0xcd, 0x80, 0xc0, 0xe6,
0x2d, 0x17, 0x00, 0x43, 0xf6, 0x30, 0x37, 0x8f, 0x0e, 0x00, 0x00
};

const unsigned int wifi_logo_css_gz_len = 743;

#endif
61 changes: 45 additions & 16 deletions lib/WebPages/RootPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,25 @@ void handleRootPage()
sprintf(titleBuffer, APP_NAME " - %s", appcfg.ota_hostname);
sendHeader(titleBuffer);

sendPrint("<form class='pure-form pure-form-aligned'><fieldset>");
sendPrint_P(PSTR("<form class='pure-form pure-form-aligned'><fieldset>"));

sendLegend("Current Status");
sendLegend_P(PSTR("Current Status"));
sendPrintf("<div id='idpwr' class='pure-button' "
"style='background-color: #%s'>Power is %s</div>",
webPowerState ? "80ff80" : "ff8080",
webPowerState ? "ON" : "OFF");

sendLegend("Actions");
sendPrint(
sendLegend_P(PSTR("Actions"));
sendPrint_P(PSTR(
"<a href=\"/?power=ON\" class=\"pure-button button-on\">ON</a>"
"<a href=\"/?power=OFF\" class=\"pure-button button-off\">OFF</a>");
"<a href=\"/?power=OFF\" class=\"pure-button button-off\">OFF</a>"));

sendLegend_P(PSTR("WiFi signal"));
sendPrint_P(PSTR("<span id='wifi' style='vertical-align:middle;display:inline-block;width:48px;height:48px' class='wifi4'></span>" ));
sendPrint_P(PSTR("<span id='wsig'></span>" ));

#if defined(HAVE_ENERGY_SENSOR) && defined(HAVE_HLW8012)
sendLegend("Energy Sensor");
sendLegend_P("Energy Sensor");
int rid=0;
char valueBuffer[32];

Expand All @@ -56,10 +60,10 @@ void handleRootPage()
sendTextGroupReadOnly( rid++, "Power", valueBuffer );
#endif

sendPrint("</fieldset></form>\n");
sendPrint_P(PSTR("</fieldset></form>\n"));

#ifdef HAVE_ENERGY_SENSOR
sendPrint( "<script>function getPowerState(){"
sendPrint_P( PSTR("<script>function getPowerState(){"
"var v=document.getElementById('pgid0'),"
"c=document.getElementById('pgid1'),"
"p=document.getElementById('pgid2');"
Expand All @@ -75,15 +79,40 @@ void handleRootPage()
"s.textContent=\"Power is OFF\";"
"s.style=\"background-color: #ff8080\";"
"}"
"})}setInterval(getPowerState,5e3);</script>" );
"})}setInterval(getPowerState,5e3);</script>" ));
#else
sendPrint(
"<script>function getPowerState(){var e = "
"document.getElementById(\"idpwr\");fetch(\"/state\").then((resp) => "
"resp.json()).then(function(data){if(data.state===\"ON\"){e.textContent="
"\"Power is ON\";e.style=\"background-color: #80ff80\";} else "
"{e.textContent=\"Power is OFF\";e.style=\"background-color: "
"#ff8080\";}});} setInterval(getPowerState,10000);</script>");
sendPrint_P(PSTR(
"<script>"
"function getPowerState(){"
"var e = document.getElementById(\"idpwr\");"
"fetch(\"/state\").then((resp) => resp.json()).then(function(data){"
"if(data.state===\"ON\"){"
"e.textContent=\"Power is ON\";"
"e.style=\"background-color: #80ff80\";"
"}"
"else {"
"e.textContent=\"Power is OFF\";"
"e.style=\"background-color:#ff8080\";"
"}"
"})"
"}"
"setInterval(getPowerState,10000);"
"</script>"));
#endif

sendPrint_P(PSTR(
"<script>"
"function getInfo(){"
"var wi = document.getElementById(\"wifi\");"
"var ws = document.getElementById(\"wsig\");"
"fetch(\"/info\").then((resp) => resp.json()).then(function(info){"
"var i = Math.min(Math.trunc(info.wifi_signal/25)+1,4);"
"ws.innerHTML= ' ' + info.wifi_signal + '%';"
"wi.className='wifi' + i;"
"})"
"}"
"getInfo();"
"setInterval(getInfo,61000);"
"</script>"));
sendFooter();
}

0 comments on commit cdc260f

Please sign in to comment.