I previously wrote a similar an unsolved question about simultaneously submitting three parameters to and ESP32--and moving back to the main menu. Now, I just want to submit the three parameters to the ESP32 using whatever method works (get, post, any, etc).
This is based off this tutorial: ESP32 Arduino HTTP server: Getting query parameters – techtutorialsx
GUI
File structure
sketch (folder)
- sketch.ino
- data (folder)
- index.html
sketch.ino
#include <WiFi.h>
#include <ESPAsyncWebServer.h>
#include <SPIFFS.h>
#include <painlessMesh.h>
const char* ssid = "Wireless Controller";
const char* password = "12345678";
// User stub
void sendMessage() ; // Prototype so PlatformIO doesn't complain
Task taskSendMessage( TASK_SECOND * 1 , TASK_FOREVER, &sendMessage );
void sendMessage() {
taskSendMessage.setInterval( random( TASK_SECOND * 1, TASK_SECOND * 5 ));
}
AsyncWebServer server(80);
void notFound(AsyncWebServerRequest *request) {
request->send(404, "text/plain", "Not found");
}
IPAddress IP(192, 168, 1, 1);
IPAddress gateway(192, 168, 1, 1);
IPAddress subnet(255, 255, 255, 0);
void setup()
{
Serial.begin(115200);
// Initialize SPIFFS
if (!SPIFFS.begin(true))
{
Serial.println("An Error has occurred while mounting SPIFFS");
return;
}
WiFi.softAP(ssid, password);
delay(500);
WiFi.softAPConfig(IP, gateway, subnet);
IPAddress IP = WiFi.softAPIP();
Serial.print("AP IP address: ");
Serial.println(IP);
server.on("/", HTTP_GET, [](AsyncWebServerRequest * request) {
int paramsNr = request->params();
Serial.println(paramsNr);
for (int i = 0; i < paramsNr; i++)
{
AsyncWebParameter* p = request->getParam(i);
Serial.print("Param name: ");
Serial.println(p->name());
Serial.print("Param value: ");
Serial.println(p->value());
Serial.println("------");
}
request->send(200, "text/plain", "");
});
server.onNotFound(notFound);
server.begin();
}
void loop() {}
index.html
<!DOCTYPE html>
<html>
<body>
<h1>Main Menu</h1>
<form action="/" method="get">
<label for="size" style="font-size: 22px">Shape Size:</label>
<select name="size" id="size" style="font-size: 22px;">
<option value="1"> 1 </option>
<option value="2"> 1/2 </option>
</select>
<p><label for="speed" style="font-size: 22px">Speed:</label>
<select name="speed" id="speed" style="font-size: 24px">
<option value="1"> Slowest </option>
<option value="2" selected> Regular </option>
</select></p>
<p><<button class="submit" name="circle" value="3">Circle</button></p>
<p><button class="submit" name="square" value="4">Square</button></p>
</form>
</body>
</html>
I have changed the "get" to "post" and "any" while also changing the Arduino code to server.on("/", HTTP_POST and server.on("/", HTTP_ANY with no luck. Every time, the screen is either blank or not found.
This is a minimalistic example of a much larger program. I want to simply keep it to using one HTML file and one ino Arduino file. I realize a bunch of bells and whistles can be added with JS, and this may be better for a more advanced version, but I want to keep the first version as simple as possible. (I will not be the only one using this.)
The index.HTML file is loaded onto the ESP32 by going to Tools → ESP32 Sketch Data Upload.
