Last active
January 27, 2018 21:49
-
-
Save Firehed/b5cb92d730378893062910a0182db3f8 to your computer and use it in GitHub Desktop.
Wifi Example
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
const char* ssid = "yourssid"; | |
const char* password = "yourpassword"; | |
const char* deviceName = "ghsw8181"; |
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 <ESP8266WebServer.h> | |
#include <ESP8266WiFi.h> | |
#include <ESP8266mDNS.h> | |
#include "wifi.h" | |
ESP8266WebServer server(80); | |
void setup() { | |
connectToWifi(); | |
server.on("/", [](){ | |
server.send(200, "text/plain", "ok"); | |
}); | |
server.begin(); | |
} | |
void connectToWifi() { | |
WiFi.hostname(deviceName); | |
WiFi.mode(WIFI_STA); // Client only | |
WiFi.begin(ssid, password); | |
while (WiFi.status() != WL_CONNECTED) { | |
delay(500); | |
} | |
if (!MDNS.begin(deviceName)) { | |
Serial.println("mDNS responder setup failed"); | |
} | |
} | |
void loop() { | |
if (WiFi.status() != WL_CONNECTED) { | |
connectToWifi(); | |
} | |
server.handleClient(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment