I'm trying to create a AsyncWebServer
after enabling the SoftAP
:
#include <Arduino.h>
#include <SPIFFS.h>
#include <WiFi.h>
#include <WiFiAP.h>
#include <AsyncTCP.h>
#include <ESPAsyncWebServer.h>
WebApp webapp;
void setup()
{
Serial.begin(115200);
SPIFFS.begin();
File f = SPIFFS.open("/index.html");
String s = f.readString();
Serial.println(s);
f.close();
WiFi.softAP("ssid", NULL);
WiFi.softAPsetHostname("ssid");
Serial.println(WiFi.softAPIP());
webapp.Begin();
}
void loop()
{
}
class WebApp
{
public:
WebApp();
void Begin();
private:
AsyncWebServer _server;
};
#include "webapp.h"
WebApp::WebApp() : _server(80)
{
}
void WebApp::Begin()
{
_server.on("/", HTTP_GET, [this](AsyncWebServerRequest *request)
{
Serial.println("GET request");
_server.serveStatic("/", SPIFFS, "/").setDefaultFile("/index.html");
});
_server.onNotFound([](AsyncWebServerRequest *request){
request->send(404);
});
_server.begin();
Serial.println("[WEB] HTTP server started");
}
The SoftAP
brings up the network and I can connect to it (softAPgetStationNum()
tells me that 1 client is connected). It answers to pings.
The index.html
is stored into the flash (the contents is printed out correctly).
But when I try to open the root page (192.168.4.1) it prints out "GET request" but the browser request timeouts and nothing is received.
Am I missing anything in the code?