EthernetClient "GET" method help

Hi all,

Could someone explain how the GET works in the line below:

client.println("GET /search?q=arduino HTTP/1.0");

this is from an example sketch EthernetClient( ) that I copied from Arduino site. (http://arduino.cc/en/Reference/EthernetClient)

I had uploaded it to my UNO with the line "server[ ] =" pointing to google's ip address but it returned "connection failed". I then tried setting it to my own IP and that returned something that I didn't understand. So I thought that the google IP address was old so I pinged google.ca and got a different IP and used it which returned more than I knew what to do with.

My search for GET lead me all over the place and I wasn't sure how "GET" is actually used in this case. I did come across this link (http://www.scienceprog.com/getting-hands-on-arduino-ethernet-shield/) that looked similar to the above but I'm still not sure how to use it.

Out of curiosity, could I try this in a HTML file that would GET info from something?

Simple examples with what I should expect to get as a result would be helpful at this time.

May thanks for any help
Arne

The "?q=arduino" is called a query string, which you can search for info using google. Below is some client test code you can try to see if your setup works.

//zoomkat 12-08-11
//simple client test
//for use with IDE 1.0
//open serial monitor and send an e to test
//for use with W5100 based ethernet shields

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

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = { 192, 168, 1, 102 }; // ip in lan assigned to arduino
//byte gateway[] = { 192, 168, 1, 1 }; // internet access via router
//byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
byte myserver[] = { 208, 104, 2, 86 }; // zoomkat web page server IP address
EthernetClient client;
//////////////////////

void setup(){

  Ethernet.begin(mac, ip);
  //Ethernet.begin(mac, ip, subnet, gateway);
  Serial.begin(9600); 
  Serial.println("Better client test 12/01/11"); // so I can keep track of what is loaded
  Serial.println("Send an e in serial monitor to test"); // what to do to test
}

void loop(){
  // check for serial input
  if (Serial.available() > 0) //if something in serial buffer
  {
    byte inChar; // sets inChar as a byte
    inChar = Serial.read(); //gets byte from buffer
    if(inChar == 'e') // checks to see byte is an e
    {
      sendGET(); // call sendGET function below when byte is an e
    }
  }  
} 

//////////////////////////

void sendGET() //client function to send/receive GET request data.
{
  if (client.connect(myserver, 80)) {  //starts client connection, checks for connection
    Serial.println("connected");
    client.println("GET /~shb/arduino.txt HTTP/1.0"); //download text
    client.println(); //end of get request
  } 
  else {
    Serial.println("connection failed"); //error message if no client connect
    Serial.println();
  }

  while(client.connected() && !client.available()) delay(1); //waits for data
  while (client.connected() || client.available()) { //connected or data available
    char c = client.read(); //gets byte from ethernet buffer
    Serial.print(c); //prints byte to serial monitor 
  }

  Serial.println();
  Serial.println("disconnecting.");
  Serial.println("==================");
  Serial.println();
  client.stop(); //stop client

}

Thanks zoomkat,

This is what I got:

Better client test 12/01/11
Send an e in serial monitor to test
connected
HTTP/1.1 200 OK
Date: Mon, 13 Feb 2012 00:24:19 GMT
Server: Apache
Last-Modified: Sat, 13 Nov 2010 16:31:40 GMT
Accept-Ranges: bytes
Content-Length: 51
Connection: close
Content-Type: text/plain; charset=UTF-8

Woohoo! Your arduino ethernet client works!
zoomkat
disconnecting.

So where is this info coming from?

I typed in the IP address into Safari's address bar but I get Server Error, 404 - File... not found, etc.

Is it possible to get it info from my system to help understand what's going on?

Arne

from zoomkat
client.println("GET /~shb/arduino.txt HTTP/1.0"); //download text
So is it that 'arduino.txt' is a file in a directory '~shb' and this is located some where on your server?

If this is right, what do I have to do to get this to access a file on my system?

I don't have a server but could I for experimenting have a txt file on my desktop to try accessing?

Arne
I was looking at some books but not sure which areas (as in html, asp, php, etc) to look at?

This is not "file sharing", but is a simple text file on a drive of an apache web server. the arduino sends a web HTTP request, and the server sends the file contents back to the arduino. For testing, download the apache web server and install it on your pc. Google searching for HTTP should provide you with some web protocol info.

Would it work if I was to just connect the arduino to my pc (adhoc like) this is how I had it when I ran the example sketch at the beginning?

Then send a simple request or is a server absolutely necessary?

I would like to keep it as simple as possible, to start getting into apache would bury me quickly.

I got myself going in this direction to see how difficult it would be to get the local temperature off the internet.
Would anybody have done this?

Yahoo offers a free weather service: http://developer.yahoo.com/weather/.

Thanks dhunt
I suppose I would have to "GET" the data and then find what I need and do something useful with it?

Would it look something like this:

client.println("GET /search?q=http://weather.yahooapis.com/forecastrss?w=4118&u=c HTTP/1.0");

I'd recommend installing a copy of wireshark on your PC, then using your browser to send the request and checking the packets in wireshark to see what the get looks like and what the response looks like.

I have wireshark and have played with it but I'm not at that level yet.

It would be helpful to be able to monitor the traffic between my mac and the arduino for now. If this is possible it would help me understand what's going on, maybe.

I find video's very helpful. I have seen the one's for wireshark and cace pilot, very interesting but way over my head.

Thanks for the tip.