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("<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!