I'm using an Arduino Uno and ethernet shield to pull xml data from OpenWeatherMap.org . I have the api url to get the xml data, and a library to read that data and find the relevant information, however when I try to connect to the url using the ethernet library, it will not connect. I think it's because of the port needed.
I have tried 80 (for the standard http protocol) and I have downloaded an extension to chrome to find the port used when connecting to the api site (22). However the ethernet will still not connect.
Does anybody have any experience using OWM? or have any idea why the ethernet will not connect?
Thanks
OWMweatherShare.ino (1.79 KB)
system
February 6, 2017, 5:27pm
2
char server[] = "http://api.openweathermap.org/data/2.5/weather?id=2644487&appid=APIkey&mode=xml&units=metric";
That is NOT the name of the server. The server would be api.openweathermap.org .
Thanks for that, i actually got it to connect! Would I need to use a GET call to actually get the xml data then?
Thanks for your help, I have managed to get it to connect, but now can't get it to read any of the data from the GET call.
// 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
char APIkey[33]= "8bb5e7132d2a55ee9386eff704b909b4"; //32 length +1 for ending character
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 extra[]="/data/2.5/weather?id=2644487&appid=8bb5e7132d2a55ee9386eff704b909b4&mode=xml&units=metric";
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
Ethernet.begin(mac,ip, gateway, subnet);
}
Serial.print("Using IP: ");
for (int i=0;i<4;i++){
Serial.print(ip[i]);
Serial.print(".");
}
Serial.println();
Serial.print("Using MAC: ");
for(int m=0;m<6;m++){
Serial.print(mac[m]);
Serial.print(":");
}
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=8bb5e7132d2a55ee9386eff704b909b4&mode=xml&units=metric HTTP/1.1");
client.println("HOST: http://api.openweathermap.org");
client.println();
Serial.println("Connected to XML data.");
char c = client.read();
Serial.println(c);
client.flush();
Serial.println("Disconnected");
}
else
{
Serial.println("Connection failed.");
}
}
void loop()
{
}
OWMweather.ino (1.92 KB)