Created
April 24, 2019 15:35
-
-
Save baobao/b22869125475e6387ea5c486bea35497 to your computer and use it in GitHub Desktop.
ESP8266WiFi接続ショートコード
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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(); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment