Skip to content

Instantly share code, notes, and snippets.

@joelrebel
Created April 5, 2017 06:31
Show Gist options
  • Save joelrebel/db7a77f6ce912c9a0c9d8bc7edd3a359 to your computer and use it in GitHub Desktop.
Save joelrebel/db7a77f6ce912c9a0c9d8bc7edd3a359 to your computer and use it in GitHub Desktop.
#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