#include #include #include #include RCSwitch mySwitch = RCSwitch(); // Replace with your network credentials const char *thessid = "your ssid here"; const char *thepassword = "your wifi password here"; // Update these with values suitable for your network. IPAddress theip(192, 168, 1, 10); //Node static IP IPAddress thegateway(192, 168, 1, 1); IPAddress thesubnet(255, 255, 255, 0); ESP8266WebServer server(80); String pinstate = "

-

"; int ONBOARDLED = 2; int RCSwitchPin = 4; int connrestart = 0; String webPage1 = "\n" "control\n" "\n" "\n" "
\n" "

control

\n"; String webPage2 = "\n" "

\n" "
\n" ""; void setup(void) { pinMode(ONBOARDLED, OUTPUT); byte ledStatus = HIGH; mySwitch.enableTransmit(RCSwitchPin); delay(1000); Serial.begin(115200); WiFi.mode(WIFI_STA); WiFi.config(theip, thegateway, thesubnet); WiFi.begin(thessid, thepassword); Serial.println(""); if (WiFi.status() != WL_CONNECTED) { connrestart = 0; } // Wait for connection while (WiFi.status() != WL_CONNECTED) { // Blink the LED digitalWrite(ONBOARDLED, ledStatus); // Write LED high/low ledStatus = (ledStatus == LOW) ? HIGH : LOW; delay(500); Serial.print("."); connrestart += 1; // if hasn't connected to WiFi for 30 seconds restart the ESP with a delay if (connrestart == 60) { delay(60000); ESP.restart(); } } if (WiFi.status() == WL_CONNECTED) { connrestart = 0; } digitalWrite(ONBOARDLED, HIGH); Serial.println(""); Serial.print("Connected to "); Serial.println(thessid); Serial.print("IP address: "); Serial.println(WiFi.localIP()); server.on("/", []() { server.send(200, "text/html", webPage1 + pinstate + webPage2); }); server.on("/submit", []() { String state = server.arg("formcommand"); if (state == "activateFAX") { digitalWrite(ONBOARDLED, LOW); // send switch ON 10 times for (int i = 0; i <= 9; i++) { mySwitch.setPulseLength(260); // this should be set according to your reading from RF receiver mySwitch.send("010101010101010101010101"); // sample raw data for 433MHz RF transmitter Serial.print("ON "); Serial.println(i); delay(200); } delay(5000); digitalWrite(ONBOARDLED, HIGH); // send switch OFF 10 times for (int i = 0; i <= 9; i++) { pinstate = "

switch activated

"; mySwitch.setPulseLength(260); // this should be set according to your reading from RF receiver mySwitch.send("010101010101010101010101"); // sample raw data for 433MHz RF transmitter Serial.print("OFF "); Serial.println(i); delay(200); } server.send(200, "text/html", webPage1 + pinstate + webPage2); } else if (state == "activate-other-RF-switch") { digitalWrite(ONBOARDLED, HIGH); // send switch command 10 times for (int i = 0; i <= 9; i++) { pinstate = "

sample switch 2

"; mySwitch.setPulseLength(260); // this should be set according to your reading from RF receiver mySwitch.send("010101010101010101010101"); // sample raw data for 433MHz RF transmitter Serial.print("ON "); Serial.println(i); delay(250); } delay(5000); server.send(200, "text/html", webPage1 + pinstate + webPage2); } else { pinstate = "

-

"; digitalWrite(ONBOARDLED, HIGH); delay(5000); server.send(200, "text/html", webPage1 + pinstate + webPage2); } }); server.begin(); Serial.println("HTTP server started"); } void loop(void) { server.handleClient(); }