Any help/examples on porting real time data to processing from the Web of satellites or oceans or the environment?
Thanks in advance
Luis
1 Like
There are many examples of using real time data in Processing. Probably the best approach is to connect your sketch to an API (you’ll need the library HTTP Request for Processing and some understanding of XML or JSON) and refresh the data at a set interval of time.
Hello fed.
That was my first approach. Any good example you recomend?
Thanks in advance
Luis
This is a simple sketch/meteo app that I’ve made that uses Openweathermap’s API:
JSONObject json, main;
String APIKEY = "";
String citta, country;
float temp, tempMin, tempMax;
int humidity, pressure;
String unita = "K";
void setup() {
background(0);
size(500, 500);
loadData();
}
void draw() {
}
void keyPressed() {
background(0);
if (key == 'c') {
temp = kelvinToCelsius(main.getFloat("temp"));
tempMin = kelvinToCelsius(main.getFloat("temp_min"));
tempMax = kelvinToCelsius(main.getFloat("temp_max"));
unita = "C";
}
if (key == 'f') {
temp = kelvinToFahrenheit(main.getFloat("temp"));
tempMin = kelvinToFahrenheit(main.getFloat("temp_min"));
tempMax = kelvinToFahrenheit(main.getFloat("temp_max"));
unita = "F";
}
if (key == 'k') {
temp = main.getFloat("temp");
tempMin = main.getFloat("temp_min");
tempMax = main.getFloat("temp_max");
unita = "K";
}
if (key == 'r') {
loadData();
unita = "K";
}
drawData();
}
void loadData() {
json = loadJSONObject("http://api.openweathermap.org/data/2.5/weather?q=Pordenone&APPID="+APIKEY);
citta = json.getString("name");
main = json.getJSONObject("main");
country = json.getJSONObject("sys").getString("country");
temp = main.getFloat("temp");
tempMin = json.getJSONObject("main").getFloat("temp_min");
tempMax = json.getJSONObject("main").getFloat("temp_max");
pressure = json.getJSONObject("main").getInt("pressure");
humidity = json.getJSONObject("main").getInt("humidity");
}
void drawData() {
textSize(40);
text(nfc(temp, 1) + "°" + unita, 10, 50);
textSize(32);
text(citta + ", " + country, 10, 100);
textSize(18);
text("minima: " + nfc(tempMin, 1) +
"\nmassima: " + nfc(tempMax, 1) +
"\numiditĂ : " + humidity + "%" +
"\npressione: " + pressure + "hPa", 10, 150);
}
float kelvinToCelsius(float value) {
return value - 273.15;
}
float kelvinToFahrenheit(float value) {
return (value*9/5) - 459.67;
}
I think you should find your data sources first and then decide how to use it.
2 Likes
Thanks on your example!
Luis