Go Down

Topic: [Solved] Unable to connect to web server, can't seem to find the problem (Read 706 times) previous topic - next topic

JackSac67

I want to adjust the background color of a web page by adjusting a pot, but I can't for the life of me figure out why I'm not able to connect to the web server. I just get "Unable to connect to server" in my browser. Here's the code, help point me towards anything missing or that needs revision please.

Code: [Select]


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

byte mac[] = { 0x90, 0xA2, 0xDA, 0x0D, 0x50, 0x9A };
byte ip[] = { 10, 0, 1, 8 };

EthernetServer server(8010);

void setup() {

 pinMode(A3, INPUT);
 
 Serial.begin(9600);
 
 Ethernet.begin(mac, ip);
 server.begin();

}

void loop() {
 
 EthernetClient client = server.available();
 
 int val = analogRead(A3);    //read pot analog input
 
 if (client) {
   
   boolean current_line_is_blank = true;
 
   while (client.connected()) {
   
     if (client.available()) {
       
       char c = client.read();
       int color = map(val, 0, 1023, 0x000000, 0xFFFFFF);    //map the analogRead() values to HEX values for HTML colors
       
       Serial.println(val);    //print em'
       Serial.println(color);
       Serial.println();
       
       if (c == '\n' && current_line_is_blank) {
       
         client.println("HTTP/1.1 200 OK");    //standard HTTP header, a little HTML too
         client.println("Content-Type: text/html");
         client.println();
         client.println("<html><head><title>");
         client.println("Change pot to change color!");
         client.println("</title><body bgcolor=");
         client.print(color);
         client.println(">");
         client.println("<h1>Hello, World</h1>");
         client.println();
         client.print("</body></html>");
       
       }
       
       if (c == '\n') {
       
         current_line_is_blank = true;
       
       } else if (c != '\r') {
       
         current_line_is_blank = false;
       
       }
     
     }
   
   }
   
   delay(1);
   client.stop();
 
 }

}

SurferTim

#1
Feb 12, 2013, 01:09 pm Last Edit: Feb 12, 2013, 01:28 pm by SurferTim Reason: 1
Is this ip in the subnet of your localnet?
Code: [Select]
byte ip[] = { 10, 0, 1, 8 };

Are you using the port with it in your web browser?
http://10.0.1.8:8010

edit: Eye Korretd mi spelin misteak.  ;)

PaulS

Quote
edit: Eye Korretd mi spelin misteak.

You misspelled "Korrectd".  8)

PaulS

These two statements:
Code: [Select]
  pinMode(A3, INPUT);
and
Code: [Select]
  int val = analogRead(A3);    //read pot analog input
do not go together.

Analog pins are input only. They can not be set to output, nor do they have pullup resistors. So, the pinMode() command is completely unaware that they exist. You are diddling with the digital nature of that pin, which you don''t use. So, don't diddle with it.

JackSac67


Is this ip in the subnet of your localnet?
Code: [Select]
byte ip[] = { 10, 0, 1, 8 };

Are you using the port with it in your web browser?
http://10.0.1.8:8010

edit: Eye Korretd mi spelin misteak.  ;)


Yes and yes

Quote
These two statements:
Code: [Select]

  pinMode(A3, INPUT);

and
Code: [Select]

  int val = analogRead(A3);    //read pot analog input

do not go together.

Analog pins are input only. They can not be set to output, nor do they have pullup resistors. So, the pinMode() command is completely unaware that they exist. You are diddling with the digital nature of that pin, which you don''t use. So, don't diddle with it.
Right, that was my bad. But how would this have an effect on my problem?

SurferTim

Can you ping the Arduino from your computer?

Do you have a uSD card in the slot on the shield? If so, remove it and try again.

Try adding this to your setup() function. Maybe something with the SPI isn't working.
Code: [Select]
  Ethernet.begin(mac, ip);
  Serial.print("IP = ");
  Serial.println(Ethernet.localIP());

  server.begin();

Does it show "IP = 10.0.1.8"? If it shows anything else, like "IP = 0.0.0.0", it may not be working.

JackSac67

Never mind, I've fixed it. Turns out my router was reset with an ethernet connection already established on one of its ethernet ports and it screwed up the whole system. Just had to unplug and plug back in.

Go Up