Pages: [1]   Go Down
Author Topic: WiFi sheild - can read HTML from some, but not all sites. Why?  (Read 528 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 14
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have recently purchased an Arduino WiFi shield (and Uno) with the hope of connecting it to a web site hosted by the www.iinet.com domain.  With the help of the great examples on this site, I am able to connect the shield to my router and read content from most of the web.  For example, I can see web content from www.google.com or www.cnn.com.  My problem has to do with the fact the the PHP files I really want to talk to are hosted by my ISP (www.iinet.com) and I can't seem to connect to my pages or to that site at all.  I've tried using the domain name in statements such as:  char server[]="www.iinet.com";  and I've tried the IP address with no luck.  Whenever I run "client.connect( server, 80);" where server describes that domain, all I get back is "false" (no connection). 

I was wondering if someone else could use their shield and try pointing it to "www.iinet.com" to see if you get the same results.  If so, is there a reason why some sites do not result in a successful connection when using client.connect()?  For example, if my ISP redirects the client, will that trigger a "false" when calling client.connect()?  Any help would be appreciated.  I'm looking forward to using my shield to help monitor and control my garden remotely (while I travel), but need to connect to my PHP pages first. 

Thanks!

David

Logged

0
Offline Offline
God Member
*****
Karma: 39
Posts: 988
Get Bitlash: http://bitlash.net
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You're probably not sending a proper Host: header.

Post all your code, in code tags, and you'll get a better answer…

-br
Logged

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

Because the client.connect() returns false, the shield never sends the HTTP head information.  It sure looks to me as though the shield can't connect to that domain over port 80, but I don't understand why.  

Here is the code I've been using (more or less)....  

Note that if I replace "www.iinet.com" with mostly any other domain name, the code works as expected and I can see the HTML write out through the serial port.  So any help connecting to "www.iinet.com" would be appreciated.  The site loads just fine in any conventional web browser.  

Code:
#include <WiFi.h>

char ssid[] = "David's Network";     //  your network SSID (name)
char pass[] = "XXXXXXX";    // your network password
int status = WL_IDLE_STATUS;     // the Wifi radio's status
IPAddress ip;
char server[]="www.iinet.com";
WiFiClient client;

void setup() {
  // initialize serial:
  Serial.begin(9600);

  // attempt to connect using WPA2 encryption:
  Serial.println("Attempting to connect to WPA network...");
  status = WiFi.begin(ssid, pass);

  // if you're not connected, stop here:
  if ( status != WL_CONNECTED) {
    Serial.println("Couldn't get a wifi connection");
    while(true);
  }
  // if you are connected, print out info about the connection:
  else {
    Serial.println("Connected to network");
    
    ip = WiFi.localIP();
    Serial.println(ip);
    
    //if (client.connect( server, 80)) {  
    Serial.println("Trying to make an HTTP request....");  
    if (client.connect( server, 80)) {
      Serial.println("connected to server.");
      client.println("GET HTTP/1.1");
      //client.println("User-Agent: Mozilla/3.0Gold");
      client.println("Host: www.iinet.com");
      //client.println("Connection: close");
      client.println();
    }
    else{
      Serial.println("No connection....");
    }
  }
}

void loop() {
  // if there are incoming bytes available
  // from the server, read them and print them:
  while (client.available()) {
    char c = client.read();
    Serial.write(c);
  }

  // if the server's disconnected, stop the client:
  if (!client.connected()) {
    Serial.println();
    Serial.println("disconnecting from server.");
    client.stop();

    // do nothing forevermore:
    while(true);
  }
}
« Last Edit: May 04, 2013, 04:54:18 pm by Exemel » Logged

0
Offline Offline
God Member
*****
Karma: 39
Posts: 988
Get Bitlash: http://bitlash.net
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Properly forming the GET request might help:

Code:
      client.println("GET / HTTP/1.1");

-br
Logged

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

That might explain why some web sites complained that the request seemed funny, but when this code is pointed at www.iinet.com that line of code is never executed because the "if" condition just above it evaluates to false. 

Your advice will come in very handy once I get this shield connect to this domain.  :-)

David
Logged

0
Offline Offline
God Member
*****
Karma: 39
Posts: 988
Get Bitlash: http://bitlash.net
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

So you're seeing "Connected to network…" followed by "No connection…"?

-br
Logged

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

Here is the exact serial output that results:

Code:
Attempting to connect to WPA network...
Connected to network
192.168.1.5
Trying to make an HTTP request....
No connection....
Logged

0
Offline Offline
God Member
*****
Karma: 39
Posts: 988
Get Bitlash: http://bitlash.net
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

That domain looks normal from here via browser and curl.

Are you familiar with Wireshark?  It might be time to do a little packet sniffing to watch the TCP connection setup that's not working.

-br
Logged

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

No, I'm not familiar with Wireshark. I'm on a Mac, but even if I could run it, based on their example videos, I don't think I have a deep enough understanding of the network protocols to debug this issue.  I was hoping somebody on this forum might be able to point their shield to "www.iinet.com" just to see if they get the same results.  If so, I might be able to work with my ISP, or that might be enough incentive to author my PHP with some other hosting service.

But many thanks billroy for all your helpful suggestions and advice.

David
Logged

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

Works ok with an ethernet shield.
Logged

Pages: [1]   Go Up
Jump to: