AJAX for WeatherLink

AJAX  -  Asynchronous JavaScript And XML

Without going into details, I’ll give you a quick and simple run down on how AJAX works. Two common weather programs, Weather Display and Virtual Weather Station, are able to create some small files every few seconds that contains hundreds of pieces of current and historical weather data in a string. As soon as these files are created, they are ftp'd to the internet host and are over-writing the previous files. This will constantly put fresh data every several seconds where you need it, but now it needs to be quickly deciphered for use. Here is where AJAX comes to play. This AJAX program is simply javascript. It knows the location of every piece of weather data that is in the string of data and makes it an object to use on your web page. The web page can now use javascript to display each object of the weather data from last set of ftp'd files. All of the weather variables on the web page are updated instantly from the last set of ftp'd files whether they have changed or not. This repeated process will update just the weather data about a dozen times a minute without updating the whole page. It's much faster than updating and sending the complete weather page.

This is the ultimate tool for WD and VWS owners. It was conceived by Pinto - http://www.joske-online.be/ and Tom - http://www.carterlake.org/. They pioneered the basic AJAX code. Tom at CarterLake.org and Ken True - Saratoga-weather.org , tailored it to the weather programs and added features. There are several other contributors that helped out to make this an outstanding program.

 

What about AJAX for WeatherLink???

WL is the software program that is packaged with the necessary data logger that connects the weather station to the computer. You can either use WL or spend more money on more software. Most WL users are happy with it while others opt to buy another software package to expand their weather data information. With WeatherLink, there are just over 200 weather tags for you to use and it doesn’t have the ability to produce those stringed weather data files every few seconds. Without those weather data files being generated every several seconds and the lack of weather tags, the AJAX package with the added functions just doesn’t have much to offer.

HOWEVER…  WL can utilize AJAX effectively. Since WL can’t produce a weather data file every few seconds, it can produce one every minute from a template and update your weather data on your web page accordingly. You can use every WL tag available with some limited expandability. How is this done? The same way AJAX for WD and VWS is used. The javascript file that runs these two programs is drastically stripped down to use with WL. Most of the “optional” functions that WD and VWS use are not available but it will do the job of updating your web page weather data every minute.

 

SWITCHING OVER TO AJAX

First off, you will need to consider the following.

  • Whether or not you need to upload your complete web page at regular intervals.
  • PHP capability from your host.
  • Visitors that don't use javascript.

Depending on your web page content, it may be neccessary to keep uploading your complete web page to update other items like web cam pictures, radar graphics, forecasts, etc. If you have PHP, you may not need to upload the page frequently, just the weather data. Importantly, let's not forget the small percentage of visitors that don't use javascript. They do exist and the first time that they don't see the weather data, they will go elsewhere and won't return.

To make things easy for you, there are two plans that you can choose from to suit your needs.

Plan A – If you need to parse your complete weather page at regular intervals and/or PHP is not available.

Plan B – If you no longer need to upload the complete page, just change the weather data, and have php capability.

 

A CLOSER LOOK

Let’s take a look at Plan A. In your weather page template, you will have a tag that looks like this:

<!--outsideTemp-->    A standard WL tag.

That would be replaced with this:

<span class="ajax" id="ajaxoutsideTemp"><!--outsideTemp--></span>

The first part of this, <span class="ajax" id="ajaxoutsideTemp"> invokes the AJAX portion. It is closed by </span>. A corresponding WL tag is in the middle. When javascript is enabled, the WL tag data is disregarded and inserts the fresh AJAX data in its place. If a visitor happens to have javascript disabled, the AJAX data will not display but will now use the WL tag data to report the weather data from the last time the complete weather page was uploaded. Just like it has always worked before. If you normally upload your web page every ten minutes or so, you can still do this and have the weather data updated every minute. Your non-javascript visitors will see your data like they always have before while all other will see the latest data every minute.

Plan B is similar to Plan A. Instead of using a WL tag in the middle, php will be used for non-javascript users. This plan requires a second data template file that creates the php variables and names. It needs to be uploaded every minute like the first data template.

<span class="ajax" id="ajaxoutsideTemp"><?php echo $outsideTemp; ?></span>

Plan B eliminates parsing the complete weather page for non-javascript viewers and gives everybody the latest weather data. Since it uses PHP, your web host must have PHP.

If you are not concerned about the small amount of non-javascript viewers, Plan A would be the choice and you can remove the WL tags in the middle of the spans to cut down your web page size.

Here is another option. If you don't want AJAX but would like to have fresh data every minute, just use the php. The weather data displayed will update when the browser opens the page or gets re-freshed. This would suit both types of javascript viewers.

 

YOUR WEATHER STATION OPTIONS

WeatherLink has a total of 252 weather tags available and due to a "bug" in the software, about 30 of them don't get parsed. A basic weather station with no options can use only 111 of those tags. If you have solar and UV sensors, you will have about 170 tags to choose from. Adding optional sensors to your weather station will boost your choice up to 222 working tags. The point here is the amount of tags in the template file(s) that needs to be ftp'd.

A basic station doesn't need all of the tags parsed so a smaller template file would be quite suitable. The same goes for the station with solar and UV sensors. Why parse all of the optional leaf, soil, temp, and humidity data and upload these over and over when you don't need them?  This adds up after a month of uploading every minute. Plan A  and  Plan B  were split up to reduce the amount tags to parse resulting in smaller template files to upload.

 

DEMO

You can see both of these plans with various tags. They are functional but not being updated.

Plan A
Plan B  (php)

*      Several tags are not yet supported by WL.  These tags do not get parsed and this package is not yet recommended.

**    All the tags that do get parsed with WL

***  Tags for one of each optional accessory. (solar radiation sensor and UV sensor tags included)

**** Standard tags with no options on the weather station

 

Thanks goes to Eric at Anchorage, KY Weather Center for fully testing this on his web site. He reports everything is working very well and WL doesn't freeze up anymore. He also inspired making the data template more flexible to serve as a dual pupose file. By adding several tags to the top of the data file, a weather graphics "sticker" program can use this file for its data and will eliminate ftp'ing the original sticker data file. See this version here and the php version here.

The Bottom Line Disclaimer:

Ken True provides, and fully supports, the AJAX files for WD and VWS free of charge. This program is adapted from one of those javascript files with the removal of most of the functions that he and others put so much time, talent , effort and quality into. The only support for this AJAX for WL program is offered by me. I am not a programmer and you may find errors in it that haven't been spotted yet. Just let me know.

As with any convenience there is an in-convenience. Pushing this data may slow down WL and at times if the conditions are right, it may cause ftp problems. I recommend a program called Fling to get your data files uploaded. If you send data to CWOP, there may be issues and then I recommend VirtualVp and VPLive. It may take a little experimentation and juggling to get your desired output.

My intention is to give an optional tool for WL users. You can use this AJAX program and modify it to suit your needs. I will be glad to help out if you have any questions and I also will take comments.