Pages: [1]   Go Down
Author Topic: [Solved] Unable to connect to web server, can't seem to find the problem  (Read 552 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 34
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:

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

}
« Last Edit: February 13, 2013, 10:42:42 pm by JackSac67 » Logged

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

Is this ip in the subnet of your localnet?
Code:
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.  smiley-wink
« Last Edit: February 12, 2013, 07:28:40 am by SurferTim » Logged

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

Quote
edit: Eye Korretd mi spelin misteak.
You misspelled "Korrectd".  smiley-cool
Logged

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

These two statements:
Code:
  pinMode(A3, INPUT);
and
Code:
  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.
Logged

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

Is this ip in the subnet of your localnet?
Code:
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.  smiley-wink

Yes and yes

Quote
These two statements:
Code:
  pinMode(A3, INPUT);
and
Code:
  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?
Logged

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

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

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

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

Pages: [1]   Go Up
Jump to: