0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

ESP32 で アクセスポイント + WebServer

Last updated at Posted at 2020-05-26

検証用のミニマムコードです。

「スケッチ例」-「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);
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?