#include const char* ssid = "yourWiFiSSID"; const char* password = "yourpassword"; const char* host = "192.168.2.1"; const char *connect = ";CONNECT"; const char *disconnect = ";DISCONNECT"; // for Wemos D1 #if 0 #define OUTPUT_PIN (2) #define OUT_ON LOW #define OUT_OFF HIGH #else // for OBI Socket 2 #define OUTPUT_PIN (4) #define OUT_ON HIGH #define OUT_OFF LOW #endif void setup() { pinMode(OUTPUT_PIN, OUTPUT); // Initialize GPIO pin as an output Serial.begin(115200); Serial.println(); Serial.printf("Connecting to %s ", ssid); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println(" connected"); digitalWrite(OUTPUT_PIN, OUT_ON); // Turn the LED on delay(500); // Wait for 500 ms digitalWrite(OUTPUT_PIN, OUT_OFF); // Turn the LED off } void loop() { WiFiClient client; Serial.printf("\n[Connecting to %s ... ", host); if (client.connect(host, 1012)) { Serial.println("connected]"); /* Serial.println("[Sending a request]"); client.print(String("GET /") + " HTTP/1.1\r\n" + "Host: " + host + "\r\n" + "Connection: close\r\n" + "\r\n" ); Serial.println("[Response:]"); */ while (client.connected() || client.available()) { if (client.available()) { String line = client.readStringUntil('\n'); Serial.println(line); if( line.indexOf( connect ) > -1) { Serial.println("line busy]"); digitalWrite(OUTPUT_PIN, OUT_ON); // Turn the OUTPUT on } if( line.indexOf( disconnect ) > -1) { Serial.println("line free]"); digitalWrite(OUTPUT_PIN, OUT_OFF); // Turn the OUTPUT off } } } client.stop(); Serial.println("\n[Disconnected]"); } else { Serial.println("connection failed!]"); client.stop(); } delay(5000); }