検証用のミニマムコードです。
「スケッチ例」-「WebServer」-「HelloServer」を改造しました。
"HelloServer" は、WiFi のクライアントで動作しますが、WiFiのAPモードに変更しています。
環境
- Arduino 1.8.10 for Linux
- esp32 by Espressif System Version 1.0.3
- WEMOS LOLIN32
コード
# include <WiFi.h>
# include <WebServer.h>
const char* ssid = "ESP32";
const char* password = "11111111";
WebServer server(80);
void handleRoot() {
server.send(200, "text/plain", "hello ESP32 Web Server");
}
void handleNotFound() {
String message = "File Not Found\n\nURI: ";
message += server.uri();
server.send(404, "text/plain", message);
}
void setup(void) {
Serial.begin(115200);
WiFi.softAP(ssid,password);
IPAddress myIP = WiFi.softAPIP();
Serial.print("AP IP address: ");
Serial.println(myIP);
server.on("/", handleRoot);
server.on("/inline", []() {
server.send(200, "text/plain", "this works as well");
});
server.onNotFound(handleNotFound);
server.begin();
Serial.println("HTTP server started");
}
void loop(void) {
server.handleClient();
}
はじめに投稿したコードは以下のようにヘンな括弧が入っていてバグってました。Sorry!
void handleNotFound() {
String message = "File Not Found\n\nURI: ";
message += server.uri();
}
server.send(404, "text/plain", message);
}