Simple Web Server with Get String Parsing.

I wrote this a while back when I could not find anything that worked the way that I wanted it to. I should have posted it sooner but it couldn’t find the time.

Let me know if you have any questions, Its not the most elegant code, but it works and is a good place to start.

(see attached file)

webserver.pde (27.2 KB)

Would it be possible to get more comments on the code, im looking into using an ethernet shield equipped arduino as a webserver but havnt got a clue as to what your code is doing. A rundown of what is going on would be brilliant.

Some server test code I use to control two servos via a web page. With the serial monitor open, you can see what is being received by the server and how the get request is being parced.

//zoomkat 10-22-10
//routerbot code
//for use with IDE 0021
//open serial monitor to see what the arduino receives
//use a url like below

#include <SPI.h>
#include <Ethernet.h>
#include <Servo.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
Server server(84); //server port

String readString, servo1, servo2; 

Servo myservo1;  // create servo object to control a servo 
Servo myservo2;

void setup(){

  //start Ethernet
  Ethernet.begin(mac, ip, gateway, subnet);

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

void loop(){
  // Create a client connection
  Client 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') {


          //readString looks like "GET /?-1500-1500 HTTP/1.1"

          if (readString.length() >0) {

            servo1 = readString.substring(7, 11);
            servo2 = readString.substring(12, 16);


            int n1;
            int n2;

            char carray1[6];
            servo1.toCharArray(carray1, sizeof(carray1));
            n1 = atoi(carray1); 

            char carray2[6];
            servo2.toCharArray(carray2, sizeof(carray2));
            n2 = atoi(carray2); 



          //now output HTML data header
          client.println("HTTP/1.1 204 Zoomkat");
          //stopping client

          //clearing string for next read