The scripts referenced here are used in the operation of this weather station, and may be freely copied and used to support your station. Please note that you use these scripts at your own risk. No warranty is expressed or implied. I accept no liability for any damages that may ensue from their use.
You will need to configure them for your own particular weather station website. A RSS Feed is available to help keep you informed on updates to the scripts.
A Version History is available -- check back from time to time to see if there are updates to scripts you have downloaded earlier.
Announcements of version updates and new scripts are made on
and saratogaWXPHP Twitter account as they become available.
This script will read the HTML from the Environment Canada Lightning Danger Map page (cached) and download/cache the lightning map images as .png files on your website. Since the EC uses lightning graphic names with embedded timestamps, this script offers one of the few ways that weather enthusiasts can include EC lightning map images in their own websites.
The ec-lightning.php script uses a subdirectory (./radar/ default) to store the contents of the EC lightning HTML pages and the current lightning graphics. For proper operation of the script, you need to ensure that the cache directory is writable by PHP scripts. A simple test script is included to check this (ec-lightning-cachetest.php).
If present, the script will load lightning map images from the 'AAA' lightning site. The available lightning maps are:
id=NAT - National lightning (script default $lightningID) id=PAC - Pacific region lightning id=WRN - Prairies region lightning id=ONT - Ontario region lightning id=QUE - Quebec region lightning id=ATL - Atlantic region lightning
(Default) Text is in English..
Text is in French .
Don't start the animation when the page is loaded. Viewer must press play-stop button to start animation.
Return a 1/4 size static image of the latest lightning selected.
This is for use in an <img> statement on your page like this:
alt="lightning" title="lightning" />
See example 1 below for usage.
Note: the small lightning map images are width="290" and vary in height.
For webmaster help with debugging the setup/configuration of the script, the following parameters may also be used:
Forces refresh of EC lightning page and lightning map images .
Settings inside the script
If you create a writable /lightning subdirectory in the document root of your webserver, then the only settings you should change are $siteID and $defaultLang.
// --------- start of settings ----------
// Go to http://weather.gc.ca/lightning/index_e.html
// Click on the desired area page.
// You should see a lightning page with an url like
// copy the three letter area id=XXX into $lightningID = 'XXX'; below
$lightningID = 'NAT'; // set to default Site for lightning (same as id=xxx on EC website)
// // available sites: NAT ARC PAC WRN ONT QUE ATL
$defaultLang = 'en'; // set to 'fr' for french default language
// // set to 'en' for english default language
$lightningCacheName = 'ec-lightning.txt'; // note: will be changed to -en.txt or
// -fr.txt depending on language choice and stored in $lightningDir
$lightningDir = './radar/'; // directory for storing lightning-XXX-0.png to lightning-XXX-6.png images
// note: relative to document root.
$lightningWidth = 620; // width of images to output in pixels. default=620
$refetchSeconds = 300; // look for new images from EC every 5 minutes (300 seconds)
// NOTE: EC may take up to 20 minutes to publish new images
$noLightningMinutes = 25; // minutes to wait before declaring the image site as 'N/O -not operational'
$aniSec = 1; // number of seconds between animations
$charsetOutput = 'ISO-8859-1'; // default character encoding of output
// ---------- end of settings -----------
Example 1 - Current default lightning small image
<img src="http://saratoga-weather.org/ec-lightning.php?imgonly=Y" width="290" height="240"
alt="Latest Canada lightning from Environment Canada"
title="Latest Canada lightning from Environment Canada" />
If you are NOT already using the ec-radar.php script, then create a new ./radar/ directory on the webserver one directory below where you placed the script.
Upload ec-lightning-cachetest.php script to the chosen directory from step 1 and run the program from your browser.
If the ec-lightning-cachetest.php reports success in writing the file, finding the needed legendLightning.png and that GD is installed, then proceed to step 4.
If you have error messages appearing, then you'll have to fix the problem on your webserver (by changing the permissions on the ./radar/ directory to 777 on Linux/Unix systems, or allowing 'all' to read/write/create on IIS system). The ec-lightning.php program requires the use of cache files, so you'll have to get a clean run on ec-lightning-cachetest.php to have ec-lightning.php run successfully.