They're free, but use at your own risk
The scripts in PHP and Perl 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 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 WXForum.net and Weather-Watch forums as they become available.
This page was updated
Tuesday, 01-Sep-2009 12:30 PM
Using AJAX for near real-time updates with Weather-Display and PHP
Weather-Display software offers a near real-time update capability for the clientraw.txt file (a space-delimited text file of current conditions that's primarily used as a data source for the add-on WD-Live and MesoMapLive Flash displays). The contents of the clientraw.txt file (layout/field meanings and current values can be seen at http://www.tnetweather.com/wd-parser.php and docs in the clientrawdescription.txt in your wdisplay directory).
The clientraw.txt file is updated (if you so select with WD) every 5 seconds or so with most (but not all) the data from your weather staton. You can use this (with AJAX) to update your conditions webpage between regular update times without reloading the entire page in the browser. It does require a 'modern' browser, and that JavaScript be enabled in the browser.
Saratoga-weather.org uses two pages with AJAX updates. The home page and a current conditions sidebar (on left of page) have AJAX-enabled updates. The latter is included in pages that don't have another real-time update already but is omitted for WD-Live, netcam, WU rapid-fire pages since they already show current conditions another way.
I've created a demo file set with a simplified ajax.php page and an ajax-testpage.php page to include it to show how it works on my site. I don't have Weather-Display upload full pages (except for the trends.php page, because it has so many variables in it), but instead have Weather-Display and WeatherLink process small template files to load conditions data into PHP variables as outlined in PHP Weather-Display tags. This makes for reduced FTP upload traffic (since I'm only sending up small pages for inclusion, rather than full pages).
The key to successful use of AJAX is to present the same appearing display to your visitor when JavaScript is not enabled in their browser. AJAX is only available if JavaScript is enabled, since it's a JavaScript technology. If you'll glance at the sample ajax.php file, you'll see two types of code for each condition variable to be updated. The first type is a <span class="ajax" id="ajax..."></span> pair, between the start/end tag is where the JavaScript will write the value on the page. The PHP code to display the condition is contained within the <span></span> tags so the no-JavaScript condition will automatically display the uploaded values from testtags.php. The id="" tags on the <span></span> pairs must be unique on the page, and don't have to start with 'ajax' .. that was just used to let me know what that tag was doing. The class="ajax" tags in the <span></span> are used to enable the 'green flash' of conditions during AJAX updates (and for 2 seconds afterwards).
The bulk of the AJAX work is done by the ajaxWDwx.js script (the same ajaxWDwx.js script as used in the carterlake/AJAX template set). The ajaxWDwx.js script is controlled by several settings inside the source:
// -- begin settings --------------------------------------------------------------------------
var flashcolor = '#00CC00'; // color to flash for changed observations RGB
var flashtime = 2000; // miliseconds to keep flash color on (2000 = 2 seconds);
var reloadTime = 5000; // reload AJAX conditions every 5 seconds (= 5000 ms)
var maxupdates = 0; // Maxium Number of updates allowed (set to zero for unlimited)
// maxupdates * reloadTime / 1000 = number of seconds to update
var clientrawFile = '/clientraw.txt'; // location of clientraw.txt relative to this page on website
var ajaxLoaderInBody = false; // set to true if you have <body onload="ajaxLoader(..."
var imagedir = './ajax-images'; // place for wind arrows, rising/falling arrows, etc.
var useunits = 'E'; // 'E'=USA(English) or 'M'=Metric
var useKnots = false; // set to true to use wind speed in Knots (otherwise
// wind in km/hr for Metric or mph for English will be used.
var useMPS = false; // set to true for meters/second for metric wind speeds, false= km/h
var useMPH = false; // set to true to force MPH for both English and Metric units
var useFeet = false; // set to true to force Feet for height in both English and Metric
var showUnits = true; // set to false if no units are to be displayed
var thermometer = './thermometer.php'; // script for dynamic thermometer PNG image (optional)
// optional settings for the Wind Rose graphic in ajaxwindiconwr as wrName + winddir + wrType
var wrName = 'wr-'; // first part of the graphic filename (followed by winddir to complete it)
var wrType = '.gif'; // extension of the graphic filename
var wrHeight = '58'; // windrose graphic height=
var wrWidth = '58'; // windrose graphic width=
var wrCalm = 'wr-calm.gif'; // set to full name of graphic for calm display ('wr-calm.gif')
// -- end of settings -------------------------------------------------------------------------
The setting for clientrawFile needs to point to the relative URL address of the clientraw.txt file on your website. The setting for imagedir needs to point to the relative URL address of the images (rotating wind arrows, up/down arrows) on your website. The remaining settings can be adjusted to your needs.
Also in the demo package are functions to display a rotating wind arrow (and the arrow icons), and functions to display direction arrows (rising/falling) based on trend info (where available), and a UV word describing the current UV level. The ajax-images directory also contains 30 Northern Hemisphere moon images for use in the Almanac section.
If you're in the Southern Hemisphere, you should replace those moon images with this set of Southern Hemisphere moon images. The weather functions are in both JavaScript and PHP forms.
Version 1.06 now offers three display PHP script sets and an associated test page. The V2.09 version of ajaxWDwx.js script now has all language-specific features collected into a new language settings area for ease in translation to other languages.
ajax-gizmo-testpage Demo
ajax-sidebar-testpage Demo
ajax-dashboard-testpage Demo
I hope you find this explanation helpful. Good luck with your own AJAX project.
Note: This set of scripts is offered for historical purposes only .. the functionality of the ajax-dashboard and gizmo has been incorporated into the WD/AJAX/PHP weather website template sets which are recommended for your use instead of this set of scripts.
AJAX demo package for Weather-Display: [v1.07] download [see version history]
Special thanks goes to 'pinto' (http://www.joske-online.be/clientraw/index.php) and
Tom (carterlake) who together pioneered the AJAX techniques
with Weather-Display and shared it with the world on the Weather-Display forum. My efforts here are based on their work and they have my gratitude for allowing other websites to use it.