#include const char* ssid = "HTMAA"; const char* password = "your_password"; WiFiServer server(80); String header; String output2State = "off"; const int output2 = 2; unsigned long currentTime = millis(); unsigned long previousTime = 0; const long timeoutTime = 2000; void setup() { Serial.begin(9600); pinMode(output2, OUTPUT); digitalWrite(output2, LOW); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("="); } Serial.println("IP address: "); Serial.println(WiFi.localIP()); server.begin(); } void loop() { WiFiClient client = server.available(); if (client) { String currentLine = ""; currentTime = millis(); previousTime = currentTime; while (client.connected() && currentTime - previousTime <= timeoutTime) { currentTime = millis(); if (client.available()) { char c = client.read(); Serial.write(c); header += c; if (c == '\n') { if (currentLine.length() == 0) { client.println("HTTP/1.1 200 OK"); client.println("Content-type:text/html"); client.println("Connection: close"); client.println(); if (header.indexOf("GET /2/on") >= 0) { Serial.println("GPIO 2 on"); output2State = "on"; digitalWrite(output2, HIGH); } else if (header.indexOf("GET /2/off") >= 0) { Serial.println("GPIO 2 off"); output2State = "off"; digitalWrite(output2, LOW); } client.println(""); client.println(""); client.println(""); client.println(""); client.println("

CZhu HTMAA Web Server Test

"); client.println("

Output is " + output2State + "

"); if (output2State == "off") { client.println("

"); } else { client.println("

"); } client.println(""); client.println(); break; } else { currentLine = ""; } } else if (c != '\r') { currentLine += c; } } } header = ""; client.stop(); Serial.println("Client disconnected."); Serial.println(""); } }