x 過去ログを見よ!!
x 何度か「シリアルモニタ」を閉じたり開いたりする。
修正する箇所
const char *ssid = "ご自宅のSSID";
const char *password = "ご自宅のパスワード";
結果
(なぜかUSBシリアルが失敗)
(開きなおす)
(なぜかUSBシリアルが成功)
プログラム
#include <WiFi.h>
#include <NetworkClient.h>
#include <WebServer.h>
#include <ESPmDNS.h>
const char *ssid = "ご自宅のSSID";
const char *password = "ご自宅のパスワード";
WebServer server(80);
const int led = 7;
void handleRoot() {
digitalWrite(led, 1);
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, 0);
}
void handleNotFound() {
digitalWrite(led, 1);
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, 0);
}
void setup(void) {
pinMode(led, OUTPUT);
digitalWrite(led, 0);
Serial.begin(115200);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
Serial.println("");
for(int i=0;i<9;i++){
delay(500); //起動待ち
Serial.print(".");
}
Serial.println("");
// Wait for connection
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
if (MDNS.begin("esp32")) {
Serial.println("MDNS responder started");
}
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();
delay(2); //allow the cpu to switch to other tasks
}