PHP script

Download the code from github by clicking Download ZIP. Uncompress the file and find the folder named php

Using an FTP client, upload these files to a web server which runs PHP-- most of them do. You can even run it on a Raspberry Pi on your local network. Be sure to also include the contents of the lib folder. 

This PHP script parses some information from DarkSky.net and takes some of the heavy string processing off the shoulders of the ESP8266.

The script is setup to get the temperature in Fahrenheit and other information in English. If you'd like to change this modify the following lines of code:

$units = 'us';  // Can be set to 'us', 'si', 'ca', 'uk' or 'auto' (see forecast.io API); default is auto
$lang = 'en'; // Can be set to 'en', 'de', 'pl', 'es', 'fr', 'it', 'tet' or 'x-pig-latin' (see forecast.io API); default is 'en'
DarkSky API no longer accepts new signups. Unless you already have one this project will be tricky to complete!

Go to https://darksky.net/dev/ and sign up for a free API key. At the free level there's a pretty generous limit to the number of requests per day you can make, well below what we'll be using. 

It's a good idea to test the PHP script at this point by pointing your web browser to: http://YOUR_DOMAIN_NAME/weather.php?apiKey=APIKEY&lat=40.71&lon=-74&units=us

Alter this URL to point to your PHP script, replacing YOUR_DOMAIN_NAME with the actual domain name hosting your script and replacing APIKEY with the API key you received from forecast.io. This longitude and latitude are for New York City- feel free to change them to get the weather for your location in the world.  NASA has a good tool for finding your longitude and latitude.

If you manage to enter the URL correctly, your web browser should give you a webpage that looks like this:

This guide was first published on Sep 29, 2015. It was last updated on Mar 08, 2024.

This page (PHP script) was last updated on Mar 08, 2024.

Text editor powered by tinymce.