Arduino Ethernet, GET requests and Heroku

Hello,

I'm attempting to pull down a string from an app hosted on heroku. I've been attempting to simply Tom Igoe's Twitter example to do so, but am not having much luck. I was wondering whether this was an issue with using heroku, or simply my code. My code, cobbled together from Tom's code and David Mellis' WebClient code, follows:

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


// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = { 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
IPAddress ip(xxx,xxx,x,x);

// initialize the library instance:
EthernetClient client;

const unsigned long requestInterval = 60000;  // delay between requests

char serverName[] = "http://freezing-stream-5123.herokuapp.com/";  // twitter URL

void setup() {
  // reserve space for the strings:
  currentLine.reserve(256);
  tweet.reserve(150);

  // initialize serial:
  Serial.begin(9600);
  // attempt a DHCP connection:
  Serial.println("Attempting to get an IP address using DHCP:");
  if (!Ethernet.begin(mac)) {
    // if DHCP fails, start with a hard-coded address:
    Serial.println("failed to get an IP address using DHCP, trying manually");
    Ethernet.begin(mac, ip);
  }
  Serial.print("My address:");
  Serial.println(Ethernet.localIP());
  // connect to Twitter:
  connectToServer();
}



void loop(){

  if (client.available()){
    char c = client.read();
    Serial.print(c);
  }
}

void connectToServer() {
  // attempt to connect, and wait a millisecond:
  Serial.println("connecting to server...");
  if (client.connect(serverName, 80)) {
    Serial.println("connected");
    Serial.println("making HTTP request...");
    // make HTTP GET request to twitter:
    client.println("GET /");
    client.println("HOST: http://freezing-stream-5123.herokuapp.com/");
    client.println();
  }
  // note the time of this connect attempt:
  lastAttemptTime = millis();
}

Any help would be much appreciated.

Thanks

Not so fast. That code does something. You expect it to do something. If those two somethings were the same thing, you wouldn't be posting. So, it's obvious that they are not the same thing. What either one is, though, is a mystery that you need to clear up first.

PaulS:
Not so fast. That code does something. You expect it to do something. If those two somethings were the same thing, you wouldn't be posting. So, it's obvious that they are not the same thing. What either one is, though, is a mystery that you need to clear up first.

The code is functional in that it attempts to connect to the server. The response I'm getting follows:

At xxx.xxx.x.x
connecting to server...
Attempting to get an IP address using DHCP:
failed to get an IP address using DHCP, trying manually
My address:xxx.xxx.x.x
connecting to server...

So the code just causes the request to hang and never actually connect. I'm wondering whether I'm incorrectly asking for the contents of the domain. It's my understanding that you should be asking for a specific file within the host. I believe I am simply asking for the root of my website by saying

client.println("GET /");
    client.println("HOST: http://freezing-stream-5123.herokuapp.com/");

But I'm not entirely sure. I'm also not entirely sure whether I'm using the correct port. Currently it's:

if (client.connect(serverName, 80)) {

But I'm not sure if port 80 is correct.

I'm not entirely sure what you're asking for me to expand on, but I've tried my best to give a more concise list of my issues.

Additionally, when I check my Heroku logs, this is what I get:

2012-03-30T18:46:37+00:00 heroku[router]: GET freezing-stream-5123.herokuapp.com/favicon.ico dyno=web.1 queue=0 wait=0ms service=2ms status=404 bytes=238

So it appears that the GET request is being received, but is causing my basic app on heroku to give a 404, if I understand this correctly. So, it is very possible that my problem lays on the Heroku side, and not the Arduino side.

Typically, the GET request ends with " HTTP/1.0" or " HTTP/1.1". Yours does not.

The 404 return code should be familiar. If not, look it up.

It means that you (the client) are requesting something that does not exist.

PaulS:
Typically, the GET request ends with " HTTP/1.0" or " HTTP/1.1". Yours does not.

The 404 return code should be familiar. If not, look it up.

It means that you (the client) are requesting something that does not exist.

Yes, I am familiar with what a 404 means, I apologize that I did not make that clear. The 404 is what led me to believe there is something wrong on the server side, rather than on the Arduino side. I have modified the code so that the get request reads: client.println("GET / HTTP/1.1"); as well as HTTP 1.0 and the request still hangs. Additionally, I have changed the code so that serverName referenced in if (client.connect(serverName, 80)) { is the full url, but still the request hangs.

The only other thing that does not look right is the Host line. The protocol to talk to the host is http, but that is not part of the host name. Try loosing the http:// from the host name.

PaulS:
The only other thing that does not look right is the Host line. The protocol to talk to the host is http, but that is not part of the host name. Try loosing the http:// from the host name.

Pretty sure you were right in the first place. It's giving a 404 because there is nothing there for it to find. What I'm outputting from my sample python script isn't a string that is retrievable. Nothing wrong with my Arduino code, just something wrong with what I'm asking it to find.

Thank you for the help.