Webserver Ethernet Shield +SD

I am trying to get my arduino to host a simple webserver that will display a couple of analog values and also allow the client to check some radio buttons that will turn on some outputs as well as a text input box that i can read the value they entered.

The displaying stuff isn’t a problem but what im not sure about is how to retreive on the arduino the radio button they selected as well as a value they entered in a text box.

So far i have put this together for the form part of my HTML web server:




Temp Setpoint:

<!add temp setpoint to text field?>

Not sure if i need a submit button in order for the input to get sent to the webserver(arduino) or once they click a radio button or enter the text and say hit the enter key it will automatically send the get request. Anyway from what little info i can find on it you have to like parse the get command and find the information sent back to the server.

I was hoping maybe someone would know of an example where someone has already done something like this (not just buttons) so i could see how the coding is implemented in the arduino. Anyway any help, tutorials, examples, code, etc would be greatly appreciated.

Once i get this working i would like to save at least the static portions of the html code on the SD card instead of using arduino memory so any examples on that would be great as well.

Thanks ahead of time for any responses.


Some server code you can try.

//zoomkat 1-10-11
//routerbot 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 
//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(4, OUTPUT); //pin selected to control
  //start Ethernet
  Ethernet.begin(mac, ip, gateway, subnet);

  //enable serial data print 
  Serial.println("servertest1"); // 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 = client.read();

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

          //store characters to string 
          readString += c; 
          //Serial.print(c); //uncomment to see in serial monitor

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


          //now output HTML data header

          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");

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

          client.println("<H1>HTML form GET example</H1>");

          client.println("<FORM ACTION=\"\" method=get >");

          client.println("Pin 4 \"on\" or \"off\": <INPUT TYPE=TEXT NAME=\"LED\" VALUE=\"\" SIZE=\"25\" MAXLENGTH=\"50\">

          client.println("<INPUT TYPE=SUBMIT NAME=\"submit\" VALUE=\"Change Pin 4!\">");




          //stopping client

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


Big thanks to zoomkat, that was exactly what i was looking for. You rock!

I have another question i need to be able to convert a part of the string that is returned into a integer. For example the string that returns when i enter a value into the text box on the website looks like this:

GET /?status=off&setp=45 HTTP/1.1 Host: User-Agent: Mozilla/5.0 (Windows NT 5.1; r

I use readString.indexOf("setp") to see if a value is entered into the text box and now i need to take that value that was entered, in this case it was 45 and convert it to a integer that i can put in a variable. Something like this

int var var = (int)(readString[n] + readString[n+1]); //where the + is concat and n is the index of where the number 45 starts

obviously this doesn't work but i'm wording if there is a library in the string class (not from what i can tell) or something to easily accomplish this.

I just answered my own question, for some reason i didn't think this would work with the string class.

int var var = atoi(&readString[n]);

I think you can use something like below.

      // expect a string like 07002100 containing the two servo positions      
      servo1 = readString.substring(0, 4); //get the first four characters
      servo2 = readString.substring(4, 8); //get the next four characters 
      Serial.println(servo1);  //print to serial monitor to see results
      int n1 = servo1.toInt();
      int n2 = servo2.toInt();

kindly upload your arduino and HTML code.