We use cookies to personalise content and ads, to provide social media features and to analyse our traffic. We also share information about your use of our site with our social media, advertising and analytics partners who may combine it with other information that you've provided to them or that they've collected from your use of their services.

Weather data and forecast

przykład wizualizacji pogodyNowadays when one wants to check the weather - instead of looking through the window, they type in the address of The Weather Chanel’s web page or look at the MSN Weather gadget. A PLC visualization should also present information about current and the expected weather.

Below you will find a description of a simple ‘plugin’, which supports obtaining and presenting information from Yahoo Weather.

The code is inspired by and partially based on James Fleeting's Simple Weather plugin.  In his plugin the weather forecast is limited to one day.  It made me write an inferior but a new code...

The easiest and the quickest way to see it is by downloading the example file

The plugin makes avaliable 2 functions:

$.GetCurrentWeather()

The functions downloads information about the current weather at the requested location.  Handling of the data must take place within the success function declared when the GetCurrentWeather() is called.

Parameters:

  • location - default 'PLXX0029', the location for which the data is to be downloaded.  To find the code of your town check out www.edg3.co.uk, or simply google: "yahoo weather code",
  • unit - default 'c'; possible 'c' or 'f'

Returned data:

  • weather.city
  • weather.wind_speed
  • weather.wind_direction
  • weather.humidity
  • weather.pressure
  • weather.rising - (presentation of the pressure change in a form of an arrow)
  • weather.visibility
  • weather.sunrise
  • weather.sunset
  • weather.code - (to be used when downloading the weather-describing image)
  • weather.temp
  • weather.text - (weather status descritpion)
  • weather.date

Example 1:

$.GetCurrentWeather({
	location: 'GMXX0007',
	success: function(weather) {
		alert(weather.visibility)
	}
});

When the function is called the weather for Berlin (GMXX0007) will be checked and the information about visibility will be displayed.

$.GetWeatherforecast()

Downloads information about the 5-day weather forecast (including the current day) at the requested location.  Handling of the data must take place within the success function declared when the GetCurrentWeather() is called.

 Parameters:

  • location - default 'PLXX0029', the location for which the data is to be downloaded.  To find the code of your town check out www.edg3.co.uk, or simply google: "yahoo weather code"

Returned data: 

The data received from Yahoo WEather are stored in an array forecast[..].  Data for the current day is to be found in  forecast[0], for day 4 in forecast[4].  For each table element the folowing data is available:

  • forecast[i].code - (to be used when downloading the weather-describing image)
  • forecast[i].date
  • forecast[i].day - (week day)
  • forecast[i].high 
  • forecast[i].low
  • forecast[i].text - (weather status description)

 Przykład 1:

$.GetWeatherForecast({
	location: 'FRXX0076',
	success: function(forecast) {
		alert(forecast[0].text)
	} //End of the success function
});

When the function is called the weather for Paris(FRXX0076) will be checked and the current weather descritpnion will be displayed.

Here is the link to the file with examples