Pages: [1]   Go Down
Author Topic: Having trouble connecting to Arduino Webserver  (Read 1311 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
#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();
}
}



Logged

0
Offline Offline
Tesla Member
***
Karma: 145
Posts: 9686
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   smiley-cool

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

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

Pages: [1]   Go Up
Jump to: