Created
April 5, 2017 06:31
-
-
Save joelrebel/db7a77f6ce912c9a0c9d8bc7edd3a359 to your computer and use it in GitHub Desktop.
This file contains 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> | |
#include <ESP8266WebServer.h> | |
const char* ssid = "fridge"; | |
const char* password = "fridge"; | |
ESP8266WebServer server(80); | |
void handle_root() { | |
server.send(200, "text/html", "Hi, I accept /on or /off commands :)"); | |
delay(100); | |
} | |
void handle_on() { | |
digitalWrite(BUILTIN_LED, LOW); | |
server.send(200, "text/plain", "Turn on LED"); | |
} | |
void handle_off() { | |
digitalWrite(BUILTIN_LED, HIGH); | |
server.send(200, "text/plain", "Turn off LED"); | |
} | |
void setup(void) | |
{ | |
pinMode(BUILTIN_LED, OUTPUT); | |
digitalWrite(BUILTIN_LED, HIGH); | |
Serial.begin(115200); | |
WiFi.softAP(ssid, password); | |
IPAddress myIP = WiFi.softAPIP(); | |
Serial.println(myIP); | |
server.on("/", handle_root); | |
server.on("/on", handle_on); | |
server.on("/off", handle_off); | |
server.begin(); | |
Serial.println("HTTP server started"); | |
} | |
void loop(void) | |
{ | |
server.handleClient(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment