Skip to content

Commit

Permalink
allow re-configuration (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
ldab authored Dec 28, 2022
1 parent aaab94a commit 224752d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
6 changes: 3 additions & 3 deletions include/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ const char HTTP_CONFIG[] PROGMEM = R"rawliteral(
<div class="content">
<div class="card-grid">
<div class="card">
<form action="/" method="POST">
<form action="/config" method="POST">
<p>
<label for="ssid">SSID</label>
<input type="text" id ="ssid" name="ssid"><br>
<input type="text" id ="ssid" name="ssid" value=%HTML_CONFIG_SSID%><br>
<label for="pass">Password</label>
<input type="text" id ="pass" name="pass"><br>
<input type="text" id ="pass" name="pass" value=************><br>
<label for="server">MQTT Server</label>
<input type="text" id ="server" name="server" value="io.adafruit.com"><br>
<label for="user">MQTT Username</label>
Expand Down
2 changes: 1 addition & 1 deletion platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
default_envs = esp32

build_flags =
'-D FIRMWARE_VERSION="2.0.1"'
'-D FIRMWARE_VERSION="2.0.2"'
-D VERBOSE
; -DCORE_DEBUG_LEVEL=3

Expand Down
11 changes: 8 additions & 3 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,8 @@ String processor(const String &var)
ret = "<strong> Not Connected</ strong>";
return ret;
}
if (var == "HTML_CONFIG_SSID")
return WiFi.SSID();
if (var == "UPTIME") {
String ret = String(millis() / 1000 / 60);
ret += " min ";
Expand Down Expand Up @@ -360,9 +362,9 @@ String processor(const String &var)
return String();
}

void captiveServer()
void configServer()
{
server.on("/", HTTP_POST, [](AsyncWebServerRequest *request) {
server.on("/config", HTTP_POST, [](AsyncWebServerRequest *request) {
int params = request->params();
StaticJsonDocument<192> doc;
char output[192] = {'\0'};
Expand Down Expand Up @@ -974,6 +976,7 @@ void setup()

WiFi.mode(WIFI_STA);
WiFi.onEvent(WiFiEvent);
WiFi.setHostname("kiln");
WiFi.begin();

// Initialize SPIFFS
Expand All @@ -992,7 +995,7 @@ void setup()
WiFi.waitForConnectResult() == WL_NO_SSID_AVAIL) { //~ 100 * 100ms
DBG("WiFi Failed!: %u\n", WiFi.status());

captiveServer();
configServer();

WiFi.softAP("myKiln");

Expand Down Expand Up @@ -1064,6 +1067,8 @@ void setup()
request->send_P(200, "text/html", HTTP_CONFIG, processor);
});

configServer();

server.on("/info", HTTP_GET, [](AsyncWebServerRequest *request) {
request->send_P(200, "text/html", HTTP_INFO, processor);
});
Expand Down

0 comments on commit 224752d

Please sign in to comment.