1
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?

1円大)XIAO ESP32C6、WebServerを使ってそれっぽいHTMLをPCに表示させる。(これは、マイコン)

Last updated at Posted at 2025-04-13

参考

いろいろ、注意

  • 過去ログを見よ!!
  • これは、親指姫サイズの組み込み用マイコン(pc系の人が見ている感じだか?(これだけで本当に動いているよ!!!
  • アンテナ系を修正した0414
  • 修正する箇所

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

  • なぜかLEDが反転

o_coq866.jpg

結果

o_coq867.jpg


http://esp32.local/

o_coq865.jpg

イメージ

image_original (81).jpg

プログラム



//webserver_test1_XAIO_ESP32C6_1


//インクルド
#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);

  char html[] = {
    "                                "
    "<HTML lang=\"jp\">              "
    "                                "
    "<HEAD>                          "
    "                                "
    "  <meta charset=\"UTF-8\">      "
    "                                "
    "  <TITLE>ようこそ</TITLE>        "
    "                                "
    "</HEAD>                         "
    "                                "
    "<BODY>                          "
    "                                "
    "  <H1>M5NanoC6の接点情報</H1>    "
    "                                "
    "  <H2>GPIO-G1</H2>              "
    "                                "
    "  AAA                           "
    "                                "
    "  <H2>GPIO-G2</H2>              "
    "                                "
    "  BBB                           "
    "                                "
    "                                "
    "  <H3>適度に更新してください</H3>  "
    "                                "
    "</BODY>                         "
    "                                "
    "</HTML>                         "
    "                                "
    "                                "
  };
  
  server.send(200, "text/html", html);
  digitalWrite(LED_BUILTIN, HIGH);
}//handleRoot


//ホームページがない場合
void handleNotFound() {
  digitalWrite(LED_BUILTIN, LOW);
  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);
}//handleNotFound


//初期化
void setup(void) {

  //アンテナの設定
  pinMode(WIFI_ENABLE, OUTPUT); // pinMode(3, OUTPUT);
  digitalWrite(WIFI_ENABLE, LOW); // digitalWrite(3, LOW); // Activate RF switch control
  delay(100);
  pinMode(WIFI_ANT_CONFIG, OUTPUT); // pinMode(14, OUTPUT);
  digitalWrite(WIFI_ANT_CONFIG, LOW); // digitalWrite(14, LOW); // Use IN antenna

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

  //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

1
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
1
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?