From d1d0fb5f65e02c8820fe53736fc3cadd9ef701f5 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Sat, 19 Oct 2024 16:30:33 -0400 Subject: [PATCH 1/3] ssid dropdown proof-of-concept --- noisemeter-device/access-point-html.cpp | 10 +++++++--- noisemeter-device/access-point-html.hpp | 3 ++- noisemeter-device/access-point.cpp | 20 +++++++++++++++++++- platformio.ini | 2 +- 4 files changed, 29 insertions(+), 6 deletions(-) diff --git a/noisemeter-device/access-point-html.cpp b/noisemeter-device/access-point-html.cpp index 513fe4e..ac6b4f7 100644 --- a/noisemeter-device/access-point-html.cpp +++ b/noisemeter-device/access-point-html.cpp @@ -72,11 +72,15 @@ const char *HTML_FOOTER = R"html( )html"; -const char *HTML_BODY_FORM = R"html( +const char *HTML_BODY_FORM_HEADER = 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:

- +

Wifi network name: (* = password required)

+

Wifi network password:

Your Email (also your username for logging into the tRacket portal):

diff --git a/noisemeter-device/access-point-html.hpp b/noisemeter-device/access-point-html.hpp index bccf76c..3e500a9 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; diff --git a/noisemeter-device/access-point.cpp b/noisemeter-device/access-point.cpp index 0896120..e66eaaa 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,7 +161,21 @@ 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); diff --git a/platformio.ini b/platformio.ini index 0143d98..feddba3 100644 --- a/platformio.ini +++ b/platformio.ini @@ -27,7 +27,7 @@ build_flags = -std=gnu++17 -DBUILD_PLATFORMIO -DNO_GLOBAL_EEPROM - -DNOISEMETER_VERSION=\"0.2.2\" + -DNOISEMETER_VERSION=\"0.2.3\" -Wall -Wextra [env:esp32-pcb] From 7c633f7c8272c93ea8513c8b2a87d0cb0e4ec0f7 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Sat, 19 Oct 2024 17:05:18 -0400 Subject: [PATCH 2/3] setup form tweaks; use lock emoji for ssids --- noisemeter-device/access-point-html.cpp | 15 ++++++++------- noisemeter-device/access-point.cpp | 4 ++-- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/noisemeter-device/access-point-html.cpp b/noisemeter-device/access-point-html.cpp index ac6b4f7..8dbbeb4 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; @@ -75,16 +76,16 @@ const char *HTML_FOOTER = R"html( const char *HTML_BODY_FORM_HEADER = 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: (* = password required)

- )html"; const char *HTML_BODY_FORM_FOOTER = R"html( - -

Wifi network password:

- -

Your Email (also your username for logging into the tRacket portal):

- +
+
+
+
+

)html"; diff --git a/noisemeter-device/access-point.cpp b/noisemeter-device/access-point.cpp index e66eaaa..7a6e99f 100644 --- a/noisemeter-device/access-point.cpp +++ b/noisemeter-device/access-point.cpp @@ -170,8 +170,8 @@ bool AccessPoint::handle(WebServer& server, HTTPMethod method, String uri) response += ssid; response += "\">"; response += ssid; - if (auto ty = WiFi.encryptionType(i); ty != WIFI_AUTH_OPEN) - response += " *"; + if (WiFi.encryptionType(i) != WIFI_AUTH_OPEN) + response += " 🔒"; response += ""; } From 4694672e1924d3f499b10c58ce42f250d2e139d5 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Thu, 2 Jan 2025 17:24:16 -0500 Subject: [PATCH 3/3] access point: add manual entry page --- noisemeter-device/access-point-html.cpp | 22 ++++++++++++++++++---- noisemeter-device/access-point-html.hpp | 2 +- noisemeter-device/access-point.cpp | 9 +++++++++ 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/noisemeter-device/access-point-html.cpp b/noisemeter-device/access-point-html.cpp index 8dbbeb4..1fc6c3f 100644 --- a/noisemeter-device/access-point-html.cpp +++ b/noisemeter-device/access-point-html.cpp @@ -74,15 +74,16 @@ const char *HTML_FOOTER = R"html( )html"; const char *HTML_BODY_FORM_HEADER = R"html( -

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

+

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)

+




@@ -90,3 +91,16 @@ const char *HTML_BODY_FORM_FOOTER = R"html(
)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:

+ +

Wifi network password:

+ +

Your Email (also your username for logging into the tRacket portal):

+ +

+
+)html"; + diff --git a/noisemeter-device/access-point-html.hpp b/noisemeter-device/access-point-html.hpp index 3e500a9..56af007 100644 --- a/noisemeter-device/access-point-html.hpp +++ b/noisemeter-device/access-point-html.hpp @@ -3,4 +3,4 @@ extern const char *HTML_CONTAINER; extern const char *HTML_FOOTER; 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 7a6e99f..5a942be 100644 --- a/noisemeter-device/access-point.cpp +++ b/noisemeter-device/access-point.cpp @@ -178,6 +178,15 @@ bool AccessPoint::handle(WebServer& server, HTTPMethod method, String uri) 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") {