Tested against Ignition versions using python 2.5 (should also work with python 2.4). This document is attached in a cleanly formatted word doc
[ul]1. Download json-py
2. Extract the three .py files (though technically, I believe all you need is json.py) and place them in Ignition’s Python library folder. Additional information on using third party python libraries can be found in this knowledge base article.
3. To get an data from weather underground, you must get an API key. At a minimum, you must setup a free developer’s account with Weather Underground to get an API key (The free version is limited to 10 queries an hour and 200 queries a day) information for doing this can be found via Google searches
[list]a. Click on the ‘Weather underground’ label or open browser and enter the provider address wunderground.com/. Tap the ‘Weather API for developers’ link under the ‘Weather’ tab. Enter your name, e-mail address and password in the ‘Create free account’ form. Tap the ‘Sign Up’ button.
b. Click the link in the confirmation e-mail to confirm your account. Then register on the provider web site with your login and password.
c. Tap the ‘Explore My Options’ button under the ‘API Home’ tab.
d. Select the plan that fits your needs (‘Stratus’ is the free plan) and tap the ‘Purchase Key’ button (this is the free option.
e. Enter your information, N/A can be entered if you don’t have a website
f. Check ‘I agree to the Terms of Service’ flag and tap the ‘Purchase Key’ button.
g. Copy the personal API key for use in the next step.[/ul]
4. Use the following script as a template, replace [YOUR_API_KEY] with your API key from weather underground , [TWO_LETTER_STATE_ABBREVIATION] with your state ID (i.e. TX for Texas), and [NAME_OF_CITY] (i.e. Dallas). Additional variables are listed after the code section.[/list:u]
[code]#Import necessary libraries
#replace these variables with your specific details
apiKey = [YOUR_API_KEY]
weatherState = [TWO_LETTER_STATE_ABBREVIATION]
weatherCity = [NAME_OF_CITY]
#create URL string
urlStr = “http://api.wunderground.com/api/%s/geolookup/conditions/q/%s/%s.json” %(apiKey, weatherState, weatherCity)
#Get data on the selected city
f = urllib2.urlopen(urlStr)
json_string = f.read()
#parse as fully formatted json, it is important to use the .strip() function
parsed_json = system.util.jsonDecode(json_string.strip())
#example to find city, temperature (as Fahrenheit), wind speed, and wind direction
city = parsed_json[‘location’][‘city’]
temp = parsed_json[‘current_observation’][‘temp_f’]
windSpeed = parsed_json[‘current_observation’][‘wind_mph’]
windDir = parsed_json[‘current_observation’][‘wind_dir’]
#Will print the following - Folsom weather: 59.8 °F, wind 5 MPH from the East
print (city + " weather: " + str(temp) + " °F, wind "
+ str(windSpeed) + " MPH from the " + windDir)
If you get error messages make sure that you’ve correctly downloaded and copied json-py to Ignition’s pylib user library
My understanding is that System.util.jsonDecode creates a pyObject, presumably it is a 2 dimensional list and I will refer to it as such, but there might be more, check the weather underground API for more detailed information. All elements listed in this document can be accessed by referencing [Element1_ID][Element2_ID]
The first element of the list will either be [‘location’] or [‘current_observation’]. All the items in the [‘location’] list will give information about the selected city, items in the [‘current_observation’] will give you weather details.
Here are some of the available elements for the [‘location’] list are (and an example of what they’d display):
Available elements for the [‘current_observation’] list are (and an example of what they’d display):
['station_id'] KCAFOLSO25 ['observation_time'] Last Updated on February 9 12:35 PM PST ['observation_time_rfc822'] Thu 09 Feb 2017 12:35:57 -0800 ['observation_epoch'] 1486672557 ['local_time_rfc822'] Thu 09 Feb 2017 12:36:07 -0800 ['local_epoch'] 1486672567 ['local_tz_short'] PST ['local_tz_long'] America/Los_Angeles ['local_tz_offset'] -0800 ['weather'] Rain ['temperature_string'] 58.3 F (14.6 C) ['temp_f'] 58.3 ['temp_c'] 14.6 ['relative_humidity'] 99% ['wind_string'] From the South at 6.3 MPH Gusting to 12.0 MPH ['wind_dir'] South ['wind_degrees'] 180 ['wind_mph'] 6.3 ['wind_gust_mph'] 12.0 ['wind_kph'] 10.1 ['wind_gust_kph'] 19.3 ['pressure_mb'] 1013 ['pressure_in'] 29.93 ['pressure_trend'] - ['dewpoint_string'] 58 F (14 C) ['dewpoint_f'] 58 ['dewpoint_c'] 14 ['heat_index_string'] NA ['heat_index_f'] NA ['heat_index_c'] NA ['windchill_string'] NA ['windchill_f'] NA ['windchill_c'] NA ['feelslike_string'] 58.3 F (14.6 C) ['feelslike_f'] 58.3 ['feelslike_c'] 14.6 ['visibility_mi'] 3.0 ['visibility_km'] 4.8 ['solarradiation'] -- ['UV'] 1 ['precip_1hr_string'] 0.24 in ( 6 mm) ['precip_1hr_in'] 0.24 ['precip_1hr_metric'] 6 ['precip_today_string'] 0.35 in (9 mm) ['precip_today_in'] 0.35 ['precip_today_metric'] 9