Pages: [1]   Go Down
Author Topic: webServer Example  (Read 1161 times)
0 Members and 1 Guest are viewing this topic.
Santander
Offline Offline
Newbie
*
Karma: 0
Posts: 47
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Code:
#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("<br />");
          }
          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!

Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 613
Posts: 49236
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Code:
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?

Code:
          // 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("<br />");
          }
Do you have something connected to these pins? Or is this just garbage?

Quote
or if I change the instruction to mySerial.print(client.read());
Why can't you be bothered to separate the values being printed?

Quote
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.
Logged

Santander
Offline Offline
Newbie
*
Karma: 0
Posts: 47
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

I use a FTDI Basic Breakout - 3.3V https://www.sparkfun.com/products/9873 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.

Quote
Do you have something connected to these pins? Or is this just garbage?
No, anything is connected to them.

Code:
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.
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 613
Posts: 49236
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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.

Code:
mySerial.print(client.read());
if fine IF you follow that with
Code:
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.

Quote
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?
Logged

Santander
Offline Offline
Newbie
*
Karma: 0
Posts: 47
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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!
Logged

Santander
Offline Offline
Newbie
*
Karma: 0
Posts: 47
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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.

Logged

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 146
Posts: 6009
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
*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.

Logged

Santander
Offline Offline
Newbie
*
Karma: 0
Posts: 47
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Now It works!

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

Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 613
Posts: 49236
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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.
Logged

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 146
Posts: 6009
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Santander
Offline Offline
Newbie
*
Karma: 0
Posts: 47
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

Thank you! So solving this error I continue with other problems. I talk about it in the next post: [url]http://arduino.cc/forum/index.php/topic,128982.msg977159.html#msg977159[\url]
 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.


Logged

Pages: [1]   Go Up
Jump to: