Go Down

Topic: Having trouble connecting to Arduino Webserver (Read 1 time) previous topic - next topic

ajsivsan

I am trying the run an example code but i am having hard time with it.

When i try to connect to the server via browser it does not connect.

I connected the lan cable directly to my laptop. No router in between. Is that a problem?

Please help me out...
Code: [Select]

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

byte mac[] = { 0x48, 0xC2, 0xA1, 0xF3, 0x8D, 0xB7 };
byte ip[] = { 192,168,0, 104 };

EthernetServer server(80);
void setup()
{
// Begin ethernet and server
Ethernet.begin(mac, ip);
server.begin();
}

void loop()
{

EthernetClient client = server.available();
if (client) {
// an http request ends with a blank line
boolean BlankLine = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
// If line is blank and end of line is newline character '\n' = end of HTTP request
if (c == '\n' && BlankLine) {
client.println("HTTP/1.1 200 OK"); // Standard HTTP response
client.println("Content-Type: text/html\n");
client.println("<html><head><META HTTP-EQUIV=""refresh""CONTENT=""5"">\n");
client.println("<title>Arduino Web Server</title></head>");
client.println("<body>\n");
client.println("<h1>Arduino Web Server</h1>");
client.println("<h3>Internal Temperature</h3>");
client.println("Temp C:");
client.println("<br/>");
client.println("Temp F:");
client.println("<br/>");
client.println("<h3>External Temperature</h3>");
client.println("Temp C:");
client.println("<br/>");
client.println("Temp F:");
client.println("<br/>");
break;
}
if (c == '\n') {
// Starting a new line
BlankLine = true;
}
else if (c != '\r') {
// Current line has a character in it
BlankLine = false;
}
}
}
// Allow time for the browser to receive data
delay(10);
// Close connection
client.stop();
}
}





zoomkat

Quote
I connected the lan cable directly to my laptop. No router in between. Is that a problem?


Possibly. Did you configure your laptop to support such a setup?
Google forum search: Use Google Advanced Search and use Http://forum.arduino.cc/index in the "site or domain:" box.

ajsivsan

A week ago i tried the same way and it worked.... and today it did not. 4 hrs passed away just like that..

Then i decided to see alteast if it works as a webClient... i loaded the Twitter program and it worked!!!!

Then i loaded the WebServer program and this time it worked too .....  :smiley-eek:

:smiley-eek-blue:

No idea what went wrong.. but it is working as expected now...

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy