baobao
4/24/2019 - 3:35 PM

ESP8266WiFi接続ショートコード

ESP8266WiFi接続ショートコード

#include <ESP8266WiFi.h>

const char* ssid = "";
const char* password = "";

WiFiServer server(80);
WiFiClient client;
 
void setup() 
{
  Serial.begin(115200);
  Serial.println("");
  // Wifi接続開始
  WiFi.begin(ssid, password);
  
  Serial.print("Connecting Wifi");
  while (WiFi.status() != WL_CONNECTED) 
  {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("Complete Connect Wifi!!");
  
  server.begin();
  Serial.println("Server started");
  Serial.print("local IP : ");
  Serial.println(WiFi.localIP());
}

void loop() 
{
  responseHelloworld();
  delay(1);
}

void responseHelloworld()
{
  client = server.available();
  while(client)
  {
    if(client.available())
    {
        Serial.println("client.read");
        Serial.println(client.read());
        String result = "<html><body>Hello World!!</body></html>";
        client.print(result);
        delay(10);
        client.stop();             
    }
  }
}