diff --git a/noisemeter-device/access-point-html.cpp b/noisemeter-device/access-point-html.cpp index 513fe4e..1fc6c3f 100644 --- a/noisemeter-device/access-point-html.cpp +++ b/noisemeter-device/access-point-html.cpp @@ -19,6 +19,7 @@ font-size: 24px; padding: 5px; margin-top: 3px; } +select, input{margin-bottom: 1em;min-width: 150px;} .meter { height: 5px; position: relative; @@ -72,7 +73,25 @@ const char *HTML_FOOTER = R"html( )html"; -const char *HTML_BODY_FORM = R"html( +const char *HTML_BODY_FORM_HEADER = R"html( +

Select your home WiFi network below and enter its password to get the sensor online:

+
+
+ +

(🔒 = password required)
(Don't see your network? Enter it manually)

+

+
+
+
+

+
+)html"; + +const char *HTML_BODY_FORM_MANUAL = R"html(

Enter the wifi network name and password for your home network, which the sensor can connect to to get online:

Wifi network name:

diff --git a/noisemeter-device/access-point-html.hpp b/noisemeter-device/access-point-html.hpp index bccf76c..56af007 100644 --- a/noisemeter-device/access-point-html.hpp +++ b/noisemeter-device/access-point-html.hpp @@ -1,5 +1,6 @@ extern const char *HTML_HEADER; extern const char *HTML_CONTAINER; extern const char *HTML_FOOTER; -extern const char *HTML_BODY_FORM; - +extern const char *HTML_BODY_FORM_HEADER; +extern const char *HTML_BODY_FORM_FOOTER; +extern const char *HTML_BODY_FORM_MANUAL; diff --git a/noisemeter-device/access-point.cpp b/noisemeter-device/access-point.cpp index 0896120..5a942be 100644 --- a/noisemeter-device/access-point.cpp +++ b/noisemeter-device/access-point.cpp @@ -27,6 +27,8 @@ constexpr auto ACCESS_POINT_TIMEOUT_SEC = MIN_TO_SEC(30); const IPAddress AccessPoint::IP (8, 8, 4, 4); const IPAddress AccessPoint::Netmask (255, 255, 255, 0); +static int networkScanCount = 0; + AccessPoint::AccessPoint(SubmissionHandler func): timeout(ACCESS_POINT_TIMEOUT_SEC), server(80), @@ -50,6 +52,8 @@ String AccessPoint::htmlFromMsg(const char *msg, const char *extra) void AccessPoint::run() { + networkScanCount = WiFi.scanNetworks(); + WiFi.mode(WIFI_AP); WiFi.softAPConfig(IP, IP, Netmask); WiFi.softAP(SSID, Passkey); @@ -157,9 +161,32 @@ bool AccessPoint::handle(WebServer& server, HTTPMethod method, String uri) response.reserve(2048); response += HTML_HEADER; response += HTML_CONTAINER; - response += HTML_BODY_FORM; + response += HTML_BODY_FORM_HEADER; + + for (int i = 0; i < networkScanCount; ++i) { + const auto ssid = WiFi.SSID(i); + + response += ""; + } + + response += HTML_BODY_FORM_FOOTER; response += HTML_FOOTER; + timeout = DAY_TO_SEC(30); + server.send_P(200, PSTR("text/html"), response.c_str()); + } else if (uri == "/manual") { + String response; + response.reserve(2048); + response += HTML_HEADER; + response += HTML_CONTAINER; + response += HTML_BODY_FORM_MANUAL; + response += HTML_FOOTER; timeout = DAY_TO_SEC(30); server.send_P(200, PSTR("text/html"), response.c_str()); } else if (uri == "/connecttest.txt") { diff --git a/platformio.ini b/platformio.ini index 18acf4b..215b03d 100644 --- a/platformio.ini +++ b/platformio.ini @@ -26,7 +26,7 @@ build_unflags = build_flags = -std=gnu++17 -DNO_GLOBAL_EEPROM - -DNOISEMETER_VERSION=\"0.2.2\" + -DNOISEMETER_VERSION=\"0.2.3\" -Wall -Wextra # Optional build flags: