Receive String from Ethernet Shield/Server

Hello All, I have an Arduino Ethernet that is hooked up to a serial LCD screen from Spark Fun. The screen is a 20x4. I have the screen working with the Arduino already and can statically print strings on the screen. However, I want to send a packet to the Arduino via Ethernet that contains the strings to print on the screen. What is the best way to implement this? I was thinking the packet that I send to the Arduino will have a newline character to tell me when to break up the string into the next line and so on. I can't seem to wrap my head around how to do this. I can already setup the Ethernet server with no issue, I am mainly stuck on how to receive/parse the string. I know this much:

EthernetClient client = server.available();

if (client == true) {
  while (client.connected()){
    if (client.available() ) {
        parseString(client);  //Would a method call to handle this be right or should I parse it right here?  And how would I parse each line out assuming I use a newline to seperate?  Should I globally declare four strings to put each in?

Basic server code that captures what is sent from the client in the readString variable.

//zoomkat 12-8-11
//simple button GET with iframe code
//for use with IDE 1.0
//open serial monitor to see what the arduino receives
//use the \ slash to escape the " in the html (or use ')
//address will look like when submited
//for use with W5100 based ethernet shields

#include <SPI.h>
#include <Ethernet.h>

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = { 192, 168, 1, 102 }; // ip in lan
byte gateway[] = { 192, 168, 1, 1 }; // internet access via router
byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
EthernetServer server(84); //server port

String readString; 


void setup(){

  pinMode(5, OUTPUT); //pin selected to control
  //start Ethernet
  Ethernet.begin(mac, ip, gateway, gateway, subnet);

  //enable serial data print 
  Serial.println("server LED test 1.0"); // so I can keep track of what is loaded

void loop(){
  // Create a client connection
  EthernetClient client = server.available();
  if (client) {
    while (client.connected()) {
      if (client.available()) {
        char c =;

        //read char by char HTTP request
        if (readString.length() < 100) {

          //store characters to string 
          readString += c; 

        //if HTTP request has ended
        if (c == '\n') {

          Serial.println(readString); //print to serial monitor for debuging 

          //now output HTML data header
             if(readString.indexOf('?') >=0) { //don't send new page
               client.println("HTTP/1.1 204 Zoomkat");
             else {
          client.println("HTTP/1.1 200 OK"); //send new page
          client.println("Content-Type: text/html");

          client.println("<TITLE>Arduino GET test page</TITLE>");

          client.println("<H1>Zoomkat's simple Arduino button</H1>");
          client.println("<a href=\"/?on1\" target=\"inlineframe\">ON</a>"); 
          client.println("<a href=\"/?off\" target=\"inlineframe\">OFF</a>"); 

          //client.println("<IFRAME name=inlineframe src=\"res://D:/WINDOWS/dnserror.htm\" width=1 height=1\">");
          client.println("<IFRAME name=inlineframe style=\"display:none\" >");          


          //stopping client

          ///////////////////// control arduino pin
          if(readString.indexOf("on1") >0)//checks for on
            digitalWrite(5, HIGH);    // set pin 4 high
            Serial.println("Led On");
          if(readString.indexOf("off") >0)//checks for off
            digitalWrite(5, LOW);    // set pin 4 low
            Serial.println("Led Off");
          //clearing string for next read


What Zoomkat is saying is that if you get your Arduino ethernet to display a web page a user can enter data into the page (such as a data entry field) and press a submit button (or select a URL link) to send data back to your Arduino ethernet device.

For example when I enter a password into the login screen of my Arduino ethernet application at and press the Submit button this is the kind of data that is sent back to my Arduino:

User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Firefox/31.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-nz,th;q=0.5
Accept-Encoding: gzip, deflate
DNT: 1
Connection: keep-alive
Content-Type: application/x-www-form-urlencoded
Content-Length: 18

My system parses this information to extract the password (AVALUE%34 is not the real one) and then reports what it has determined from the above input and other sources as follows:

Socket #: 2
Dest Port: 49673
PAGE Password Login

Within my application the successful entry of a password causes the application to assign a session cookie which allows the user to remain logged in for ten minutes. This login status gives the user access to much more application functionality.

Once you have parsed and extracted your web page input data you can do whatever your application needs to do.

You don’t need to use a browser to send the above information to your Arduino. Any application that can generate the correct content and send it to your Arduino ethernet device on the correct port is able to upload data.


Catweazle NZ