/* WiFi Web Server Change the macro WIFI_AP, WIFI_PASSWORD and WIFI_AUTH to your own router settings. */ #include #include #include #include #define WIFI_AP "TELUS0673" #define WIFI_PASSWORD "b48f690c43" #define WIFI_AUTH LWIFI_WPA // choose from LWIFI_OPEN, LWIFI_WPA, or LWIFI_WEP according to your WiFi AP configuration //I would try LWIFI_WPA first //if that fails LWIFI_WEP //if that fails LWIFI_OPEN (and find out why you are giving WiFi to the neighbours!) int serverPort = 80; LWiFiServer server(serverPort); int LED = 13; #define wheel 9 #define wheel1 3 void setup() { pinMode(wheel, OUTPUT); pinMode(wheel1, OUTPUT); pinMode(LED, OUTPUT); LWiFi.begin(); //Serial.begin(115200); // keep retrying until connected to AP //Serial.println("Connecting to AP"); while (0 == LWiFi.connect(WIFI_AP, LWiFiLoginInfo(WIFI_AUTH, WIFI_PASSWORD))) { digitalWrite(LED, HIGH); delay(100); digitalWrite(LED, LOW); delay(100); digitalWrite(LED, HIGH); delay(100); digitalWrite(LED, LOW); delay(600); } digitalWrite(LED, HIGH); printWifiStatus(); //Serial.println("Start Server"); server.begin(); //Serial.println("Server Started"); digitalWrite(LED, LOW); } int loopCount = 0; void loop() { // put your main code here, to run repeatedly: String str = ""; String url = ""; int i; delay(500); loopCount++; LWiFiClient client = server.available(); if (client) { //Serial.println("new client"); // an http request ends with a blank line boolean currentLineIsBlank = true; while (client.connected()) { if (client.available()) { // we basically ignores client request, but wait for HTTP request end char c = client.read(); //Serial.print(c); if(c != '\n') str += c; if(c == '\n') { ////Serial.println(str); if(str.startsWith("GET ")) { url = str.substring(4, str.lastIndexOf(" ")); //Serial.print("URL:"); //Serial.print(url); //Serial.println(":"); } str = ""; } if (c == '\n' && currentLineIsBlank) { //Serial.println("send response"); // send a standard http response header client.println("HTTP/1.1 200 OK"); client.println("Content-Type: text/html"); client.println("Connection: close"); // the connection will be closed after completion of the response client.println(); if(url != String("favicon.ico")) { client.println(""); client.println("\n\nRover Control\n"); IPAddress ip = LWiFi.localIP(); client.println("
"); client.println("
What do you want your robot to do?

Forward.
Turn left.
Turn right.

"); //i = digitalRead(LED); url.toLowerCase(); if(url == String("/?q=forward")) { digitalWrite(wheel, HIGH); digitalWrite(wheel1, HIGH); delay(2500); digitalWrite(wheel, LOW); digitalWrite(wheel1, LOW); } else if(url == String("/?q=left")) { digitalWrite(wheel1, LOW); digitalWrite(wheel, HIGH); delay(1500); digitalWrite(wheel, LOW); } else if(url == String("/?q=right")) { digitalWrite(wheel, LOW); digitalWrite(wheel1, HIGH); delay(1500); digitalWrite(wheel1, LOW); } else { client.println("Doing nothing
"); } client.println("
\n"); client.println(); break; } } if (c == '\n') { // you're starting a new line currentLineIsBlank = true; } else if (c != '\r') { // you've gotten a character on the current line currentLineIsBlank = false; } } } // give the web browser time to receive the data delay(50); // close the connection: //Serial.println("close connection"); client.stop(); //Serial.println("client disconnected"); } } 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"); }