#include <WiFi.h>
#include <ESPAsyncWebServer.h>
#include <SPIFFS.h>
//#include <esp_task_wdt.h>
#include <soc/rtc_wdt.h>
const char* ssid = "Wireless Controller";
const char* password = "12345678";
AsyncWebServer server(80);
void notFound(AsyncWebServerRequest *request)
{
request->send(404, "text/plain", "Not found");
}
void action(AsyncWebServerRequest *request)
{
Serial.println("ACTION!");
int params = request->params(); // amount of params
for (int i = 0; i < params; i++)
{
AsyncWebParameter* p = request->getParam(i);
Serial.printf("POST[%s]: %s\n", p->name().c_str(), p->value().c_str());
}
request->send(SPIFFS, "/index.html", String(), false);
}
IPAddress IP(192, 168, 1, 1);
IPAddress gateway(192, 168, 1, 1);
IPAddress subnet(255, 255, 255, 0);
void setup()
{
Serial.begin(115200); // debugging
Serial2.begin(9600, SERIAL_8N1, 16, 17); // Send data on pin 17
delay(500);
// esp_task_wdt_init(30, false);
// rtc_wdt_protect_off();
// rtc_wdt_disable();
// Initialize SPIFFS
if (!SPIFFS.begin(true))
{
Serial.println("An Error has occurred while mounting SPIFFS");
return;
}
// Connect to Wi-Fi network with SSID and password
Serial.print("Setting AP (Access Point)…");
// Remove the password parameter, if you want the AP (Access Point) to be open
WiFi.softAP(ssid, password);
delay(2000);
WiFi.softAPConfig(IP, gateway, subnet);
IPAddress IP = WiFi.softAPIP();
Serial.print("AP IP address: ");
Serial.println(IP);
// Route to load style.css file
server.on("/style.css", HTTP_GET, [](AsyncWebServerRequest * request) {
request->send(SPIFFS, "/style.css", "text/css");
});
// Index.HTML NAVIGATION BUTTIONS ************************************************
server.on("/", HTTP_GET, [](AsyncWebServerRequest * request) {
request->send(SPIFFS, "/index.html", String(), false);
});
server.on("/action", HTTP_POST, action);
// Pictures *****************************************************************
server.on("/0all.png", HTTP_GET, [](AsyncWebServerRequest * request) {
request->send(SPIFFS, "/0all.png", "image/png");
});
server.on("/1circle.png", HTTP_GET, [](AsyncWebServerRequest * request) {
request->send(SPIFFS, "/1circle.png", "image/png");
});
server.on("/2fspiral.png", HTTP_GET, [](AsyncWebServerRequest * request) {
request->send(SPIFFS, "/2fspiral.png", "image/png");
});
server.on("/3ped.png", HTTP_GET, [](AsyncWebServerRequest * request) {
request->send(SPIFFS, "/3ped.png", "image/png");
});
server.on("/4clover.png", HTTP_GET, [](AsyncWebServerRequest * request) {
request->send(SPIFFS, "/4clover.png", "image/png");
});
server.onNotFound(notFound);
server.begin();
// esp_task_wdt_init(30, false);
rtc_wdt_protect_off();
rtc_wdt_disable();
}
void loop()
{
// May not need once loop contains something:
vTaskDelay(10); //https://github.com/espressif/arduino-esp32/issues/595
}