From d1d0fb5f65e02c8820fe53736fc3cadd9ef701f5 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Sat, 19 Oct 2024 16:30:33 -0400 Subject: [PATCH] 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]