#include #include #include // name and password from WiFi network const char* ssid = "Your access point (router) name"; const char* password = "router password"; IPAddress ip(192,168,1,112); // enter static ip IPAddress gateway(192,168,1,1); IPAddress subnet(255,255,255,0); // server port 80 WiFiServer server(80); void setup() { Serial.begin(115200); delay(100); //preparing GPIO pinMode(12, OUTPUT); digitalWrite(12, 1); pinMode(13, OUTPUT); digitalWrite(13, 1); // connecting to WiFi Serial.println(); Serial.println(); Serial.print("Connecting to "); Serial.println(ssid); WiFi.begin(ssid, password); WiFi.config(ip, gateway, subnet); // waiting for connection while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println(""); Serial.println("WiFi connected"); // run server server.begin(); Serial.println("Server started"); // show ip Serial.println(WiFi.localIP()); } void loop() { // connection check WiFiClient client = server.available(); if (!client) { return; } // Waiting for data Serial.println("new client"); while (!client.available()) { delay(1); } // Reading the first line of the query String req = client.readStringUntil('\r'); Serial.println(req); client.flush(); // works with GPIO if (req.indexOf("/12/0") != -1) digitalWrite(12, 0); else if (req.indexOf("/12/1") != -1){ digitalWrite(12, 1); Serial.println("TEST OK"); String s = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n\r\n\r\nTest OK. Uptime: "; // UpTime int Sec = (millis() / 1000UL) % 60; int Min = ((millis() / 1000UL) / 60UL) % 60; int Hours = ((millis() / 1000UL) / 3600UL) % 24; int Day = ((millis() / 1000UL) / 3600UL / 24UL); s += Day; s += "d "; s += Hours; s += ":"; s += Min; s += ":"; s += Sec; s += "\n"; client.print(s); client.stop(); return; } else // If an invalid query write error { Serial.println("invalid request"); String s = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n\r\n\r\nInvalid request"; s += "\n"; client.print(s); client.stop(); return; } client.flush(); // Response formation String s = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n\r\n\r\nGPIO set OK"; s += "\n"; // Send the response to the client client.print(s); delay(1); Serial.println("Client disonnected"); }