Greetings everyone - I'm fairly new to Processing (and programming in general). I'm writing a program that will take an XML feed of weather data, extract the current weather conditions, and return a color based upon the current weather.
I'm having trouble, however, getting the XML feed to update - once the program starts running, it seems to only get data from the XML feed once. When the weather feed updates every hour, the text doesn't update along with it. Ideally, the program will update itself as new information becomes available.
My (admittedly very preliminary) code is below- the if loop has been simplified so that it looks less messy. Is there something that I'm missing re: the XML feed?
thanks for your help!
Code:
import processing.serial.*;
int n;
XMLElement xml;
String cs;
color c;
Serial port;
void setup() {
String feed = (xml weather feed URL) //actual URL removed
PFont font;
size(500,300); //screen size, etc.
background(0);
font = loadFont("Arial-Black-48.vlw");
fill(255);
textFont(font, 13);
String arduinoPort = Serial.list()[2];
port = new Serial(this, arduinoPort, 19200);
xml = new XMLElement(this,feed);
}
void draw() {
background(0);
XMLElement lastreading = xml.getChild("observation_time");
XMLElement weather = xml.getChild("weather");
String reading = lastreading.getContent(); //last reading time
String currweather = weather.getContent(); //current weather
text(reading, 10, 215);
text("Current Weather: "+ currweather, 10, 240);
StringTokenizer st = new StringTokenizer(currweather, "\"<>,.()[] "); //tokenize each element in incoming string
while (st.hasMoreTokens()){
String currentweather =st.nextToken().toLowerCase();
if (currentweather.indexOf("cloudy") >=0) {
c = color(153,51,0);
}
else if (currentweather.indexOf("sunny") >= 0) {
c=color(153,51,17);
}
cs = "#"+hex(c,6);
port.write(cs);
}
delay(60000);
}
catch (Exception ex) {
ex.printStackTrace();
System.out.println("ERROR: "+ex.getMessage());
}