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
and saratogaWXPHP Twitter account as they become available.
This page was updated
Tuesday, 01-Sep-2009 12:56 PM
Using AJAX for near real-time updates with Virtual Weather Station (VWS)
NOTE: this version has been replaced by the VWS/AJAX HTML templates using Weather Flash .. if you're considering a new installation, please use the Weather Flash version instead... thanks, Ken True - 20-Jul-2007
VWS software offers the capability to frequently output a small set of data files: data.csv and data2.csv. In these files, the current conditions values are set in comma-delimited format as documented in the VWS manual on pages 45-47. The problem to overcome is how to get the data.csv file FTPed to your webserver on a rapid basis -- the current version of VWS doesn't provide that feature. Chris of Cape Coral Online Weather (who helped develop and test these VWS+AJAX code samples) uses Webdrive, a Windows FTP client for this purpose.. you may find another option to FTP the data.csv file needed by these scripts.
Chris had the following guidance on using WebDrive:
Webdrive will send the file based on whatever new file is being generated. Once a new file is created it will transfer the data to the mapped location you tell it to go. So if you're generating a file which in my case is the data.csv file every five seconds, webdrive will send it out every time it's created. This also holds true for all the graphics in VWS and the .htx conversions. It will spit out the data as fast as it created. I highly recommend it for AJAX.
The data.csv file should be updated every 5 seconds or so and FTPed to your website -- it will contain some data from your weather staton. You can use this data.csv file (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.
You should also be aware of a slight difficulty with the seconds field [6] with data.csv currently doesn't return the actual seconds in the time of the upload, so you may want to edit the areas around ajaxtime to omit the seconds from your display. Keep in mind that the first field is [0] in the JavaScript, so [6] = the seventh field in the VWS documentation.
The last caveat is to change with care the JavaScript included in the sample scripts -- I highly recommend using Firefox browser with the WebDeveloper and FireBug plugins -- makes spotting JavaScript errors very easy.
Making AJAX work for your VWS weather website
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 wx.htx or usa.htx files, 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 VWS tag to display the condition is contained within the <span></span> tags so the no-JavaScript condition will automatically display the uploaded values from VWS. 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).
To start the AJAX JavaScript function, you change the <body> tag on the including page to invoke it at page-load time: <body onload="JavaScript: ajaxLoader('data.csv?'+new Date());"> The funny business with the URL 'data.csv?'+new Date() makes the browser avoid cacheing of the data.csv file by pretending it's a CGI.
The ajaxLoader function does the heavy lifting by reading data.csv (using the JavaScript XMLHttpRequest). The comma-delimited data.csv file is sliced up by the JavaScript split command and the appropriate value retrieved from the split array. As each condition is computed (converted to english units) and formatted, it is then updated on the browser by a statement like set_ajax_obs(("ajaxhumidity",humidity); . This small set_ajax_obs function is:
function set_ajax_obs( name, value ) {
// store away the current value in both the doc and the span as lastobs="value"
// change color if value != lastobs
var element = document.getElementById(name);
if (! element) { return; } // don't store if no <span> tag found for this id=
var lastobs = element.getAttribute("lastobs");
element.setAttribute("lastobs",value);
if (value != lastobs) {
element.style.color=flashcolor;
}
element.innerHTML = value;
}
The set_ajax_obs function replaces the direct update of the value on the page so that the new value can be 'remembered' in the 'lastobs="value"' so that only changed values (from last time) can be highlighted with the 'green-flash' like on WeatherUnderground.
At the end of the ajaxLoader function you'll see:
setTimeout("reset_ajax_color('')",flashtime); // change text back to default color after 2 secs
setTimeout("ajaxLoader('data.csv?'+new Date())", 5000); // get new data after 5 secs
The setTimeout("reset_ajax_color('')",flashtime) sets a timer to invoke reset_ajax_color to reset the <span class="ajax"> contents to the default color for the page after 2000ms (2 seconds)..
The
setTimeout("ajaxLoader('data.csv?'+new Date())", 5000); says wait 5000ms (5 seconds) and call ajaxLoader again.
I hope you find this explanation helpful. Take a look at the sample code with markups, and adapt to your own website. Good luck with your own AJAX project.
Note: This sample AJAX script is for demonstration purposes .. if you are building a weather website with VWS and AJAX, I strongly recommend you use the VWS/AJAX HTML templates using WeatherFlash instead of using this demo which uses the data.csv file
AJAX demo package for VWS: [v1.00] demo and download: ZIP | wx.htx | usa.htx [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.
Special thanks also goes to Chris at Cape Coral Online Weather for inspiring the VWS-AJAX project and helping develop/test the code, and offering a platform to view the samples processed by VWS. His homepage uses most of the features of the sample AJAX JavaScript code.
The functions have been tested with IE6-SP2, IE7, Firefox 2.0, Opera 8, Netscape 7 and seem to work ok.
Sample VWS configuration for CSV upload with Webdrive
Chris provided these snapshots of his VWS configuration for export of the data.csv file and VWS tag substitution for the HTML files. Keep in mind you can assign any drive letter (not already assigned) for WebDrive use, and Chris is using Z: for his drive letter.
Then enable the page uploads to the WebDrive in VWS (so VWS will perform tag substitution):