title: Android to Arduino Uno + Wi-Fi shield string communication
body: <p>I am trying to make a wireless light control device (on/off/dimming) using an Arduino, an Android app, and a router.</p>
  
  <p>I am setting the Arduino to a static IP 192.168.1.2 using the router. I am sending strings ("1"-off, "2"-decrease brightness, "3"-increase brightness, "4"-on) from the Android app to the IP address 192.168.1.2. I have connected the Arduino to the Internet using the <a href="http://arduino.cc/en/Main/ArduinoWiFiShield" rel="nofollow">Arduino Wi-Fi shield</a> and set up the WifiServer using the following code:</p>
  
  <pre class="lang-cpp prettyprint-override"><code>char ssid[] = "NAME"; // Your network SSID (name)
  char pass[] = "PASS"; // Your network password (use for WPA, or use as key for WEP)
  
  int keyIndex = 0;     // Your network key Index number (needed only for WEP)
  
  int status = WL_IDLE_STATUS;
  
  WiFiServer server(23);
  
  boolean alreadyConnected = false; // Whether or not the client was connected previously.
  
  void setup() {
      // Start serial port:
      Serial.begin(9600);
  
      // Attempt to connect to Wi-Fi network:
      while ( status != WL_CONNECTED) {
          Serial.print("Attempting to connect to SSID: ");
          Serial.println(ssid);
          status = WiFi.begin(ssid, pass);
          // Wait 10 seconds for connection:
          delay(10000);
      }
      // Start the server:
      server.begin();
      // You're connected now, so print out the status:
      printWifiStatus();
   }
  </code></pre>
  
  <p>The main problem I am having is how to accept and print out the strings from the Android device. The current code I have to do this is:</p>
  
  <pre class="lang-cpp prettyprint-override"><code>    // Listen for incoming clients
      WiFiClient client = server.available();
      if (client) {
          // An HTTP request ends with a blank line
          boolean newLine = true;
          String line = "";
  
          while (client.connected() &amp;&amp; client.available()) {
              char c = client.read();
              Serial.print(c);
  
              // If you've gotten to the end of the line (received a newline
              // character) and the line is blank, the HTTP request has ended,
              // so you can send a reply.
              if (c == '\n' &amp;&amp; newLine) {
                  // Send a standard HTTP response header
                  //client.println("HTTP/1.1 200 OK");
                  //client.println("Content-Type: text/html");
                  //client.println();
              }
              if (c == '\n') {
                  // You're starting a new line
                  newLine = true;
                  Serial.println(line);
                  line = "";
              }
              else if (c != '\r') {
                // You've gotten a character on the current line
                newLine = false;
                line += c;
              }
          }
          Serial.println(line);
  
          // Give the web browser time to receive the data
          delay(1);
  
          // Close the connection:
          //client.stop();
      }
  }
  </code></pre>
  
  <p>I am basing this code off of the blog post <em><a href="http://blog.rogiervandenberg.nl/2013/03/android-arduino-switch-with-tinywebdb.html" rel="nofollow">Android Arduino Switch with a TinyWebDB hack</a></em>, but this code is for an Ethernet shield. The Android app was made using the <a href="http://en.wikipedia.org/wiki/App_Inventor_for_Android" rel="nofollow">MIT App Inventor</a>, which is similar to the one found the blog post.</p>
  
  <p><a href="http://en.wiktionary.org/wiki/TLDR" rel="nofollow">TLDR</a>, how can I get the strings using the Arduino Wi-Fi shield?</p>