Skip to content

Commit d1d0fb5

Browse files
committed
ssid dropdown proof-of-concept
1 parent 1d679f9 commit d1d0fb5

File tree

4 files changed

+29
-6
lines changed

4 files changed

+29
-6
lines changed

noisemeter-device/access-point-html.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,15 @@ const char *HTML_FOOTER = R"html(
7272
</html>
7373
)html";
7474

75-
const char *HTML_BODY_FORM = R"html(
75+
const char *HTML_BODY_FORM_HEADER = R"html(
7676
<p>Enter the wifi network name and password for your home network, which the sensor can connect to to get online:<br/><br/></p>
7777
<form method='POST' action='/submit' enctype='multipart/form-data'>
78-
<p>Wifi network name:</p>
79-
<input type='text' name='ssid' autocorrect='off' autocapitalize='none' autocomplete='off' required/>
78+
<p>Wifi network name: (* = password required)</p>
79+
<select name='ssid' required>
80+
)html";
81+
82+
const char *HTML_BODY_FORM_FOOTER = R"html(
83+
</select>
8084
<p>Wifi network password:</p>
8185
<input type='password' name='psk'/>
8286
<p>Your Email (also your username for logging into the tRacket portal):</p>
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
extern const char *HTML_HEADER;
22
extern const char *HTML_CONTAINER;
33
extern const char *HTML_FOOTER;
4-
extern const char *HTML_BODY_FORM;
4+
extern const char *HTML_BODY_FORM_HEADER;
5+
extern const char *HTML_BODY_FORM_FOOTER;
56

noisemeter-device/access-point.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ constexpr auto ACCESS_POINT_TIMEOUT_SEC = MIN_TO_SEC(30);
2727
const IPAddress AccessPoint::IP (8, 8, 4, 4);
2828
const IPAddress AccessPoint::Netmask (255, 255, 255, 0);
2929

30+
static int networkScanCount = 0;
31+
3032
AccessPoint::AccessPoint(SubmissionHandler func):
3133
timeout(ACCESS_POINT_TIMEOUT_SEC),
3234
server(80),
@@ -50,6 +52,8 @@ String AccessPoint::htmlFromMsg(const char *msg, const char *extra)
5052

5153
void AccessPoint::run()
5254
{
55+
networkScanCount = WiFi.scanNetworks();
56+
5357
WiFi.mode(WIFI_AP);
5458
WiFi.softAPConfig(IP, IP, Netmask);
5559
WiFi.softAP(SSID, Passkey);
@@ -157,7 +161,21 @@ bool AccessPoint::handle(WebServer& server, HTTPMethod method, String uri)
157161
response.reserve(2048);
158162
response += HTML_HEADER;
159163
response += HTML_CONTAINER;
160-
response += HTML_BODY_FORM;
164+
response += HTML_BODY_FORM_HEADER;
165+
166+
for (int i = 0; i < networkScanCount; ++i) {
167+
const auto ssid = WiFi.SSID(i);
168+
169+
response += "<option value=\"";
170+
response += ssid;
171+
response += "\">";
172+
response += ssid;
173+
if (auto ty = WiFi.encryptionType(i); ty != WIFI_AUTH_OPEN)
174+
response += " *";
175+
response += "</option>";
176+
}
177+
178+
response += HTML_BODY_FORM_FOOTER;
161179
response += HTML_FOOTER;
162180

163181
timeout = DAY_TO_SEC(30);

platformio.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ build_flags =
2727
-std=gnu++17
2828
-DBUILD_PLATFORMIO
2929
-DNO_GLOBAL_EEPROM
30-
-DNOISEMETER_VERSION=\"0.2.2\"
30+
-DNOISEMETER_VERSION=\"0.2.3\"
3131
-Wall -Wextra
3232

3333
[env:esp32-pcb]

0 commit comments

Comments
 (0)