# Real-Time Data from Web

**URL:** <https://discourse.processing.org/t/real-time-data-from-web/11537>\
**Category:** Project Guidance\
**Created:** [May 24, 2019, 9:07am UTC](https://discourse.processing.org/t/real-time-data-from-web/11537 "2019-05-24T09:07:08Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![anon57009815](https://avatars.discourse-cdn.com/v4/letter/a/f19dbf/32.png) [@anon57009815](https://discourse.processing.org/u/anon57009815)\
**Post date:** [May 24, 2019, 9:07am UTC](https://discourse.processing.org/t/real-time-data-from-web/11537/1 "2019-05-24T09:07:08Z")

</div>

Any help/examples on porting real time data to processing from the Web of satellites or oceans or the environment?  
Thanks in advance  
Luis

---

<div class="post-metadata">

**Author:** ![fedpep](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/fedpep/32/52_2.png) [@fedpep](https://discourse.processing.org/u/fedpep)\
**Post date:** [May 25, 2019, 4:18pm UTC](https://discourse.processing.org/t/real-time-data-from-web/11537/2 "2019-05-25T16:18:47Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![anon57009815](https://avatars.discourse-cdn.com/v4/letter/a/f19dbf/32.png) [@anon57009815](https://discourse.processing.org/u/anon57009815)\
**Post date:** [May 26, 2019, 9:51am UTC](https://discourse.processing.org/t/real-time-data-from-web/11537/3 "2019-05-26T09:51:46Z")

</div>

Hello fed.  
That was my first approach. Any good example you recomend?  
Thanks in advance  
Luis

---

<div class="post-metadata">

**Author:** ![fedpep](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/fedpep/32/52_2.png) [@fedpep](https://discourse.processing.org/u/fedpep)\
**Post date:** [May 26, 2019, 3:31pm UTC](https://discourse.processing.org/t/real-time-data-from-web/11537/4 "2019-05-26T15:31:53Z")

</div>

This is a simple sketch/meteo app that I’ve made that uses Openweathermap’s API:

```auto
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.

---

<div class="post-metadata">

**Author:** ![anon57009815](https://avatars.discourse-cdn.com/v4/letter/a/f19dbf/32.png) [@anon57009815](https://discourse.processing.org/u/anon57009815)\
**Post date:** [May 26, 2019, 7:36pm UTC](https://discourse.processing.org/t/real-time-data-from-web/11537/5 "2019-05-26T19:36:19Z")

</div>

Thanks on your example!  
Luis
