Hi,
I recently started working with Arduino and I'm very overwhelmed. I have a college project which is fairly difficult and I am in desperate need of help for it as the deadline is in 7 days. What I'm trying to do is control a fan or maybe two based on the wind information that Google's weather API gives. So far I have managed to use an ethernet shield to connect to the API and display the XML results in Arduino's serial monitor. What I want to do now is parse the XML so it reads the wind information specifically, then bases the output to the fan on this wind speed.
Here is the code I have used to connect to the API (actually got it off this forum I think):
#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[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192, 168, 1, 177 };
byte server[] = { 173, 194, 33, 104 }; // Google
// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
Client client(server, 80);
void setup() {
// start the Ethernet connection:
Ethernet.begin(mac, ip);
// start the serial library:
Serial.begin(9600);
// give the Ethernet shield a second to initialize:
delay(1000);
Serial.println("connecting...");
// if you get a connection, report back via serial:
if (client.connect()) {
Serial.println("connected");
// Make a HTTP request:
client.println("GET /ig/api?weather=Kinsale HTTP/1.0");
client.println();
}
else {
// if you didn't get a connection to the server:
Serial.println("connection failed");
}
}
void loop()
{
// if there are incoming bytes available
// from the server, read them and print them:
if (client.available()) {
char c = client.read();
Serial.print(c);
}
// if the server's disconnected, stop the client:
if (!client.connected()) {
Serial.println();
Serial.println("disconnecting.");
client.stop();
// do nothing forevermore:
for(;
;
}
}
That's all well and good but trying to parse that XML, well I have no idea. I tried experimenting with other scripts I found online but to no success. REALLY STUCK. I have only relatively basic understanding of the language, but if something is documented well as it goes along I can follow.
Any help would be appreciated.