I'm using an Arduino Uno and ethernet shield to pull xml data from OpenWeatherMap.org. I have the api link and a key, and it all works fine on the web browser. My code is below, however when I get to reading the response from the GET command, all i get is "ΓΏ", not anything I would expect.
I can connect to the arduino when using it as a server, and I can ping it from command prompt so I know it is on the network and the board is not at fault, so it must be something with my code. I have followed the tutorial on the arduino site and loaded the example to GET data, but this also does not work, all I get is a "did not connect" message.
Can someone please look over my code and see what I am doing wrong?
EDIT: I have added the extra loop to print all the xml data, however the program still gets stuck on the while(!client.available());
. If i comment it out, I get to the "waiting for server response" but never any further than that. I have checked that the arduino si on the same subnet mask as all the other devices in the network.
// Based on:
// Read Yahoo Weather API XML
// 03.09.2012
// http://forum.arduino.cc/index.php?topic=121992.0
//
#include <SPI.h>
#include <Ethernet.h>
#include <TextFinder.h>
int cityID=2644487; //Lincoln, UK
byte mac[] = {0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02};
byte ip[] = {192, 168, 1, 89};
byte gateway[] = {192, 168, 1, 254};
byte subnet[] = {255, 255, 255, 0};
//Open weather map xml
char server[] = "http://api.openweathermap.org";
int port = 80; //usually 80 for http.
char APIkey[33] = "HIDDENAPIKEY";
EthernetClient client;
char temperature[30];
void setup()
{
pinMode(10, OUTPUT);
digitalWrite(10,HIGH);
Serial.begin(9600);
Serial.println("Initialising...");
// Start Ethernet
if(!Ethernet.begin(mac)){//if DHCP does not automatically connect
Serial.println("Invalid Connection");
}
Serial.println("");
Serial.print("Connecting to OWM server using cityID: ");
Serial.println(cityID);
Serial.print("Using API key: ");
Serial.println(APIkey);
if (client.connect(server,port))
{
client.println("GET /data/2.5/weather?id=2644487&appid=HIDDENAPIKEY&mode=xml&units=metric HTTP/1.1");
client.println("HOST: api.openweathermap.org");
client.println();
Serial.println("Connected to XML data.");
while(!client.available()); //wait for client data to be available
Serial.println("Waiting for server response...");
while(client.available()){
char c = client.read();
Serial.println(c);
}
}
}
void loop()
{
}