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?

ESP32-S2、WebServerを使ってそれっぽいHTMLをPCに表示させる。

0
Posted at

いろいろ、注意

  • 過去ログを見よ!!
  • 修正する箇所

const char *ssid = "ご自宅のSSID";
const char *password = "ご自宅のパスワード";

結果

o_coq867.jpg


http://esp32.local/

Screenshot From 2026-08-07 06-59-53.png

無題.jpg

プログラム



//webserver_test1_esp32_s2_2


//インクルド
#include <WiFi.h>
#include <NetworkClient.h>
#include <WebServer.h>
#include <ESPmDNS.h>


//定義
const char *ssid = "ご自宅のSSID";
const char *password = "ご自宅のパスワード";

//サービスポート番号の登録
WebServer server(80);


//ホームページ
void handleRoot() {

  //digitalWrite(LED_BUILTIN, LOW); //m5nanoc6 led

  char html[] = {
    "                                "
    "<HTML lang=\"jp\">              "
    "                                "
    "<HEAD>                          "
    "                                "
    "  <meta charset=\"UTF-8\">      "
    "                                "
    "  <TITLE>ようこそ</TITLE>        "
    "                                "
    "</HEAD>                         "
    "                                "
    "<BODY>                          "
    "                                "
    "  <H1>ATOMS3の接点情報</H1>    "
    "                                "
    "  <H2>GPIO-G1</H2>              "
    "                                "
    "  AAA                           "
    "                                "
    "  <H2>GPIO-G2</H2>              "
    "                                "
    "  BBB                           "
    "                                "
    "                                "
    "  <H3>適度に更新してください</H3>  "
    "                                "
    "</BODY>                         "
    "                                "
    "</HTML>                         "
    "                                "
    "                                "
  };

  //HTMLを送ってあげる
  server.send(200, "text/html", html);
  //digitalWrite(LED_BUILTIN, HIGH); //m5nanoc6 led

}  //handleRoot


//ホームページがない場合
void handleNotFound() {

  //digitalWrite(LED_BUILTIN, LOW); //m5nanoc6 led
  String message = "File Not Found\n\n";
  message += "URI: ";
  message += server.uri();
  message += "\nMethod: ";
  message += (server.method() == HTTP_GET) ? "GET" : "POST";
  message += "\nArguments: ";
  message += server.args();
  message += "\n";
  for (uint8_t i = 0; i < server.args(); i++) {
    message += " " + server.argName(i) + ": " + server.arg(i) + "\n";
  }
  server.send(404, "text/plain", message);
  //digitalWrite(LED_BUILTIN, HIGH); //m5nanoc6 led

}  //handleNotFound


//初期化
void setup(void) {

  //GPIOポートの初期化
  //pinMode(LED_BUILTIN, OUTPUT); //m5nanoc6 led
  //digitalWrite(LED_BUILTIN, HIGH); //m5nanoc6 led

  //WiFiの初期化
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);
  delay(3000);  //決め打ちなので、おかしかったら調整してね! wifiの待ち0.5*6

  //ローカルドメインサービス
  MDNS.begin("esp32");

  //割り込みの登録 ホームページ
  server.on("/", handleRoot);

  //割り込みの登録 ホームページ以外 404
  server.onNotFound(handleNotFound);

  //Webサーバの開始
  server.begin();

}  //setup


//メインループ
void loop(void) {

  //制御を渡す
  server.handleClient();
  delay(2);  //allow the cpu to switch to other tasks

}  //loop

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?