Created
February 2, 2016 17:42
-
-
Save cjdell/4437b1b7614f3a5530e0 to your computer and use it in GitHub Desktop.
ESP8266 + 433Mhz
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 <Hash.h> | |
#include <ESP8266WiFi.h> | |
#include <WiFiClient.h> | |
#include <ESP8266WebServer.h> | |
#include <ESP8266mDNS.h> | |
#include <RCSwitch.h> | |
const char* ssid = "Chris's ESP8266"; | |
const char* password = "12345678"; | |
MDNSResponder mdns; | |
ESP8266WebServer server(80); | |
const int led = 13; | |
RCSwitch mySwitch = RCSwitch(); | |
void handleRoot() { | |
digitalWrite(led, 1); | |
server.send(200, "text/plain", "hello from esp8266!"); | |
digitalWrite(led, 0); | |
} | |
void handleNotFound(){ | |
digitalWrite(led, 1); | |
String message = "File Not Found\n\n"; | |
message += "URI: "; | |
message += server.uri(); | |
message += "\nMethod: "; | |
message += (server.method() == HTTP_GET)?"GET":"POST"; | |
message += "\nArguments: "; | |
message += server.args(); | |
message += "\n"; | |
for (uint8_t i=0; i<server.args(); i++){ | |
message += " " + server.argName(i) + ": " + server.arg(i) + "\n"; | |
} | |
server.send(404, "text/plain", message); | |
digitalWrite(led, 0); | |
} | |
void setup(void){ | |
pinMode(led, OUTPUT); | |
digitalWrite(led, 0); | |
Serial.begin(115200); | |
// WiFi.begin(ssid, password); | |
WiFi.softAP(ssid, password); | |
mySwitch.enableTransmit(4); | |
Serial.println("SETUP"); | |
// // Wait for connection | |
// while (WiFi.status() != WL_CONNECTED) { | |
// delay(500); | |
// Serial.print("."); | |
// } | |
// Serial.println(""); | |
// Serial.print("Connected to "); | |
// Serial.println(ssid); | |
// Serial.print("IP address: "); | |
// Serial.println(WiFi.localIP()); | |
if (mdns.begin("esp8266", WiFi.localIP())) { | |
Serial.println("MDNS responder started"); | |
} | |
server.on("/", handleRoot); | |
//000000000011000000111001 | |
//000000000011000000111000 | |
server.on("/send", [](){ | |
String code = server.arg("code"); | |
mySwitch.send(code.c_str()); | |
Serial.println("code: " + code); | |
char buffer[100]; | |
sprintf(buffer, "sent %s", code.c_str()); | |
server.send(200, "text/plain", buffer); | |
}); | |
server.onNotFound(handleNotFound); | |
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