Retrieve data from an online API

Good morning,

I would like to insert something in my project that allows me to check the weather of a few places, in real time. So I found an API that does that (it is “Open Weather Map”) and that returns data in JSON, XML or HTML.
The only thing I want is to get the data returned by the API and display it into my Ignition project. But I don’t get how I can do it : scripting something in Python ? Or maybe there’s a component that can display an HTML page ? That would be great, as Open Weather Map can return an HTML page with everything I want : I just need to display it in a corner of one of my project windows.

Thank you in advance! :slight_smile:

Hi Lisa,
You can do it in Python using the system.net.httpGet and system.net.httpPost functions. See the examples in the documentation.

Since you can get it in HTML maybe you could also use the web browser module: marketplace.inductiveautomation. … oduleId=82

Best,

I control my Christmas lights with openweatherdata sun set time. I created this component as an example of how to interact with the api. Most of the code is on the timer.
test1_weather_2015-08-10_1038.proj (14.2 KB)

Hi, Lisa.

As Nick suggested, using system.net.httpGet will retrieve the information for you. There is also systen.util.jsonDecode that will take the json string and objectify it to a dictionary. After that it’s just mining the dictionary for what you want.

The following code will display information for three cities (Morenci is where I grew up. It’s always good to know my parents aren’t getting a tornado…)


response = system.net.httpGet('http://api.openweathermap.org/data/2.5/group?id=5002495,2643743,1850147&units=metric') json=system.util.jsonDecode(response) for city in json['list']: print city['name']+": ", str(city['main']['temp']), city['weather'][0]['description']

Hi,
Thanks a lot for all your answers, that will help me for sure!
Kyle, I can’t open your project because it seems that my designer version is older than yours. Thank you anyway!
I will try to use these Python functions then :slight_smile:
Have a nice day!

Hi Lisa,
Try restoring on a version that is 7.7.5 or later.