62 lines
1.1 KiB
C++
62 lines
1.1 KiB
C++
#include <ESP8266WiFi.h>
|
|
#include <RCSwitch.h>
|
|
|
|
RCSwitch mySwitch = RCSwitch();
|
|
|
|
const char* ssid = "skynet";
|
|
const char* password = "#39dnSKDk39";
|
|
|
|
WiFiServer server(80);
|
|
|
|
void setup() {
|
|
Serial.begin(9600);
|
|
delay(10);
|
|
|
|
Serial.print("Connecting to ");
|
|
Serial.println(ssid);
|
|
WiFi.begin(ssid, password);
|
|
|
|
while (WiFi.status() != WL_CONNECTED) {
|
|
delay(500);
|
|
Serial.print(".");
|
|
}
|
|
Serial.println("");
|
|
Serial.println(WiFi.localIP());
|
|
|
|
server.begin();
|
|
mySwitch.enableTransmit(2);
|
|
}
|
|
|
|
void loop() {
|
|
WiFiClient client = server.available();
|
|
if (!client) {
|
|
return;
|
|
}
|
|
|
|
Serial.println("client connection");
|
|
while (!client.available()) {
|
|
delay(1);
|
|
}
|
|
|
|
String req = client.readStringUntil('\r');
|
|
Serial.println(req);
|
|
|
|
client.flush();
|
|
|
|
String code_str = req.substring(5, 17);
|
|
Serial.println("Code: " + code_str);
|
|
|
|
mySwitch.sendTriState((char*)code_str.c_str());
|
|
delay(1000);
|
|
|
|
client.flush();
|
|
|
|
String s = "HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\n\r\n";
|
|
client.print(s);
|
|
client.print(code_str);
|
|
client.println("");
|
|
|
|
delay(1);
|
|
Serial.println("Client disonnected");
|
|
}
|