//@CarmelitoA 24-Nov-2015 Wifi Blinds automation using LinkIt One //using LinkIt One(http://www.seeedstudio.com/depot/LinkIt-ONE-p-2017.html) and Micro Fitec continuous rotation servo (Tower Pro) #include #include #include #include #include #define WIFI_AP "XXXXXXXXX" //WiFi name - Please change to your Wifi Router name #define WIFI_PASSWORD "XXXXXXXXXXX" //WiFi password //Change to your Wifi Router password #define WIFI_AUTH LWIFI_WEP // choose from LWIFI_OPEN, LWIFI_WPA, or LWIFI_WEP according to your WiFi AP configuration //Important NOTE: change the value to how long it takes your blinds to open.Start with a SMALLER value like 2 seconds and then increase it const int blindOpenTime= 5000; //In my case it takes my blinds 5 seconds to open and 5 seconds to close. int semiOpenBlind = blindOpenTime/2; LWiFiServer server(80); String HTTP_req; String readString; Servo blindServo; void setup(){ LWiFi.begin(); //Serial.begin(115200); //comment out after debuing is complete using the Serial Monitor pinMode(13, OUTPUT); blindServo.attach(9); // keep retrying until connected to AP Serial.println("Connecting to AP"); LWiFi.connectWPA(WIFI_AP, WIFI_PASSWORD);//CJA using WPA connection per LinkIt One user guide printWifiStatus(); Serial.println("Start Server"); server.begin(); Serial.println("Server Started"); } void loop(){ delay(500); //Wifi Controller LWiFiClient client = server.available(); if (client) { while (client.connected()) { if (client.available()) { char c = client.read(); //read one by one char HTTP request if (readString.length() < 100) { //storing characters to string readString += c; } //if HTTP request has ended if (c == '\n') { //Serial.println(readString);//comment out for deployment of the project client.println("HTTP/1.1 200 OK"); //send new page client.println("Content-Type: text/html"); client.println("Connection: close"); client.println(); client.println(""); client.println(""); client.println(""); client.println("LinkIt ONE Blinds Automation"); client.println(""); client.println(""); client.println(""); client.println("

WiFi Blinds Automation

"); client.println("
"); client.println(""); client.println(""); client.println(""); client.println(""); client.println(""); client.println("
"); client.println("
"); client.println(""); client.println(""); delay(5); //stopping client client.stop(); if (readString.indexOf("?close") >0){ digitalWrite(13, HIGH); blindServo.write(110); delay(blindOpenTime); blindServo.write(90); delay(50); } else if (readString.indexOf("?open") >0){ digitalWrite(13, LOW); blindServo.write(40); delay(blindOpenTime); blindServo.write(90); delay(50); } else if (readString.indexOf("?semiopen") >0){ digitalWrite(13, LOW); blindServo.write(80); delay(semiOpenBlind); blindServo.write(90); delay(50); }else{ blindServo.write(90); delay(50); } //clearing string for next read readString=""; } } } } } void printWifiStatus() { // print the SSID of the network you're attached to: Serial.print("SSID: "); Serial.println(LWiFi.SSID()); // print your WiFi shield's IP address: IPAddress ip = LWiFi.localIP(); Serial.print("IP Address: "); Serial.println(ip); Serial.print("subnet mask: "); Serial.println(LWiFi.subnetMask()); Serial.print("gateway IP: "); Serial.println(LWiFi.gatewayIP()); // print the received signal strength: long rssi = LWiFi.RSSI(); Serial.print("signal strength (RSSI):"); Serial.print(rssi); Serial.println(" dBm"); }