initial import
This commit is contained in:
60
esp8266/433/esp8266_433/esp8266_433.ino
Normal file
60
esp8266/433/esp8266_433/esp8266_433.ino
Normal file
@ -0,0 +1,60 @@
|
||||
#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());
|
||||
|
||||
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");
|
||||
}
|
Reference in New Issue
Block a user