Output variable values to HTML

Feeling a bit silly stumbling across something that is probably very easy ... but , being a newbie I guess no question is stupid ...
Anyhow , I have found in the forum a simple sample of a webpage with pushbuttons , and modified it a bit to light diodes.
That works fine , but now I´d like the Arduino to get a voltagereading from a potentiometer and display the result ( Readvalue) on this webpage ... have tried looking around for a solution ... but.. I am stuck ...

Here is the code :

/* Circuit:

  • Ethernet shield attached to pins 10, 11, 12, 13

stift 2... också ?

*/

#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*, 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(*
    "Ethernet Controller"
    "



    Kalles Arduino-website
    test
    "
    "



    "
    ""
    ""
    ""
    "
    Choose diode :
    "
    "


    xxx


    "

  • ));*
    }
    void http_Unauthorized(){

  • bfill.emit_p(PSTR("HTTP/1.0 401 Unauthorized\r\n"*

  • "Content-Type: text/html\r\n\r\n"*

  • "

    401 Unauthorized

    " *

  • ));*
    }
    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)

please modify your post
select the code and press the # button to get the code in a more readable format.
thank you

OK , like this ?

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

 stift 2... också ?

*/

#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)

did you look at this example?

also, print to serial port and make sure its working there before you print with client print.

Yes , I have tried that one ... as I have not an original shield
but a compatible one I have changed Ethernet.h to UIPEthernet.h...

but that does not help much ... the webserver comes online once
every ten tries... or so...

as I have not an original shield but a compatible one I have changed Ethernet.h to UIPEthernet.h...

What Ethernet chip does your shield use, a w5100 or another type?