├── Data └── animation.gif ├── README.md └── wifirelay.ino /Data/animation.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/miladsec/esp8266-wifi-relay/13ccc55879ad9a66d59d268372874a7515544b5f/Data/animation.gif -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 |

let's build something together

3 |

4 | 5 |

6 | 7 | ### :tada: You get: 8 | 9 | ![reault](https://github.com/ZAM1R/ESP8266WifiRelay/blob/main/Data/animation.gif) 10 | 11 | ## 12 | ### :pushpin: Requirements: 13 | - [arduino IDE](https://www.arduino.cc/en/software) 14 | - [bread board](https://thecaferobot.com/store/bread-board-10-55-165mm) 15 | - [NodeMcu8266 cp2102](https://thecaferobot.com/store/nodemcu-lua-esp8266-wifi-internet-development-board) 16 | - [1Chanel 5v relay](https://thecaferobot.com/store/1chanel-5v-relay) 17 | - [Female female 20cm jumper wire](https://thecaferobot.com/store/female-female-40p-21cm) 18 | - [Male male 20cm jumper wire](https://thecaferobot.com/store/male-male-40p-21cm) 19 | - [Ac dc 9v 1a power supply](https://thecaferobot.com/store/ac-dc-9v-1a-power-supply) 20 | - [Usb to micro usb cable](https://thecaferobot.com/store/usb-to-micro-usb-data-charging-cable-blue) 21 | 22 | ## 23 | ### :wrench: Configuration: 24 | 1. Set Wifi ssid And password 25 | 2. Set relay pin (Default: D5) 26 | 3. Set server port (Default: 85) 27 | 4. Set 192.168.1.85 IP with 85 in/ex port to modem (Port Forwarding) 28 | 29 | ## 30 | ### :camera_flash: Tutorial video: 31 | [link](https://github.com/miladsec/ESP8266WifiRelay) **(coming soon)** 32 | 33 | ## 34 | ### ContactUs: 35 | miladsec 36 | -------------------------------------------------------------------------------- /wifirelay.ino: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | const char* ssid = "ca"; 4 | const char* password = "1234567899"; 5 | 6 | IPAddress ip(192, 168, 1, 85); 7 | IPAddress gateway(192, 168, 1, 1); 8 | IPAddress subnet(255, 255, 255, 0); 9 | 10 | int relayPin = D5; 11 | WiFiServer server(85); 12 | 13 | void setup() { 14 | Serial.begin(9600); 15 | delay(10); 16 | 17 | 18 | pinMode(relayPin, OUTPUT); 19 | digitalWrite(relayPin, HIGH); 20 | 21 | // Connect to WiFi network 22 | Serial.println(); 23 | Serial.println(); 24 | Serial.print("Connecting to "); 25 | Serial.println(ssid); 26 | 27 | // Configures static IP address 28 | WiFi.config(ip, gateway, subnet); 29 | 30 | WiFi.begin(ssid, password); 31 | 32 | while (WiFi.status() != WL_CONNECTED) { 33 | delay(500); 34 | Serial.print("."); 35 | } 36 | Serial.println(""); 37 | Serial.println("WiFi connected"); 38 | 39 | // Start the server 40 | server.begin(); 41 | Serial.println("Server started"); 42 | 43 | // Print the IP address 44 | Serial.print("Use this URL : "); 45 | Serial.print("http://"); 46 | Serial.print(WiFi.localIP()); 47 | Serial.println("/"); 48 | 49 | 50 | WiFi.softAP("HACK ME!!!", ")*#)*$&#@)*(%U)#@U(*HIHG"); 51 | } 52 | 53 | void loop() { 54 | // Check if a client has connected 55 | WiFiClient client = server.available(); 56 | if (!client) { 57 | return; 58 | } 59 | 60 | // Wait until the client sends some data 61 | Serial.println("new client"); 62 | 63 | unsigned long timeout = millis(); 64 | while(!client.available()){ 65 | if (millis() - timeout > 10) { 66 | Serial.println(">>> Client Timeout !"); 67 | client.stop(); 68 | return; 69 | } 70 | delay(1); 71 | } 72 | 73 | // Read the first line of the request 74 | String request = client.readStringUntil('\r'); 75 | Serial.println(request); 76 | client.flush(); 77 | 78 | // Match the request 79 | if (request.indexOf("/open") != -1) { 80 | digitalWrite(relayPin, LOW); 81 | delay(500); 82 | digitalWrite(relayPin, HIGH); 83 | } 84 | 85 | 86 | // Return the response 87 | client.println("HTTP/1.1 200 OK"); 88 | client.println("Content-Type: text/html"); 89 | client.println(""); // do not forget this one 90 | client.println(""); 91 | client.println(""); 92 | client.println(""); 93 | client.println(""); 94 | client.println(""); 95 | client.println(""); 96 | client.println("FBI open up!"); 97 | client.println(""); 98 | client.println(""); 99 | client.println("
"); 100 | client.println("

درب باز کن هوشمند

"); 101 | client.println("
"); 102 | client.println("
باز کردن درب
"); 103 | client.println("
"); 104 | client.println(""); 105 | 106 | delay(1); 107 | Serial.println("Client disconnected"); 108 | Serial.println(""); 109 | 110 | } 111 | --------------------------------------------------------------------------------