webServer Example

Hi everyone,

I've recently had some errors on my program so I've changed the board, and I tried to use a reduced the code to find the error.
Right now I am testing the WebServer Example of the Ethernet Library. Well, I've used Serial.print and even mySerial.print (SoftwareSerial.h) to detect the error. Anyway with an Arduino Ethernet board (Arduino 1.0 IDE) when I write on a browser the IP address of the board nothing happens. Trying to understand what happens I added a print instruction to see where the program stops.

#include <SPI.h>
#include <Ethernet.h>
#include <SoftwareSerial.h>
SoftwareSerial mySerial(2, 3);
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0x5E, 0xF4 };
IPAddress ip(192,168,112, 31);

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

void setup()
{
  // start the Ethernet connection and the server:
  Ethernet.begin(mac, ip);
  server.begin();
  mySerial.begin(9600);
  mySerial.print("webserver");
}

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();
        mySerial.print(c); <<<<<----------------
        // if you've gotten to the end of the line (received a newline
        // character) and the line is blank, the http request has ended,
        // so you can send a reply
        if (c == '\n' && currentLineIsBlank) {
          // send a standard http response header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println();

          // output the value of each analog input pin
          for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
            client.print("analog input ");
            client.print(analogChannel);
            client.print(" is ");
            client.print(analogRead(analogChannel));
            client.println("
");
          }
          break;
        }
        if (c == '\n') {
          // you're starting a new line
          currentLineIsBlank = true;
        } 
        else if (c != '\r') {
          // you've gotten a character on the current line
          currentLineIsBlank = false;
        }
      }
    }
    // give the web browser time to receive the data
    delay(1);
    // close the connection:
    client.stop();
  }
}

As you can see I introduce mySerial.print(c) and c is client.read() a char... It doesn't matter if it is mySerial.print (using SoftwareSerial library) or just using a Serial.print the result is this:

webserver
;Pʬ#t$¦@???_{(WÄá?l???ÉNá6
Uµ* ???65øÓ

or if I change the instruction to mySerial.print(client.read());

webserver135980202151723551163616664147128352011369512340

numbers! and I imagine when it tries to print the correspondient character the result are extrange symbols

I don't understand what happens. Please help!

thank you!

Trying to understand what happens I added a print instruction to see where the program stops.

Generally a good idea.

SoftwareSerial mySerial(2, 3);
  mySerial.begin(9600);
  mySerial.print("webserver");

What is connected to pins 2 and 3? Where is this data supposed to go?

          // output the value of each analog input pin
          for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
            client.print("analog input ");
            client.print(analogChannel);
            client.print(" is ");
            client.print(analogRead(analogChannel));
            client.println("
");
          }

Do you have something connected to these pins? Or is this just garbage?

or if I change the instruction to mySerial.print(client.read());

Why can't you be bothered to separate the values being printed?

webserver135980202151723551163616664147128352011369512340

numbers!

No. Meaningless crap, since you haven't a clue where each number starts and ends. Lacking that clue, you have no way of determining a meaning for the numbers, which is an essential piece of information.

What is connected to pins 2 and 3? Where is this data supposed to go?

I use a FTDI Basic Breakout - 3.3V SparkFun FTDI Basic Breakout - 3.3V - DEV-09873 - SparkFun Electronics I only connect the tx y rx ports to pins 2 y 3. But I've just said the same happens if I used a Serial.print.

Do you have something connected to these pins? Or is this just garbage?

No, anything is connected to them.

Why can't you be bothered to separate the values being printed?

I've just used the example. When I've tried in other occasions It print out the values of these ports on the browser.

The expected answer is a http frame, but instead it shows the extrange symbols or the numbers.

I've just used the example.

No. The example doesn't use mySerial and it doesn't print the value of client.read().

If you are going to modify the example, feel free to do a good job.

mySerial.print(client.read());

if fine IF you follow that with

mySerial.print(" ");

so that you see something like
webserver13 59 80 20 21 51 72 3551163616664147128352011369512340
or
webserver135 98 0 20 21 51723551163616664147128352011369512340

See, it's how the numbers break apart that is important.

I only connect the tx y rx ports to pins 2 y 3.

And ground, too?

Why aren't you using the standard USB cable to connect the Arduino to the PC?

Hi again,

more information:
*the IP address is not used. I've tried with a ping.
*I change the ethernet cable.
*when I connect the board I ping it and it responds.
*My operating system is Ubuntu 11 and since a week I 'm using arduino 1.0 IDE. So I erase the 022 ide version. I thought that maybe the libraries were causing some conflits...

I do not know what is the problem. Maybe you know basic tips I didn't realize.

Thank you!

No. The example doesn't use mySerial and it doesn't print the value of client.read().

If you are going to modify the example, feel free to do a good job.

I was answering to your question about if there were something connecting to the ports.

I thought that maybe it could be a conflict using the Serial for that reason I prove with the SoftwareSerial library. But if I use the normal serial instructions it happens the same.

Arduino Ethernet, the FTDI board and the usb cable using just
char c = client.print() ;
Serial.print(c);
Serial.print(" ");
it prints the strange symbols. Or if I change it for
char c = client.print() ;
Serial.print(client.print());
Serial.print(" ");
it prints the numbers as you said with a space between then.

The strage thing is that when I tried this before no matter with which board it prints the http frame-

http://192.168.112.31/
Accept:text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8
User-Agent:Mozilla/5.0 (X11; Linux i686) AppleWebKit/535.19 (KHTML, like Gecko) Ubuntu/11.10 Chromium/18.0.1025.168 Chrome/18.0.1025.168 Safari/535.19

or something as this.

*My operating system is Ubuntu 11 and since a week I 'm using arduino 1.0 IDE.

IDE v0022 and v1.0 had a bug in the ethernet library that caused problems like that. Try downloading the new IDE v1.0.1 from the Arduino site and unpack it in a local directory. Then navigate to that directory and run the arduino shell script there.

Now It works!

Thank you!! And sorry for this, because at the end It was a version of the IDE problem.

And sorry for this, because at the end It was a version of the IDE problem.

No problem. Next time someone has a similar problem, maybe I'll remember this thread. Or, maybe they'll even find it and not have to ask.

pawqar:
Now It works!

Good deal. Here are my code samples from the playground. They have been tested well.
http://www.arduino.cc/playground/Code/WebClient
http://www.arduino.cc/playground/Code/WebServerST

Hi,

Thank you! So solving this error I continue with other problems. I talk about it in the next post: xbee + ethernet shield + arduino uno r2 - #9 by system - Networking, Protocols, and Devices - Arduino Forum
I hope you could help me.

There is a problem when I tried to use the board Arduino Ethernet with a Xbee Shield (using XBee Arduino Library Version 0.3 - Supports Arduino 1.0).

thank you again.