/* WiFi Web Server A simple web server that a repeated counter Change the macro WIFI_AP, WIFI_PASSWORD and WIFI_AUTH accordingly. created 13 July 2010 by dlf (Metodo2 srl) modified 31 May 2012 by Tom Igoe modified 20 Aug 2014 by MediaTek Inc. mofified 23 Oct 2015 by @carmelitoA for the halloween skull Web App controller instructable */ #include #include #include #include #include int pos=0; int servoCounter =10; //change this value to make the head movement longer int led = 13; Servo headServo; int i=0; String readString; const int red = 7; const int green = 8; const int blue = 10; const int leftEye =12; const int rightEye = 13; #define WIFI_AP "XXXXXXX" //WiFi name #define WIFI_PASSWORD "XXXXXXX" //WiFi password #define WIFI_AUTH LWIFI_WEP // choose from LWIFI_OPEN, LWIFI_WPA, or LWIFI_WEP according to your WiFi AP configuration LWiFiServer server(80); String HTTP_req; // stores the HTTP request boolean LED_status = 0; // state of LED, off by default void setup() { LWiFi.begin(); //Serial.begin(115200); pinMode(led, OUTPUT); pinMode(red, OUTPUT); pinMode(green, OUTPUT); pinMode(blue, OUTPUT); pinMode(leftEye, OUTPUT); pinMode(rightEye, OUTPUT); digitalWrite(leftEye,HIGH); digitalWrite(rightEye,HIGH); headServo.attach(9); // keep retrying until connected to AP Serial.println("Connecting to AP"); //while (0 == LWiFi.connect(WIFI_AP, LWiFiLoginInfo(WIFI_AUTH, WIFI_PASSWORD))) /* while (0 == LWiFi.connectWEP(WIFI_AP, WIFI_PASSWORD)) { delay(1000); }*/ 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); digitalWrite(leftEye,HIGH); digitalWrite(rightEye,HIGH); 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(""); client.println(""); client.println("Skull Controller"); client.println(""); client.println(""); client.println("

Halloween Skull-ees Controller

"); client.println("
"); client.println("
"); client.println("

Controlling the RGB led

"); client.println("
"); client.println("Red"); client.println("Blue"); client.println("Green"); client.println("Turn Off LED
"); client.println("
"); client.println("
"); client.println("

Control Head Movement

"); client.println("
"); client.println("Move Head"); client.println("Stop Head
"); client.println("
"); client.println(""); client.println(""); delay(1); //stopping client client.stop(); //controls the RGB Led if (readString.indexOf("?ledred") >0){ digitalWrite(led, HIGH); colorRGBLED(HIGH,LOW,LOW);//RGB Red } if (readString.indexOf("?ledgreen") >0){ digitalWrite(led, LOW); colorRGBLED(LOW,HIGH,LOW);//RGB green } if (readString.indexOf("?ledblue") >0){ digitalWrite(led, LOW); colorRGBLED(LOW,LOW,HIGH);//RGB blue } if (readString.indexOf("?ledoff") >0){ digitalWrite(led, LOW); colorRGBLED(LOW,LOW,LOW);//RGB Led off } if (readString.indexOf("?servoon") >0){ for(i = 0; i < servoCounter; i += 1){ for(pos = 0; pos < 180; pos += 1){ headServo.write(pos); delay(15); } for(pos = 180; pos < 1; pos -= 1){ headServo.write(pos); delay(15); } } } if (readString.indexOf("?servooff") >0){ i=0; headServo.write(90); delay(100); } //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"); } void colorRGBLED(int redColor,int greenColor,int blueColor) { //controlling the RGB LED digitalWrite(red,redColor); digitalWrite(green,greenColor); digitalWrite(blue,blueColor); }