/********* 6 устройств 16 05 04 14 12 13 D0 D1 D2 D5 D6 D7 *********/ // Load Wi-Fi library #include // Поменяйте на свои значения const char* ssid = "ABC"; const char* password = "xyz"; // Порт вашего вебсервера, пример, 80 WiFiServer server(80); // Переменная для хранения HTTP запроса String header; // Вспомогательные переменные для хранения текущего состояния вывода String output4State = "off"; String output5State = "off"; String output16State = "off"; String output14State = "off"; String output12State = "off"; String output13State = "off"; // Назначьте выходные переменные на контакты GPIO const int output4 = 4; const int output5 = 5; const int output16 = 16; const int output14 = 14; const int output12 = 12; const int output13 = 13; void setup() { Serial.begin(115200); // Инициализируйте выходные переменные как выходы pinMode(output4, OUTPUT); pinMode(output5, OUTPUT); pinMode(output16, OUTPUT); pinMode(output14, OUTPUT); pinMode(output13, OUTPUT); pinMode(output12, OUTPUT); // Установите выходы на HIGH digitalWrite(output4, HIGH); digitalWrite(output5, HIGH); digitalWrite(output16, HIGH); digitalWrite(output14, HIGH); digitalWrite(output13, HIGH); digitalWrite(output12, HIGH); // Подключитесь к сети Wi-Fi с помощью SSID и пароля Serial.print("Connecting to "); Serial.println(ssid); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(1000); Serial.print("."); } // Вывести локальный IP-адрес и запустить веб-сервер Serial.println(""); Serial.println("WiFi connected."); Serial.println("IP address: "); Serial.println(WiFi.localIP()); server.begin(); } void loop() { WiFiClient client = server.available(); // Listen for incoming clients if (client) { // If a new client connects, Serial.println("New Client."); // print a message out in the serial port String currentLine = ""; // make a String to hold incoming data from the client while (client.connected()) { // loop while the client's connected if (client.available()) { char c = client.read(); Serial.write(c); header += c; if (c == '\n') { // if the byte is a newline character // if the current line is blank, you got two newline characters in a row. // that's the end of the client HTTP request, so send a response: if (currentLine.length() == 0) { // HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK) // and a content-type so the client knows what's coming, then a blank line: client.println("HTTP/1.1 200 OK"); client.println("Content-type:text/html"); client.println("Connection: close"); client.println(); // turns the GPIOs on and off if (header.indexOf("GET /4/on") >= 0) { Serial.println("GPIO 4 on"); output4State = "on"; digitalWrite(output4, LOW); } else if (header.indexOf("GET /4/off") >= 0) { Serial.println("GPIO 4 off"); output4State = "off"; digitalWrite(output4, HIGH); } else if (header.indexOf("GET /5/on") >= 0) { Serial.println("GPIO 5 on"); output5State = "on"; digitalWrite(output5, LOW); } else if (header.indexOf("GET /5/off") >= 0) { Serial.println("GPIO 5 off"); output5State = "off"; digitalWrite(output5, HIGH); } else if (header.indexOf("GET /12/on") >= 0) { Serial.println("GPIO 12 on"); output12State = "on"; digitalWrite(output12, LOW); } else if (header.indexOf("GET /12/off") >= 0) { Serial.println("GPIO 12 off"); output12State = "off"; digitalWrite(output12, HIGH); } else if (header.indexOf("GET /13/on") >= 0) { Serial.println("GPIO 13 on"); output13State = "on"; digitalWrite(output13, LOW); } else if (header.indexOf("GET /13/off") >= 0) { Serial.println("GPIO 13 off"); output13State = "off"; digitalWrite(output13, HIGH); } else if (header.indexOf("GET /14/on") >= 0) { Serial.println("GPIO 14 on"); output14State = "on"; digitalWrite(output14, LOW); } else if (header.indexOf("GET /14/off") >= 0) { Serial.println("GPIO 14 off"); output14State = "off"; digitalWrite(output14, HIGH); } else if (header.indexOf("GET /16/on") >= 0) { Serial.println("GPIO 16 on"); output16State = "on"; digitalWrite(output16, LOW); } else if (header.indexOf("GET /16/off") >= 0) { Serial.println("GPIO 16 off"); output16State = "off"; digitalWrite(output16, HIGH); } // Display the HTML web page client.println(""); client.println(""); client.println(""); // Web Page Heading client.println("

Smart Home DL1

"); // Display current state for GPIO client.println("

GPIO 4 - State " + output4State + "

"); client.println("

GPIO 5 - State " + output5State + "

"); client.println("

GPIO 12 - State " + output12State + "

"); client.println("

GPIO 13 - State " + output13State + "

"); client.println("

GPIO 14 - State " + output14State + "

"); client.println("

GPIO 16 - State " + output16State + "

"); client.println("

Please visit www.bandardalat.com for more projects.

"); client.println(""); // The HTTP response ends with another blank line client.println(); // Break out of the while loop break; } else { // if you got a newline, then clear currentLine currentLine = ""; } } else if (c != '\r') { // if you got anything else but a carriage return character, currentLine += c; // add it to the end of the currentLine } } } // Clear the header variable header = ""; // Close the connection client.stop(); Serial.println("Client disconnected."); Serial.println(""); } }