Problem using Ethernet shield

Have found in the forum an example of a webpage on an Arduino displaying four
pushbuttons , that I have modified a little , and it works fine . But then I wanted
to include a potentiometer reading in the scetch and had it´s value displayed (ReadValue)
on that web-page , but not succeeded ...have tried to find a solution among
other examples ... but no luck ...

here is the code :

/*  Circuit:
 * Ethernet shield attached to pins 10, 11, 12, 13

  Potentiometer to A0

*/

#include <EtherCard.h>

// Ethernet Part declaration
static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 };
#define BUFFER_SIZE 800
BufferFiller bfill;
byte Ethernet::buffer[BUFFER_SIZE];
static byte myip[] = {192,168,0,2};

// Ethernet Part ends here

// Diodepins definition

const int ledPin1 = 3;
const int ledPin2 = 4;
const int ledPin3 = 5;

//Volt meter start
//Analog volt read pin
const int voltPin = 0;
float Readvalue;



void setup () {
 /*    sök efter ip-adress till Arduinon    */
 
  Serial.begin(9600);
   Serial.println("\n[Starting the Arduino Server]");

  Serial.print("MAC: ");
  for (byte i = 0; i < 6; ++i) {
    Serial.print(mymac[i], HEX);
    if (i < 5)
      Serial.print(':');
  }
  Serial.println();
  
  if (ether.begin(sizeof Ethernet::buffer, mymac) == 0) 
    Serial.println( "Failed to access Ethernet controller");

  Serial.println("Setting up DHCP (this can take a while...)");
  if (!ether.dhcpSetup())
    Serial.println( "DHCP failed");
  
  ether.printIp("IP: ", ether.myip);
  ether.printIp("Netmask: ", ether.mymask);
  ether.printIp("GW IP: ", ether.gwip);
  ether.printIp("DNS IP: ", ether.dnsip);
  ether.printIp("Surf to this IP to view the Arduino Server: ", ether.myip);


 myip ==ether.myip;
 
 
 /*    initierad ...*/
 
 
 
//Ethernet Debugging
 
ether.begin(sizeof Ethernet::buffer, mymac);

ether.staticSetup(myip);

//Ethernet Debugging Ends Here



// Turn off all diodes

  pinMode(ledPin1, OUTPUT);
  digitalWrite(ledPin1, LOW);
  pinMode(ledPin2, OUTPUT);
  digitalWrite(ledPin3, LOW);
  pinMode(ledPin3, OUTPUT);
  digitalWrite(ledPin3, LOW);
}


void homepage(){
      bfill.emit_p(PSTR(
"<!DOCTYPE html><html><title>Ethernet Controller</title>"
"<body><div id='content' style='background-color:lightgreen;width:1100px;height:900px;'><hr><h1><p><center><font size='28'>
Kalles Arduino-website 
test
"
"</p><hr>
<table bgcolor='#58D3F7' border='1'><tr><th colspan='4' >Choose diode :</th></tr>"
"<tr><td><INPUT Type='BUTTON' VALUE='Red ' ONCLICK='window.location.href=\"/?cmd=Red\"'></td><td>"
"<INPUT Type='BUTTON' VALUE='Yellow' ONCLICK='window.location.href=\"/?cmd=Yellow\"'></td>"
"<td><INPUT Type='BUTTON' VALUE='Green' ONCLICK='window.location.href=\"/?cmd=Green\"'></td>"
"<td><INPUT Type='BUTTON' VALUE='Off' ONCLICK='window.location.href=\"/?cmd=Off\"'></td></tr>"
"</table>
<hr>xxx</font>
<hr></div></body></html>"
   ));
}
void http_Unauthorized(){
      bfill.emit_p(PSTR("HTTP/1.0 401 Unauthorized\r\n"
    "Content-Type: text/html\r\n\r\n"
    "<h1>401 Unauthorized</h1>"   
      ));
}

void loop() {
  //checking for requesting client
  word len = ether.packetReceive();
  word pos = ether.packetLoop(len);
 

 
  if(pos) {
    bfill = ether.tcpOffset();
   
    //storing buffer on data variable
    char *data = (char *) Ethernet::buffer + pos;
   
    if (strncmp("GET /", data, 5) != 0) {
            // Unsupported HTTP request
            // 304 or 501 response would be more appropriate
             http_Unauthorized();
        }
    else {
        data += 5;
           
            if (data[0] == ' ') {
                // Return home page
                homepage();
            }
            else if (strncmp("?cmd=Red ", data, 8) == 0) {
                homepage();
               
               digitalWrite(ledPin1, HIGH);      // Red diode on
                digitalWrite(ledPin2, LOW);
                 digitalWrite(ledPin3, LOW);


            }
            else if (strncmp("?cmd=Yellow ", data, 11) == 0) {
              homepage();
              
                digitalWrite(ledPin1, LOW);
                  digitalWrite(ledPin2, HIGH);    // Yellow diode on
                 digitalWrite(ledPin3, LOW);
            }
            else if (strncmp("?cmd=Green ", data, 10) == 0) {
                homepage();
               
                 digitalWrite(ledPin1, LOW);
                  digitalWrite(ledPin2, LOW);
                 digitalWrite(ledPin3, HIGH);     // Green diode on
              
            }
            else if (strncmp("?cmd=Off ", data, 8) == 0) {
                homepage();
               
                 digitalWrite(ledPin1, LOW);       // All off
                  digitalWrite(ledPin2, LOW);
                 digitalWrite(ledPin3, LOW);
            
            }
            else {
                // Page not found
                http_Unauthorized();
            }
            delay(1000);
        }
        Readvalue=VoltageMeasure();
        
    ether.httpServerReply(bfill.position());
    len ==0;
  }
}

float VoltageMeasure()

{
  float voltage;
  //volt meter start

//Obtain RAW voltage data
voltage = analogRead(voltPin);
//Convert to actual voltage (0 - 5 Vdc)
voltage = (voltage / 1024) * 5.0;
return voltage;
}

Webpage_med_inmatning_av_data.ino (4.76 KB)

If you want a value to appear on the HTML page you should add it to the HTML text in homepage().

One way to get the arduino analog pin inputs into a web page using frames.

// zoomkat's meta refresh data frame test page 5/25/13
// use http://192.168.1.102:84 in your brouser for main page
// http://192.168.1.102:84/data static data page
// http://192.168.1.102:84/datastart meta refresh data page
// for use with W5100 based ethernet shields
// set the refresh rate to 0 for fastest update
// use STOP for single data updates

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

const int analogInPin0 = A0;
const int analogInPin1 = A1;
const int analogInPin2 = A2;
const int analogInPin3 = A3;
const int analogInPin4 = A4;
const int analogInPin5 = A5;

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = { 192, 168, 1, 102 }; // arduino 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
unsigned long int x=0; //set refresh counter to 0
String readString; 

//////////////////////

void setup(){
  Serial.begin(9600);
    // disable SD SPI if memory card in the uSD slot
  pinMode(4,OUTPUT);
  digitalWrite(4,HIGH);

  Ethernet.begin(mac, ip, gateway, gateway, subnet);
  server.begin();
  Serial.println("meta refresh data frame test 5/25/13"); // so I can keep track of what is loaded
}

void loop(){
  EthernetClient client = server.available();
  if (client) {
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
         if (readString.length() < 100) {
          readString += c; 
         } 
        //check if HTTP request has ended
        if (c == '\n') {

          //check get atring received
          Serial.println(readString);

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

          //generate data page
          if(readString.indexOf("data") >0) {  //checks for "data" page
            x=x+1; //page upload counter
            client.print("<HTML><HEAD>");
            //meta-refresh page every 1 seconds if "datastart" page
            if(readString.indexOf("datastart") >0) client.print("<meta http-equiv='refresh' content='1'>"); 
            //meta-refresh 0 for fast data
            if(readString.indexOf("datafast") >0) client.print("<meta http-equiv='refresh' content='0'>"); 
            client.print("<title>Zoomkat's meta-refresh test</title></head><BODY>
");
            client.print("page refresh number: ");
            client.print(x); //current refresh count
            client.print("

");
            
              //output the value of each analog input pin
            client.print("analog input0 is: ");
            client.print(analogRead(analogInPin0));
            
            client.print("
analog input1 is: ");
            client.print(analogRead(analogInPin1));
                        
            client.print("
analog input2 is: ");
            client.print(analogRead(analogInPin2));
            
            client.print("
analog input3 is: ");
            client.print(analogRead(analogInPin3));
                                    
            client.print("
analog input4 is: ");
            client.print(analogRead(analogInPin4));
            
            client.print("
analog input5 is: ");
            client.print(analogRead(analogInPin5));
            client.println("
</BODY></HTML>");
           }
          //generate main page with iframe
          else
          {
            client.print("<HTML><HEAD><TITLE>Zoomkat's frame refresh test</TITLE></HEAD>");
            client.print("Zoomkat's Arduino frame meta refresh test 5/25/13");
            client.print("

Arduino analog input data frame:
");
            client.print("&nbsp;&nbsp;<a href='http://192.168.1.102:84/datastart' target='DataBox' title=''yy''>META-REFRESH</a>");
            client.print("&nbsp;&nbsp;&nbsp;&nbsp;<a href='http://192.168.1.102:84/data' target='DataBox' title=''xx''>SINGLE-STOP</a>");
            client.print("&nbsp;&nbsp;&nbsp;&nbsp;<a href='http://192.168.1.102:84/datafast' target='DataBox' title=''zz''>FAST-DATA</a>
");
            client.print("<iframe src='http://192.168.1.102:84/data' width='350' height='250' name='DataBox'>");
            client.print("</iframe>
</HTML>");
          }
          delay(1);
          //stopping client
          client.stop();
          //clearing string for next read
          readString="";
        }
      }
    }
  }
}

OK thanks ... but for the first answer : Yes I have tried to include in the Homepage() HTML...
but never succeeded..

As for the second answer , it works for an W5100 shield , but I forgot to tell I have a compatible ...

KalleL:
Yes I have tried to include in the Homepage() HTML...
but never succeeded..

I guess it is time to try it again. If you show your code and report your results we might be able to guide you in the correct direction.