Query OpenWeatherMap for current weather info using PHP

openweatherAs part of a wider project (more updates posted shortly) I am working with OpenWeatherMap’s API to obtain current and forecast weather information. This is ultimately going to be displayed on a ‘digital photo frame’ type setup.

OpenWeatherMap API offers results in both XML and JSON format. For my project I have chosen the JSON route, so using the below PHP I am grabbing the weather and outputting strings and an image based on current conditions.

This is very much a work in progress piece of code, and is part of a much larger tutorial which I will be posting up once complete. However, I thought the snippet below may prove useful for visitors just wanting a straight output from OpenWeatherMap.

NB: To use the API’s you’ll need to register for a free API ID, the one in the snippet below is just for example purposes.

Mike Hudson

Mike Hudson is a Lead Cyber Security Analyst living and working in Kingston Upon Hull. With extensive experience in Microsoft and Apple technologies, ranging from desktop OS’s to Server OS’s and hardware. By day working as part of an infrastructure team, and by night ridding the world of IT issues through blog posts..

%d bloggers like this: