Skip to content

Commit

Permalink
ssid dropdown proof-of-concept
Browse files Browse the repository at this point in the history
  • Loading branch information
tcsullivan committed Oct 19, 2024
1 parent 1d679f9 commit d1d0fb5
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 6 deletions.
10 changes: 7 additions & 3 deletions noisemeter-device/access-point-html.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,15 @@ const char *HTML_FOOTER = R"html(
</html>
)html";

const char *HTML_BODY_FORM = R"html(
const char *HTML_BODY_FORM_HEADER = R"html(
<p>Enter the wifi network name and password for your home network, which the sensor can connect to to get online:<br/><br/></p>
<form method='POST' action='/submit' enctype='multipart/form-data'>
<p>Wifi network name:</p>
<input type='text' name='ssid' autocorrect='off' autocapitalize='none' autocomplete='off' required/>
<p>Wifi network name: (* = password required)</p>
<select name='ssid' required>
)html";

const char *HTML_BODY_FORM_FOOTER = R"html(
</select>
<p>Wifi network password:</p>
<input type='password' name='psk'/>
<p>Your Email (also your username for logging into the tRacket portal):</p>
Expand Down
3 changes: 2 additions & 1 deletion noisemeter-device/access-point-html.hpp
Original file line number Diff line number Diff line change
@@ -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;

20 changes: 19 additions & 1 deletion noisemeter-device/access-point.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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);
Expand Down Expand Up @@ -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 += "<option value=\"";
response += ssid;
response += "\">";
response += ssid;
if (auto ty = WiFi.encryptionType(i); ty != WIFI_AUTH_OPEN)
response += " *";
response += "</option>";
}

response += HTML_BODY_FORM_FOOTER;
response += HTML_FOOTER;

timeout = DAY_TO_SEC(30);
Expand Down
2 changes: 1 addition & 1 deletion platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit d1d0fb5

Please sign in to comment.