HELP: i want to send a string via a web page HTML

Hello everybody,

i want to send a string via a web page HTML. I write my code, i know its wrong but if you have any ideas would be helpful.
thank you very much!!

#include <SPI.h>
#include <Client.h>
#include <Ethernet.h>
#include <Server.h>
#include <Udp.h>
#include <String/WString.h>

// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,1, 35); // ip del rango establecido en el router
char producto[24];
byte contador=0;

// Initialize the Ethernet server library
// with the IP address and port you want to use 
// (port 80 is default for HTTP):
EthernetServer server(80);

String readString = String(30);


void setup()
{
  // start the Ethernet connection and the server:
  Ethernet.begin(mac, ip);
  server.begin();
  Serial.begin(9600);

}

void loop()
{
  // listen for incoming clients
  EthernetClient client = server.available();
  if (client) {
    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        
        if (readString.length()<30) //leer peticion HTTP caracter por caracter
        {
           readString += c;
 
        }
        

        
        if (c=='\n') //Si la peticion HTTP ha finalizado
        {
           
          }
           
        }//while
        

          Serial.print(producto);
          readString=""; //Vaciar el string que se uso para la lectura
          //Enviar cabecera HTTP estandar

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

          //Crear pagina web HTML

          client.println("<html>");
          client.println("<head>");
          client.println("<title>Centro de control de productos</title>");
          client.println("</head>");
          client.println("<body>");
          client.println("<h1>Centro de control de productos</h1>");
          client.println("
<hr>
");
          client.println("<b>Nombre del Producto");
          client.println("
<form method=get enctype=text/plain> <input type=text name=nombreproducto size=25 maxlength=50>

");
          client.println("<hr><input type=submit name=Aceptar value=Introducir><input type=Reset name=Cancelar value=Cancelar></form>");
          
 
          
          
          client.println("<hr>
");
          client.println("</body>");
          client.println("</html>");

          client.stop();
        }
      }
}

alozamonto:
i know its wrong

What problem are you asking for help with?

i know its wrong

Why don't you fix it, then?

Or explain what the code does that you don't want, or doesn't do that you want.

String readString = String(30);

String readString = "30";
would do the same thing. How is that initial value useful?

I want to keep the variable "nombreproducto" . This variable is entered through the website HTML

  client.println("
<form method=get enctype=text/plain> <input type=text name=nombreproducto size=25 maxlength=50>

");
          client.println("<hr><input type=submit name=Aceptar value=Introducir><input type=Reset name=Cancelar value=Cancelar></form>");

I have not yet programmed, i have only the website programmed, but I think I should set it here to copy the string

if (client) {
    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        
        if (readString.length()<30) //leer peticion HTTP caracter por caracter
        {
           readString += c;
 
        }
        

        
        if (c=='\n') //Si la peticion HTTP ha finalizado
        {
           
          }
           
        }//while

Sorry but i am from Spain and I do not write very well in English.
thanks

but I think I should set it here to copy the string

So, why don't you?

What IS in readString when the \n arrives?

Server test code that uses a form text box to make a GET request. You can view what the server is receiving by using the serial monitor.

//zoomkat 12-08-12
//get submit box 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 a '
//address will look like http://192.168.1.102:84 when submited
//for use with W5100 based ethernet shields
//note that the below bug fix may be required
// http://code.google.com/p/arduino/issues/detail?id=605 

#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);
  server.begin();

  //enable serial data print 
  Serial.begin(9600); 
  Serial.println("server text box test1"); // 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);
        } 

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

          ///////////////
          Serial.println(readString); //see what was captured

          //now output HTML data header

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

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

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

          client.println("<FORM ACTION='/' method=get >"); //uses IP/port of web page

          client.println("Pin 5 'on' or 'off': <INPUT TYPE=TEXT NAME='LED' VALUE='' SIZE='25' MAXLENGTH='50'>
");

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

          client.println("</FORM>");

          client.println("
");

          client.println("</BODY>");
          client.println("</HTML>");

          delay(1);
          //stopping client
          client.stop();

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

        }
      }
    }
  }
}

I have tried but i have many problems, i want to keep "nombredeproducto" to my arduino via a website HTML

          client.println("
<form method=get enctype=text/plain> <input type=text name=nombreproducto size=25 maxlength=50>

");

I think this is very interesting because i want a string to send and i have not found any example.
Thank you very much

This is my code:

#include <SPI.h>
#include <Client.h>
#include <Ethernet.h>
#include <Server.h>
#include <Udp.h>
#include <String/WString.h>

// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,1, 35); // ip del rango establecido en el router
byte gateway[] = {192, 168, 2, 254 };  
char producto[24];
byte contador=0;

// Initialize the Ethernet server library
// with the IP address and port you want to use 
// (port 80 is default for HTTP):
EthernetServer server(80);

String readString = String(30);


void setup()
{
  // start the Ethernet connection and the server:
  Ethernet.begin(mac, ip, gateway);
  server.begin();
  Serial.begin(9600);
}

void loop()
{
  // listen for incoming clients
  EthernetClient client = server.available();
  if (client) {
    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        
        if (readString.length()<30) //leer peticion HTTP caracter por caracter
        {
           readString += c;
           producto[contador] = c;
           contador++;
 
        }
        

        
        if (c=='\n') //Si la peticion HTTP ha finalizado
        {
              if(Serial.available()){
                  memset(producto, 0, sizeof(producto)); // Borrado de la cadena
                  while (Serial.available()>0){ // ¿Existe comunicacion?
                  delay(5); // Permite llenar el buffer
                  producto[contador]=Serial.read(); // Lectura de teclado via serial.
                  contador++;
                  }
           
          }  
        }
           
        }
        

          //Enviar cabecera HTTP estandar

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

          //Crear pagina web HTML

          client.println("<html>");
          client.println("<head>");
          client.println("<title>Centro de control de productos</title>");
          client.println("</head>");
          client.println("<body>");
          client.println("<h1>Centro de control de productos</h1>");
          client.println("
<hr>
");
          client.println("<b>Nombre del Producto");
          client.println("
<form method=get enctype=text/plain> <input type=text name=nombreproducto size=25 maxlength=50>

");
          client.println("<hr><input type=submit name=Aceptar value=Introducir><input type=Reset name=Cancelar value=Cancelar></form>");
  
          client.println("<hr>
");
          client.println("</body>");
          client.println("</html>");

          client.stop();
        }
       

        
         Serial.println(producto); 
         readString=""; //Vaciar el string que se uso para la lectura
      
      
    }

  }

I have tried but i have many problems, i want to keep "nombredeproducto" to my arduino via a website HTML

Language might be one of them, because this statement makes no sense. You can't send a webpage to the Arduino. The Arduino can serve up a page. If the page contains a form, with a submit button, and an action field, that action field can cause another GET request to be made. If the form also contains text fields, the contents of those fields will be part of the GET request. You can then parse the GET request, to see if it contains anything for you to deal with, as opposed to an initial request for the page.

        char c = client.read();

What ARE you getting?

Please give me the Library
<String / WString.h>

Please give me the Library

You already have that library. You should NOT be using it.