Go Down

Topic: String(?) error (Read 9893 times) previous topic - next topic

Haavard GJ

Hi
was going to compile a program that i copyed off the web, but i get the following error message:

Code: [Select]

C:\arduino-0021\libraries\String\WString.cpp:34: error: prototype for 'String::String(int)' does not match any in class 'String'
C:\arduino-0021\hardware\arduino\cores\arduino/WString.h:39: error: candidates are: String::String(long unsigned int, int)
C:\arduino-0021\hardware\arduino\cores\arduino/WString.h:38: error:                 String::String(long int, int)
C:\arduino-0021\hardware\arduino\cores\arduino/WString.h:37: error:                 String::String(unsigned int, int)
C:\arduino-0021\hardware\arduino\cores\arduino/WString.h:36: error:                 String::String(int, int)
C:\arduino-0021\hardware\arduino\cores\arduino/WString.h:35: error:                 String::String(unsigned char)
C:\arduino-0021\hardware\arduino\cores\arduino/WString.h:34: error:                 String::String(char)
C:\arduino-0021\hardware\arduino\cores\arduino/WString.h:33: error:                 String::String(const String&)
C:\arduino-0021\hardware\arduino\cores\arduino/WString.h:32: error:                 String::String(const char*)
C:\arduino-0021\libraries\String\WString.cpp: In constructor 'String::String(const char*)':
C:\arduino-0021\libraries\String\WString.cpp:50: error: '_array' was not declared in this scope
C:\arduino-0021\libraries\String\WString.cpp:52: error: 'setArray' was not declared in this scope
C:\arduino-0021\libraries\String\WString.cpp: In copy constructor 'String::String(const String&)':
C:\arduino-0021\libraries\String\WString.cpp:60: error: '_array' was not declared in this scope
C:\arduino-0021\libraries\String\WString.cpp:61: error: 'clear' was not declared in this scope
C:\arduino-0021\libraries\String\WString.cpp:62: error: 'const class String' has no member named '_array'
C:\arduino-0021\libraries\String\WString.cpp:62: error: 'setArray' was not declared in this scope
C:\arduino-0021\libraries\String\WString.cpp: In member function 'const String& String::operator=(const String&)':
C:\arduino-0021\libraries\String\WString.cpp:77: error: '_array' was not declared in this scope
C:\arduino-0021\libraries\String\WString.cpp:83: error: 'clear' was not declared in this scope
C:\arduino-0021\libraries\String\WString.cpp:84: error: 'const class String' has no member named '_array'
C:\arduino-0021\libraries\String\WString.cpp:84: error: 'setArray' was not declared in this scope
C:\arduino-0021\libraries\String\WString.cpp: At global scope:
C:\arduino-0021\libraries\String\WString.cpp:90: error: prototype for 'const String& String::operator=(const char*)' does not match any in class 'String'
C:\arduino-0021\libraries\String\WString.cpp:70: error: candidate is: const String& String::operator=(const String&)
C:\arduino-0021\libraries\String\WString.cpp:107: error: prototype for 'const String& String::operator+=(const char*)' does not match any in class 'String'
C:\arduino-0021\hardware\arduino\cores\arduino/WString.h:44: error: candidate is: const String& String::operator+=(const String&)
C:\arduino-0021\libraries\String\WString.cpp:127: error: prototype for 'const String& String::operator+=(char)' does not match any in class 'String'
C:\arduino-0021\hardware\arduino\cores\arduino/WString.h:44: error: candidate is: const String& String::operator+=(const String&)
C:\arduino-0021\libraries\String\WString.cpp:145: error: prototype for 'const String& String::operator+=(int)' does not match any in class 'String'
C:\arduino-0021\hardware\arduino\cores\arduino/WString.h:44: error: candidate is: const String& String::operator+=(const String&)
C:\arduino-0021\libraries\String\WString.cpp:159: error: prototype for 'const String& String::operator+=(long int)' does not match any in class 'String'
C:\arduino-0021\hardware\arduino\cores\arduino/WString.h:44: error: candidate is: const String& String::operator+=(const String&)
C:\arduino-0021\libraries\String\WString.cpp: In member function 'const String& String::operator+=(const String&)':
C:\arduino-0021\libraries\String\WString.cpp:176: error: '_array' was not declared in this scope
C:\arduino-0021\libraries\String\WString.cpp:179: error: 'setArray' was not declared in this scope
C:\arduino-0021\libraries\String\WString.cpp:183: error: '_array' was not declared in this scope
C:\arduino-0021\libraries\String\WString.cpp:183: error: 'const class String' has no member named '_array'
C:\arduino-0021\libraries\String\WString.cpp: At global scope:
C:\arduino-0021\libraries\String\WString.cpp:191: error: no 'const String& String::append(char)' member function declared in class 'String'
C:\arduino-0021\libraries\String\WString.cpp:196: error: no 'const String& String::append(char*)' member function declared in class 'String'
C:\arduino-0021\libraries\String\WString.cpp:201: error: no 'const String& String::append(const String&)' member function declared in class 'String'
C:\arduino-0021\libraries\String\WString.cpp:206: error: no 'const String& String::append(int, int)' member function declared in class 'String'
C:\arduino-0021\libraries\String\WString.cpp:217: error: no 'const String& String::append(long int, int)' member function declared in class 'String'
C:\arduino-0021\libraries\String\WString.cpp:226: error: no 'const String& String::append(int)' member function declared in class 'String'
C:\arduino-0021\libraries\String\WString.cpp:234: error: no 'const String& String::append(long int)' member function declared in class 'String'
C:\arduino-0021\libraries\String\WString.cpp:323: error: prototype for 'char String::charAt(int)' does not match any in class 'String'
C:\arduino-0021\hardware\arduino\cores\arduino/WString.h:57: error: candidate is: char String::charAt(unsigned int) const
C:\arduino-0021\libraries\String\WString.cpp:339: error: prototype for 'void String::setCharAt(int, char)' does not match any in class 'String'
C:\arduino-0021\hardware\arduino\cores\arduino/WString.h:71: error: candidate is: void String::setCharAt(unsigned int, char)
C:\arduino-0021\libraries\String\WString.cpp:355: error: prototype for 'boolean String::equals(char*)' does not match any in class 'String'
C:\arduino-0021\hardware\arduino\cores\arduino/WString.h:60: error: candidate is: unsigned char String::equals(const String&) const
C:\arduino-0021\libraries\String\WString.cpp:366: error: prototype for 'boolean String::equals(const String&)' does not match any in class 'String'
C:\arduino-0021\hardware\arduino\cores\arduino/WString.h:60: error: candidate is: unsigned char String::equals(const String&) const
C:\arduino-0021\libraries\String\WString.cpp:372: error: no 'boolean String::contains(char*)' member function declared in class 'String'
C:\arduino-0021\libraries\String\WString.cpp:380: error: prototype for 'byte* String::getBytes()' does not match any in class 'String'
C:\arduino-0021\hardware\arduino\cores\arduino/WString.h:79: error: candidate is: void String::getBytes(unsigned char*, unsigned int)
C:\arduino-0021\libraries\String\WString.cpp:386: error: no 'void String::setArray(const char*)' member function declared in class 'String'
C:\arduino-0021\libraries\String\WString.cpp:396: error: prototype for 'int String::indexOf(int)' does not match any in class 'String'
C:\arduino-0021\hardware\arduino\cores\arduino/WString.h:65: error: candidates are: int String::indexOf(const String&, unsigned int) const
C:\arduino-0021\hardware\arduino\cores\arduino/WString.h:64: error:                 int String::indexOf(const String&) const
C:\arduino-0021\hardware\arduino\cores\arduino/WString.h:63: error:                 int String::indexOf(char, unsigned int) const
C:\arduino-0021\hardware\arduino\cores\arduino/WString.h:62: error:                 int String::indexOf(char) const
C:\arduino-0021\libraries\String\WString.cpp:402: error: prototype for 'int String::indexOf(const String&)' does not match any in class 'String'
C:\arduino-0021\hardware\arduino\cores\arduino/WString.h:65: error: candidates are: int String::indexOf(const String&, unsigned int) const
C:\arduino-0021\hardware\arduino\cores\arduino/WString.h:64: error:                 int String::indexOf(const String&) const
C:\arduino-0021\hardware\arduino\cores\arduino/WString.h:63: error:                 int String::indexOf(char, unsigned int) const
C:\arduino-0021\hardware\arduino\cores\arduino/WString.h:62: error:                 int String::indexOf(char) const
C:\arduino-0021\libraries\String\WString.cpp:408: error: prototype for 'int String::indexOf(char, int)' does not match any in class 'String'
C:\arduino-0021\hardware\arduino\cores\arduino/WString.h:65: error: candidates are: int String::indexOf(const String&, unsigned int) const
C:\arduino-0021\hardware\arduino\cores\arduino/WString.h:64: error:                 int String::indexOf(const String&) const
C:\arduino-0021\hardware\arduino\cores\arduino/WString.h:63: error:                 int String::indexOf(char, unsigned int) const
C:\arduino-0021\hardware\arduino\cores\arduino/WString.h:62: error:                 int String::indexOf(char) const
C:\arduino-0021\libraries\String\WString.cpp:420: error: prototype for 'int String::indexOf(const String&, int)' does not match any in class 'String'
C:\arduino-0021\hardware\arduino\cores\arduino/WString.h:65: error: candidates are: int String::indexOf(const String&, unsigned int) const
C:\arduino-0021\hardware\arduino\cores\arduino/WString.h:64:
anyone that understands this cryptic message?

PaulS

Quote
was going to compile a program that i copyed off the web

That code, huh?

Quote
anyone that understands this cryptic message?

Nothing cryptic about any of the messages. Terse, perhaps.

Which version of the ODE are you using.The String class got incorporated into the core, and some changes were made,in 0019, I think.

Haavard GJ

#2
Dec 16, 2010, 09:11 pm Last Edit: Dec 16, 2010, 09:14 pm by haavardgj Reason: 1
if i include "wstring" i get all the error messages as written above, but if i dont include them, i get theese message:

Code: [Select]


Arduino_Webserver___VIKTIG.cpp: In function 'void loop()':
Arduino_Webserver___VIKTIG:50: error: 'class String' has no member named 'append'
Arduino_Webserver___VIKTIG:60: error: 'class String' has no member named 'contains'
Arduino_Webserver___VIKTIG:65: error: 'class String' has no member named 'contains'

Haavard GJ

#3
Dec 16, 2010, 09:13 pm Last Edit: Dec 16, 2010, 09:19 pm by haavardgj Reason: 1
and here is the code:
btw: i use version 21
Code: [Select]


//*******************************

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

/*
Simple Ethernet Test
Arduino server outputs simple text to browser
and controlling LED with simple checkbox
The circuit:
* Arduino Duemilanove
* Arduino Ethernet shield
* Basic FTDI breakout 5V
* LED connected to GND and digital pin 4 via resistor
By Minde
http://www.sciencprog.com/
*/

byte    mac[] =     { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };   //physical mac address
byte    ip[] =      { 192, 168, 1, 110 };                     // ip in lan
byte    gateway[] = { 192, 168, 1, 1 };                       // internet access via router
byte    subnet[] =  { 255, 255, 255, 0 };                     //subnet mask
Server  server(80);                //server port
byte    sampledata=50;             //some sample data - outputs 2 (ascii = 50 DEC)
int     ledPin = 4;                // LED pin
char    link[]= "";                 //link data
String  readString = String(30);   //string for fetching data from address
boolean LEDON = false;             //LED status flag

void setup()
{    
 Serial.begin(9600); //enable serial datada print
 Ethernet.begin(mac, ip, gateway, subnet); //start Ethernet
 
 pinMode(ledPin, OUTPUT); //Set pin 4 to output
 Serial.print("Starter server");
}

void loop(){

 Client client = server.available();  // Create a client connection
   if (client) {
     while (client.connected()) {
       if (client.available()) {

         char c = client.read();

       if (readString.length() < 30) { //read char by char HTTP request
         readString.append(c); } //store characters to string
         
       Serial.print(c); //output chars to serial port for debugging



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


         //lets check if LED should be lighted
         if (readString.contains("L=1")) { //led has to be turned ON
             digitalWrite(ledPin, HIGH); // set the LED on
             LEDON = true;
         }

         if (readString.contains("L=0")) {
           //led has to be turned OFF
           digitalWrite(ledPin, LOW); // set the LED OFF
           LEDON = false;
          }


client.println("HTTP/1.1 200 OK"); // now output HTML data starting with standart header
client.println("Content-Type: text/html");
client.println();
client.print  ("<body style=background-color:white>"); //set background to white

// HTML Code

client.println("<font color='red'><h1>HTTP test routines</font></h1>");//send first heading
client.println("<hr />");
client.println("<font color='blue' size='5[ch8242]>Sample data: "); //output some sample data to browser

client.print(sampledata);//lets output some data

client.println("<br />");//some space between lines
client.println("<hr />");
client.println("<font color='green'>Simple table: "); //drawing simple table
client.println("<br />");
client.println("<table border=1><tr><td>row 1, cell 1</td><td>row 1, cell 2</td></tr>");
client.println("<tr><td>row 2, cell 1</td><td>row 2, cell 2</td></tr></table>");

client.println("<br />");
client.println("<hr />");

client.println("<font color='blue' size='5[ch8242]>Link: "); //printing some link
client.print("<a href=");
client.print(link);
client.println(">Visit Scienceprog!</a>");
client.println("<br />");
client.println("<hr />");

//controlling led via checkbox
client.println("<h1>LED control</h1>");

//address will look like http://192.168.1.110/?L=1 when submited
client.println("<form method=get name=LED> <input type='radio' name='L' value='1'>LED ON<br><input type='radio' name='L' value='0'>LED OFF<br><input type=submit value=submit></form>");

client.println("<br />");
//printing LED status
client.print("<font size='5[ch8242]>LED status: ");
 if (LEDON) {
    client.println("<font color='green' size='5[ch8242]>ON");
  }
 else {
   client.println("<font color='grey' size='5[ch8242]>OFF");
  }

client.println("<hr />");
client.println("<hr />");
client.println("</body></html>");
//clearing string for next read
readString="";

//stopping client

client.stop();

}}}}}

PaulS

Quote
btw: i use version 21


Quote
if i include "wstring" i get all the error messages as written above, but if i dont include them, i get theese message:

You should not be including WString.h with 0021.

Quote
The String class got incorporated into the core, and some changes were made,in 0019, I think.

The sample that you are trying to compile was not modified for 0021. You have two choices. One is to compile and link using 0018. The other is to update the code to use the 0021 String class.

Quote
error: 'class String' has no member named 'append'
error: 'class String' has no member named 'contains'

The old names should give you a pretty good hint as to what the functions do. It should not be too difficult to figure out what the replacement function is. I'll give you the first one, though. append becomes concat.

The contains method will require a bit more work, unfortunately. Not terribly difficult, though. Give it a try, and come back if you can't figure it out.

Haavard GJ

now i have seen through the code, and searched around a bit, is this more correct code?
Code: [Select]


//*******************************

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

/*
Simple Ethernet Test
Arduino server outputs simple text to browser
and controlling LED with simple checkbox
The circuit:
* Arduino Duemilanove
* Arduino Ethernet shield
* Basic FTDI breakout 5V  
* LED connected to GND and digital pin 4 via resistor
By Minde
http://www.sciencprog.com/
*/

byte    mac[] =     { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };   //physical mac address
byte    ip[] =      { 192, 168, 1, 110 };                     // ip in lan
byte    gateway[] = { 192, 168, 1, 1 };                       // internet access via router
byte    subnet[] =  { 255, 255, 255, 0 };                     //subnet mask
Server  server(80);                // server port
byte    sampledata=50;             // some sample data - outputs 2 (ascii = 50 DEC)
int     ledPin = 4;                // LED pin
int     heatpin = 5;               // Heating *relay*
char    link[]= "";                // link data
String  readString = String(30);   // string for fetching data from address
boolean LEDON = false;             // LED status flag
boolean HEATON = false;             // Heat status flag

void setup()
{    
 Serial.begin(57600); //enable serial datada print
 Ethernet.begin(mac, ip, gateway, subnet); //start Ethernet
 
 pinMode(ledPin, OUTPUT); //Set pin 4 to output
 Serial.print("Starter server");
}

void loop(){

 Client client = server.available();  // Create a client connection
   if (client) {
     while (client.connected()) {
       if (client.available()) {

         char c = client.read();

       if (readString.length() < 30) { //read char by char HTTP request
         readString.concat(c); } //store characters to string
         
       Serial.print(c); //output chars to serial port for debugging



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


         //lets check if LED should be lighted
         if (readString.equalsIgnoreCase("L=1")) { //led has to be turned ON
             digitalWrite(ledPin, HIGH); // set the LED on
             LEDON = true;
         }

         if (readString.equalsIgnoreCase("L=0")) {
           //led has to be turned OFF
           digitalWrite(ledPin, LOW); // set the LED OFF
           LEDON = false;
          }
         
         
         if (readString.equalsIgnoreCase("H=1")) { //heat has to be turned ON
             digitalWrite(heatpin, HIGH); // set the heat on
             HEATON = true;
         }

         if (readString.equalsIgnoreCase("H=0")) {
           //heat has to be turned OFF
           digitalWrite(heatpin, LOW); // set the heat OFF
           HEATON = false;
          }
         
         
         
         


client.println("HTTP/1.1 200 OK"); // now output HTML data starting with standart header
client.println("Content-Type: text/html");
client.println();
client.print  ("<body style=background-color:white>"); //set background to white

// HTML Code

client.println("<font color='red'><h1>Arduino fjernstyringsside</font></h1>");//send first heading
client.println("<hr />");
client.println("<font color='blue' size='5[ch8242]>Sample data: "); //output some sample data to browser

client.print(sampledata);//lets output some data

client.println("<br />");//some space between lines
client.println("<hr />");
client.println("<font color='green'>Simple table: "); //drawing simple table
client.println("<br />");
client.println("<table border=1><tr><td>row 1, cell 1</td><td>row 1, cell 2</td></tr>");
client.println("<tr><td>row 2, cell 1</td><td>row 2, cell 2</td></tr></table>");

client.println("<br />");
client.println("<hr />");

client.println("<font color='blue' size='5[ch8242]>Link: "); //printing some link
client.print("<a href=");
client.print(link);
client.println(">Visit Scienceprog!</a>");
client.println("<br />");
client.println("<hr />");

//controlling led via checkbox
client.println("<h1>LED control</h1>");

//address will look like http://192.168.1.110/?L=1 when submited
client.println("<form method=get name=LED> <input type='radio' name='L' value='1'>LED ON<br><input type='radio' name='L' value='0'>LED OFF<br><input type='radio' name='H' value='1'>HEAT ON<br><input type='radio' name='H' value='0'>HEAT OFF<br><input type=submit value=submit></form>");

client.println("<br />");
//printing LED status
client.print("<font size='5[ch8242]>LED status: ");
 if (LEDON) {
    client.println("<font color='green' size='5[ch8242]>ON");
  }
 else {
   client.println("<font color='grey' size='5[ch8242]>OFF");
  }

client.println("<hr />");
client.println("<hr />");
client.println("</body></html>");
//clearing string for next read
readString="";

//stopping client

client.stop();

Serial.println("Stopper klient");

}}}}}


still a bit confused...
(i'm still a real newbie)

PaulS

Quote
is this more correct code?

The proof, as they say, is in the pudding. Does it compile and link? Does it do what you want it to do?

Haavard GJ

#7
Dec 19, 2010, 09:48 pm Last Edit: Dec 19, 2010, 09:51 pm by haavardgj Reason: 1
the code compile, and i get the analog input to show up on the output web site.

but i can't get the substring to read the feedback from the browser.
i have tryed using "if (readString.equalsIgnoreCase("L=0")) {"  and also
"if (readString.substring(30) == "L=0") {" but none of they work...
i think i have to "crawl to the cross" and ask if you can tell me what's wrong

PaulS

Quote
and ask if you can tell me what's wrong

I have no idea what is in readString, and it isn't clear that you do, either.

The String object has an indexOf() method that can be used to locate the position of "L=". If it exists, then you can make a substring from that position on. If it doesn't exist, look for "H=". If it exists, make a substring.

If you extract a substring, then you can test that the substring is 3 bytes long, and truncate it if it isn't. Then, the substring should be L=0, L=1, H=0, or H=1.

Haavard GJ

i have been testing the code a little to get an idea of whats going in and out... so i have putted some serial.print in the code.

Code: [Select]

Starter server //start the server

GET / HTTP/1.1 //without any choises marked
Stopper klient

GET /?L=1 HTTP/1.1 // with light marked on
Stopper klient  //stopping client at end of code



the GET part is what i get out from the concat(c) (c is printed over serial)




Haavard GJ

here is my code now.... still don't working, but i'll continue tomorrow.

Code: [Select]


//*******************************

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

/*
Simple Ethernet Test
Arduino server outputs simple text to browser
and controlling LED with simple checkbox
The circuit:
* Arduino Duemilanove
* Arduino Ethernet shield
* Basic FTDI breakout 5V  
* LED connected to GND and digital pin 4 via resistor
By Minde
http://www.sciencprog.com/
*/

byte    mac[] =     { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };   //physical mac address
byte    ip[] =      { 192, 168, 2, 110 };                     // ip in lan
byte    gateway[] = { 192, 168, 2, 1 };                       // internet access via router
byte    subnet[] =  { 255, 255, 255, 0 };                     //subnet mask
Server  server(80);                // server port
int     ledPin = 4;                // LED pin
int     heatpin = 5;               // Heating *relay*
int     sensorPin = A0; // analog in 1 for testing
int     sensorValue = 0;
char    link[]= "";                // link data
String  readString = String(30);   // string for fetching data from address
boolean LEDON = false;             // LED status flag
boolean HEATON = false;             // Heat status flag


void setup()
{    
 Serial.begin(57600); //enable serial datada print
 Ethernet.begin(mac, ip, gateway, subnet); //start Ethernet
 
 pinMode(ledPin, OUTPUT); //Set pin 4 to output
 pinMode(heatpin, OUTPUT);
 Serial.print("Starter server");
 
 sensorValue = analogRead(sensorPin);
 Serial.println("");
 Serial.println (sensorValue);

}

void loop(){

 Client client = server.available();  // Create a client connection
   if (client) {
     while (client.connected()) {
       if (client.available()) {

         char c = client.read();

       if (readString.length() < 30) { //read char by char HTTP request
         readString.concat(c); } //store characters to string
         
       Serial.print(c); //output chars to serial port for debugging



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



         //lets check if LED should be lighted
         if (readString.substring(c) == "L=1") { //led has to be turned ON
             digitalWrite(ledPin, HIGH); // set the LED on
             Serial.println("ledpin på");
             LEDON = true;
         }

         if (readString.substring(c)== "L=0") {
           //led has to be turned OFF
           digitalWrite(ledPin, LOW); // set the LED OFF
           Serial.println("ledpin av");
           LEDON = false;
          }
         
         
         if (readString.substring(c) == "H=1") { //heat has to be turned ON
             digitalWrite(heatpin, HIGH); // set the heat on
             Serial.println("heatpin på");
             HEATON = true;
         }

         if (readString.substring(c) == "H=0") {
           //heat has to be turned OFF
           digitalWrite(heatpin, LOW); // set the heat OFF
           Serial.println("heatpin av");
           HEATON = false;
          }
         
         
         
         


client.println("HTTP/1.1 200 OK"); // now output HTML data starting with standart header
client.println("Content-Type: text/html");
client.println();
client.print  ("<body style=background-color:white>"); //set background to white

// HTML Code

client.println("<font color='red'><h1>Arduino fjernstyringsside</font></h1>");//send first heading
client.println("<hr />");
client.println("<font color='blue' size='5[ch8242]>Analog input: "); //output some sample data to browser
 sensorValue = analogRead(sensorPin);


client.print(sensorValue);//lets output some data
Serial.print(sensorValue);

client.println("<br />");//some space between lines
client.println("<hr />");
client.println("<font color='green'>Simple table: "); //drawing simple table
client.println("<br />");
client.println("<table border=1><tr><td>row 1, cell 1</td><td>row 1, cell 2</td></tr>");
client.println("<tr><td>row 2, cell 1</td><td>row 2, cell 2</td></tr></table>");

client.println("<br />");
client.println("<hr />");


//controlling led via checkbox
client.println("<h1>LED control</h1>");

//address will look like http://192.168.1.110/?L=1 when submited
client.println("<form method=get name=LED> <input type='radio' name='L' value='1'>LED ON<br><input type='radio' name='L' value='0'>LED OFF<br><input type='radio' name='H' value='1'>HEAT ON<br><input type='radio' name='H' value='0'>HEAT OFF<br><input type=submit value=submit></form>");

client.println("<br />");
//printing LED status
client.print("<font size='5[ch8242]>LED status: ");
 if (LEDON == true) {
    client.println("<font color='green' size='5[ch8242]>ON");
    Serial.print("led på");
}
 else {
   client.println("<font color='grey' size='5[ch8242]>OFF");
  }

client.println("<hr />");
client.println("<hr />");
client.println("</body></html>");
//clearing string for next read
readString="";

//stopping client

client.stop();

Serial.println("Stopper klient");

}}}}}

PaulS

Code: [Select]
if (readString.substring(c) == "H=0") {
c is a char variable. It is not an integer. The substring you are extracting is completely bogus.

Use Serial.print() to print readString. Then, use indexOf, to see if the string contains L= or H=. The indexOf function returns where the L= or H= occurred. Then, extract a substring from there to the end of readString.

Haavard GJ

after putting in serial.print(readstring) i have got theese results on the serial monitor
the highlighted lines are from the readstring
Code: [Select]
Starter server

499 (analog input)


G
[glow]30G[/glow]

E[glow]
30GE[/glow]

T
[glow]30GET[/glow]


[glow]30GET [/glow]

/
[glow]30GET /[/glow]

?
[glow]30GET /?[/glow]

L
[glow]30GET /?L[/glow]

=
[glow]30GET /?L=[/glow]

1
[glow]30GET /?L=1[/glow]


[glow]30GET /?L=1 [/glow]

H
[glow]30GET /?L=1 H
[/glow]
T
[glow]30GET /?L=1 HT[/glow]

T
[glow]30GET /?L=1 HTT[/glow]

P
[glow]30GET /?L=1 HTTP
[/glow]
/
[glow]30GET /?L=1 HTTP/[/glow]

1
[glow]30GET /?L=1 HTTP/1[/glow]

.
[glow]30GET /?L=1 HTTP/1.[/glow]

1
[glow]30GET /?L=1 HTTP/1.1

[/glow]

[glow]30GET /?L=1 HTTP/1.1[/glow]



[glow]
30GET /?L=1 HTTP/1.1
[/glow]

Stopper klient (stopping client)


and here is the code for the printing:
Code: [Select]
 Client client = server.available();  // Create a client connection
   if (client) {
     while (client.connected()) {
       if (client.available()) {

         char c = client.read();

       if (readString.length() < 30) { //read char by char HTTP request
         readString.concat(c); } //store characters to string
         
       Serial.print(c); //output chars to serial port for debugging
       Serial.println("");
      [glow] Serial.println(readString); // print for debugging[/glow]
       Serial.println("");

PaulS

Move the call to print readString to after the if(c == '\n') statement's open curly brace. We only want to process it when the whole string has come in.

Then, add these lines after it:
Code: [Select]
int Le = readString.indexOf("L=");
int He = readString.indexOf("H=");
Serial.print("L= position: ");
Serial.println(Le);
Serial.print("H= position: ");
Serial.println(He);


Post the results...

Haavard GJ

Horayyy... now i got it to work as intended   8-) :D

Code: [Select]


//*******************************

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

/*
Simple Ethernet Test
Arduino server outputs simple text to browser
and controlling LED with simple checkbox
The circuit:
* Arduino Duemilanove
* Arduino Ethernet shield
* Basic FTDI breakout 5V  
* LED connected to GND and digital pin 4 via resistor
By Minde
http://www.sciencprog.com/
*/

byte    mac[] =     { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };   //physical mac address
byte    ip[] =      { 192, 168, 2, 110 };                     // ip in lan
byte    gateway[] = { 192, 168, 2, 1 };                       // internet access via router
byte    subnet[] =  { 255, 255, 255, 0 };                     //subnet mask
Server  server(80);                // server port
int     ledPin = 4;                // LED pin
int     heatpin = 5;               // Heating *relay*
int     sensorPin = A0; // analog in 1 for testing
int     sensorValue = 0;
char    link[]= "";                // link data
String  readString = String(30);   // string for fetching data from address
boolean LEDON = false;             // LED status flag
boolean HEATON = false;             // Heat status flag


void setup()
{    
 Serial.begin(57600); //enable serial datada print
 Ethernet.begin(mac, ip, gateway, subnet); //start Ethernet
 
 pinMode(ledPin, OUTPUT); //Set pin 4 to output
 pinMode(heatpin, OUTPUT);
 Serial.print("Starter server");
 
 sensorValue = analogRead(sensorPin);
 Serial.println("");
 Serial.println("");
 Serial.println (sensorValue);
 Serial.println("");
 Serial.println("");

}

void loop(){

 Client client = server.available();  // Create a client connection
   if (client) {
     while (client.connected()) {
       if (client.available()) {

         char c = client.read();

       if (readString.length() < 30) { //read char by char HTTP request
         readString.concat(c); } //store characters to string
         
       Serial.print(c); //output chars to serial port for debugging
       

//indexOf("L=")

       if (c == '\n') { //if HTTP request has ended
       
         Serial.println("");
         Serial.println(readString); // print for debugging
         Serial.println("");
         int Le = readString.indexOf("L=");
         int He = readString.indexOf("H=");
         Serial.print("L= position: ");
         Serial.println(Le);
         Serial.print("H= position: ");
         Serial.println(He);
         
         
         
         
         
         //lets check if LED should be lighted
         if (readString.substring(Le,(Le+3)) == "L=1") { //led has to be turned ON
             digitalWrite(ledPin, HIGH); // set the LED on
             Serial.println("ledpin paa");
             LEDON = true;
         }

         if (readString.substring(Le,(Le+3))== "L=0") {
           //led has to be turned OFF
           digitalWrite(ledPin, LOW); // set the LED OFF
           Serial.println("ledpin av");
           LEDON = false;
          }
         
         
         if (readString.substring(He,(He+3) == "H=1") { //heat has to be turned ON
             digitalWrite(heatpin, HIGH); // set the heat on
             Serial.println("heatpin paa");
             HEATON = true;
         }

         if (readString.substring(He,(He+3) == "H=0") {
           //heat has to be turned OFF
           digitalWrite(heatpin, LOW); // set the heat OFF
           Serial.println("heatpin av");
           HEATON = false;
          }
         
         
         
         


client.println("HTTP/1.1 200 OK"); // now output HTML data starting with standart header
client.println("Content-Type: text/html");
client.println();
client.print  ("<body style=background-color:white>"); //set background to white

// HTML Code

client.println("<font color='red'><h1>Arduino fjernstyringsside</font></h1>");//send first heading
client.println("<hr />");
client.println("<font color='blue' size='5[ch8242]>Analog input: "); //output some sample data to browser
 sensorValue = analogRead(sensorPin);


client.print(sensorValue);//lets output some data
Serial.print(sensorValue);

client.println("<br />");//some space between lines
client.println("<hr />");
client.println("<font color='green'>Simple table: "); //drawing simple table
client.println("<br />");
client.println("<table border=1><tr><td>row 1, cell 1</td><td>row 1, cell 2</td></tr>");
client.println("<tr><td>row 2, cell 1</td><td>row 2, cell 2</td></tr></table>");

client.println("<br />");
client.println("<hr />");


//controlling led via checkbox
client.println("<h1>LED control</h1>");

//address will look like http://192.168.1.110/?L=1 when submited
client.println("<form method=get name=LED> <input type='radio' name='L' value='1'>LED ON<br><input type='radio' name='L' value='0'>LED OFF<br><input type='radio' name='H' value='1'>HEAT ON<br><input type='radio' name='H' value='0'>HEAT OFF<br><input type=submit value=submit></form>");

client.println("<br />");
//printing LED status
client.print("<font size='5[ch8242]>LED status: ");
 if (LEDON == true) {
    client.println("<font color='green' size='5[ch8242]>ON");
    Serial.print("led på");
}
 else {
   client.println("<font color='grey' size='5[ch8242]>OFF");
  }

client.println("<hr />");
client.println("<hr />");
client.println("</body></html>");
//clearing string for next read
readString="";

//stopping client

client.stop();

Serial.println("Stopper klient");

}}}}}


now as it works, i'm going to modify the code to get more in/outputs

here is what got out of the serial monitor:

Code: [Select]
Starter server




GET /?L=1 HTTP/1.1

30GET /?L=1 HTTP/1.1


L= position: 8
H= position: -1
Stopper klient


GET /?L=1 HTTP/1.1


L= position: 6
H= position: -1
ledpin på
led påStopper klient
GET /?L=0 HTTP/1.1

GET /?L=0 HTTP/1.1


L= position: 6
H= position: -1
ledpin av
Stopper klient


just to have said it, i tested several times, and it did work all the time after i had put in the "Le" and "He"

Thanks for your help  8-)


Go Up