Skip to content

Instantly share code, notes, and snippets.

@Firehed
Last active January 27, 2018 21:49
Show Gist options
  • Save Firehed/b5cb92d730378893062910a0182db3f8 to your computer and use it in GitHub Desktop.
Save Firehed/b5cb92d730378893062910a0182db3f8 to your computer and use it in GitHub Desktop.
Wifi Example
const char* ssid = "yourssid";
const char* password = "yourpassword";
const char* deviceName = "ghsw8181";
#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