Author Topic: WD + PHP + AJAX with Wunderground-style 'green flash'  (Read 22418 times)

0 Members and 1 Guest are viewing this topic.

Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 9722
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
WD + PHP + AJAX with Wunderground-style 'green flash'
« on: November 23, 2006, 01:27:32 AM »
Recently, I added a 'green flash' feature to my AJAX/PHP pages that looks a bit like what WeatherUnderground shows for Rapid-Fire updates (text turns green when updated, then returns to base color after 2 seconds).  It's not quite smart enough to flash only the changed values yet, but I'm working on that too.  I've also reformatted the display to not require <noscript> around the PHP for the conditions (the AJAX replaces the values when it updates), so the page shows the same (except for time) with Javascript enabled or disabled in the browser.

I've updated the AJAX/WD scripts page at http://saratoga-weather.org/scripts-WD-AJAX.php and included a brief explanation of how it works and a sample set of files in the V1.01 .zip to play with.

It's based on my current-ajax.php that's used throughout my site to provide a current conditions sidebar.  My homepage was also updated with this AJAX code too.

It has rising/falling arrow graphics (both PHP and JavaScript) and wind direction arrows (both PHP and JavaScript), along with a decoder ring for UV conditions with the color code for the conditions displayed.

My special thanks again goes to pinto and carterlake for their pioneering work on AJAX and WD for current conditions displays -- without them, this sample set wouldn't have been possible.  Thanks also to beeker425 on the WD forum for a very succinct wind degrees converter JavaScript.

Please note that the samples are PHP-dependent .. to use AJAX with html-only sites, you'll need to use the templates provided by carterlake.

Best regards,
Ken
Ken True/Saratoga, CA, USA main site: saratoga-weather.org
Davis VP1+ FARS, Blitzortung RED, GRLevel3, WD, WL, VWS, Cumulus, Meteobridge
Free weather PHP scripts/website templates - update notifications on Twitter saratogaWXPHP

Offline anchorageweather

  • Forecaster
  • *****
  • Posts: 449
    • http://eetee.us/station/station.php
Re: WD + PHP + AJAX with Wunderground-style 'green flash'
« Reply #1 on: November 23, 2006, 06:56:12 AM »
That is very cool!  This AJAX script might finally force me to breakdown and get Weather-Display. :wink:

This is NOT a criticism mind you, but, Do you worry that until you finalize the script to turn only the changed value green, that some  new visitors might just think the info is "flashing"?

P.S. Got my quake page changed.  THANKS! for the update.  Your site is awesome!
South of the Tracks, Anchorage, KY

Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 9722
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: WD + PHP + AJAX with Wunderground-style 'green flash'
« Reply #2 on: November 23, 2006, 01:11:08 PM »
It just occurred to me that maybe it would be easier for folks to incorporate 'green-flash' into their existing AJAX pages if I just said what needed to be changed on your existing page, so here's what you can do to add the 'green-flash' effect:

First, change all of the <span id="..."> tags used for AJAX substitution in your page (that you want to 'green-flash') to also have a name="ajax" tag so something like
Code: [Select]
<span id="ajaxtemp"> becomes
Code: [Select]
<span name="ajax" id="ajaxtemp">

Second, copy this
Code: [Select]
// --- added flash-green on data update functions from saratoga-weather.org

var ie4=document.all;

function getElementsByName_iefix(tag, name) {
     
     var elem = document.getElementsByTagName(tag);
     var arr = new Array();
     for(i = 0,iarr = 0; i < elem.length; i++) {
          att = elem[i].getAttribute("name");
          if(att == name) {
               arr[iarr] = elem[i];
               iarr++;
          }
     }
     return arr;
}

function set_ajax_color( usecolor ) {
    if (ie4) {
//     eval("document.all.content"+y).style.display="none";
      var elements = getElementsByName_iefix("span","ajax");
    } else {
      var elements = document.getElementsByName("ajax");
    }
 var numelements = elements.length;
//  alert("contract_all: content"+y+" numelements="+numelements);
 for (var index=0;index!=numelements;index++) {
         var element = elements[index];
element.style.color=usecolor;
      }
}


// --- end of flash-green functions
before the
Code: [Select]
// main AJAX routine .. load and format clientraw.txt
function ajaxLoader(url) {
  if (document.getElementById) {
    var x = (window.ActiveXObject) ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest(url);
  }
lines.


Then add these two lines
Code: [Select]

    set_ajax_color('#00CC00'); // change all the ajax text to green
    setTimeout("set_ajax_color('')",2000); // change text back to default color after 2 secs
 
just above the
Code: [Select]

    setTimeout("ajaxLoader('clientraw.txt?'+new Date())", 5000); // get new data after 5 secs
  }
} // end ajaxLoader function


Then your existing template should work with 'green flash'.

And yes, it is a bit cheesey to have it ALL flash green.. not quite as bad and annoying as the dreaded <blink> tag  :lol:  -- it will be a major refit to remember prior values and flash only when a change is spotted.. I'll work on that over the next week.   Meanwhile, you can green-flash only the tags you desire by adding the name="ajax" tag inside the <span> for the AJAX substitution.

Best regards,
Ken
Ken True/Saratoga, CA, USA main site: saratoga-weather.org
Davis VP1+ FARS, Blitzortung RED, GRLevel3, WD, WL, VWS, Cumulus, Meteobridge
Free weather PHP scripts/website templates - update notifications on Twitter saratogaWXPHP

Offline CNYWeather

  • Forecaster
  • *****
  • Posts: 2321
    • CNYWeather
Re: WD + PHP + AJAX with Wunderground-style 'green flash'
« Reply #3 on: November 23, 2006, 03:20:35 PM »
Thanks to Ken's help, here an example for you to see:


http://www.cnyweather.com


This AJAX stuff is really neat. Been a long time fanboy of
FrontPage, but with this setup, all you need to upload if you're
using WD is wx30.html and clientraw. No more need to upload
every page.

 :D
Tony




Offline weatheroz

  • Senior Contributor
  • ****
  • Posts: 221
    • http://www.jimboombaweather.com
Re: WD + PHP + AJAX with Wunderground-style 'green flash'
« Reply #4 on: November 23, 2006, 09:28:22 PM »
Quote from: "kenmtrue"
It just occurred to me that maybe it would be easier for folks to incorporate 'green-flash' into their existing AJAX pages if I just said what needed to be changed on your existing page, so here's what you can do to add the 'green-flash' effect:


Just tried to upgrade it and noticed that in Internet Exploder that it comes up with an error when I fiddle with the temp section of it.

Here's what I've changed :-
Code: [Select]

temp = x.responseText.split(' ')[4];
document.getElementById("ajaxtemp").innerHTML =  temp;
templast = x.responseText.split(' ')[90];
document.getElementById("ajaxtemparrow").innerHTML =
  genarrow(temp, templast, '',
'Warmer %s&deg;C than last hour.',
'Colder %s&deg;C than last hour.');


However if I keep your conversion stuff in there, but change slight to this then it does not come up with the error :-
Code: [Select]

temp = (1 * x.responseText.split(' ')[4]) + 0;
document.getElementById("ajaxtemp").innerHTML =  temp;
templast = (1 * x.responseText.split(' ')[90]) + 0;
document.getElementById("ajaxtemparrow").innerHTML =
  genarrow(temp, templast, '',
'Warmer %s&deg;C than last hour.',
'Colder %s&deg;C than last hour.');


But this 'claytons' conversion seems pretty stupid. :)
Brendan,
vk4blp
IRLP 6857 Echolink 672767


Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 9722
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: WD + PHP + AJAX with Wunderground-style 'green flash'
« Reply #5 on: November 24, 2006, 12:24:00 AM »
That is strange, OZ.  I've tried the ajax-testpage.php (and my site homepage/ pages with sidebar) using IE6-SP2, IE7, Firefox 2.0, Opera 8, and Netscape 7.1 with no errors indicated.

Which version of IE are you running?  What is the specific error message you get with the original code?

I don't know why adding a (1 * x.responseText.split(' ')[4]) + 0; would make a difference (maybe in treating it as math instead of characters?)

Puzzled,
Ken
Ken True/Saratoga, CA, USA main site: saratoga-weather.org
Davis VP1+ FARS, Blitzortung RED, GRLevel3, WD, WL, VWS, Cumulus, Meteobridge
Free weather PHP scripts/website templates - update notifications on Twitter saratogaWXPHP

Offline weatheroz

  • Senior Contributor
  • ****
  • Posts: 221
    • http://www.jimboombaweather.com
Re: WD + PHP + AJAX with Wunderground-style 'green flash'
« Reply #6 on: November 24, 2006, 01:30:26 AM »
Quote from: "kenmtrue"
That is strange, OZ.  I've tried the ajax-testpage.php (and my site homepage/ pages with sidebar) using IE6-SP2, IE7, Firefox 2.0, Opera 8, and Netscape 7.1 with no errors indicated.

Which version of IE are you running?  What is the specific error message you get with the original code?

I don't know why adding a (1 * x.responseText.split(' ')[4]) + 0; would make a difference (maybe in treating it as math instead of characters?)

Puzzled,


And you know what is more puzzling is now it is not coming up with any errors !!! .... got me stuffed what's going on there.
Brendan,
vk4blp
IRLP 6857 Echolink 672767


Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 9722
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: WD + PHP + AJAX with Wunderground-style 'green flash'
« Reply #7 on: November 25, 2006, 03:15:48 PM »
I've updated the sample instructions and sample file set for AJAX 'green-flash' for changed conditions only at http://saratoga-weather.org/scripts-WD-AJAX.php and added a section there on how to update your current AJAX template set to use the new green-flash code.

The bulk of the mod is to use a small function to update the page (instead of changing innerHTML directly).  The function (set_ajax_obs) will retrieve the prior value, set the new value and change the color if prior != current.  The prior value is stored as an attribute in the span tag as 'lastobs="value"' by the JavaScript setAttribute function.

Here's the revised instructions for how to fit 'green-flash-on-change' into your WD AJAX page:


First, change all of the <span id="..."> tags used for AJAX substitution in your page (that you want to 'green-flash') to also have a name="ajax" tag so something like
Code: [Select]
<span id="ajaxtemp"> becomes
Code: [Select]
<span name="ajax" id="ajaxtemp">

Second, copy this
Code: [Select]
// --- added flash-green on data update functions - saratoga-weather.org  24-Nov-2006
// -- begin settings
var flashcolor = '#00CC00'; // color to flash for changed observations
var flashtime  = '2000';    // miliseconds to keep flash color on (2000 = 2 seconds);
// -- end of settings

var ie4=document.all;

function getElementsByName_iefix(tag, name) {
     
     var elem = document.getElementsByTagName(tag);
     var arr = new Array();
     for(i = 0,iarr = 0; i < elem.length; i++) {
          att = elem[i].getAttribute("name");
          if(att == name) {
               arr[iarr] = elem[i];
               iarr++;
          }
     }
     return arr;
}

function reset_ajax_color( ) {
// reset all the <span name="ajax"...> styles to have no color override
    if (ie4) {
      var elements = getElementsByName_iefix("span","ajax");
    } else {
      var elements = document.getElementsByName("ajax");
    }
 var numelements = elements.length;
 for (var index=0;index!=numelements;index++) {
         var element = elements[index];
    element.style.color='';
 
      }
}

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);
var lastobs = element.getAttribute("lastobs");
element.setAttribute("lastobs",value);
if (value != lastobs) {
          element.style.color=flashcolor;
}
element.innerHTML =  value;
}
// --- end of flash-green functions

before the
Code: [Select]
// main AJAX routine .. load and format clientraw.txt
function ajaxLoader(url) {
  if (document.getElementById) {
    var x = (window.ActiveXObject) ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest(url);
  }
lines.


Then add this line
Code: [Select]

    setTimeout("reset_ajax_color()",flashtime); // change text back to default color after 2 secs
 
just above the
Code: [Select]

    setTimeout("ajaxLoader('clientraw.txt?'+new Date())", 5000); // get new data after 5 secs
  }
} // end ajaxLoader function


Now the hard part.. you have to replace all of your lines in the JavaScript with assignment of .innerHTML with a call to the set_ajax_obs function to enable the green-flash to work.  So a line like this in the JavaScript
Code: [Select]
document.getElementById("ajaxgust").innerHTML = gust.toFixed(1); would be changed to
Code: [Select]
set_ajax_obs("ajaxgust",gust.toFixed(1));


Then your existing template should work with 'green flash' for changed conditions.

I did add a little feature - an '@' in front of the date/time stamp that ALWAYS turns green when the AJAX script has retrieved data.  It's nice to see the script is working even when WD clientraw update is pausing for main ftp update :-)

You can add this feature to your template too by adding
Code: [Select]
<span name="ajax" id="ajaxindicator"><strong>@</strong></span>&nbsp;&nbsp; in the HTML of the page where you'd like the indicator to appear, then add
Code: [Select]
       document.getElementById("ajaxindicator").style.color = flashcolor; just before the
Code: [Select]

   }
    }
    x.open("GET", url, true);
    x.send(null);

//get all of them every minute = 5000 milliseconds
//edit the location of your clienraw.txt twice!! (here and in the body onload)
setTimeout("reset_ajax_color()",flashtime); // change text back to default color
    setTimeout("ajaxLoader('clientraw.txt?'+new Date())", 5000); // get new data after 5 secs
  }
} // end ajaxLoader function


My homepage and conditions sidebar have been updated with green-flash-on-change.

The functions have been tested with IE6-SP2, IE7, Firefox 2.0, Opera 8, Netscape 7 and seem to work ok.

Best regards,
Ken
Ken True/Saratoga, CA, USA main site: saratoga-weather.org
Davis VP1+ FARS, Blitzortung RED, GRLevel3, WD, WL, VWS, Cumulus, Meteobridge
Free weather PHP scripts/website templates - update notifications on Twitter saratogaWXPHP

Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 9722
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: WD + PHP + AJAX with Wunderground-style 'green flash'
« Reply #8 on: November 25, 2006, 03:40:24 PM »
:roll:   I should have checked the XHTML 1.0-Strict docs more closely.

http://www.w3.org/TR/xhtml1/#h-4.8 does say "Note that in XHTML 1.0, the name attribute of these elements is formally deprecated, and will be removed in a subsequent version of XHTML."

So.. I'll be issuing a subsequent version that doesn't use the name="ajax" attribute in it.  For folks using plain HTML 4, it should be fine and will render correctly in browsers, but get spotted by the validator.w3.org compliance checker for XHTML 1.0-Strict.

Thanks for pointing that out krelvinaz!

Best regards,
Ken
Ken True/Saratoga, CA, USA main site: saratoga-weather.org
Davis VP1+ FARS, Blitzortung RED, GRLevel3, WD, WL, VWS, Cumulus, Meteobridge
Free weather PHP scripts/website templates - update notifications on Twitter saratogaWXPHP

Offline carterlake

  • Senior Contributor
  • ****
  • Posts: 243
    • CarterLake.org
Re: WD + PHP + AJAX with Wunderground-style 'green flash'
« Reply #9 on: November 25, 2006, 06:33:07 PM »
Yeehaw!

Check out the main page... http://www.carterlake.org/

Davis VP2 6153; Weather Display (LIVE w/ Ajax); Quickcam for Notebooks Pro; Boltek w/ Nexstorm; GRLevel3; live NOAA Radio

Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 9722
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: WD + PHP + AJAX with Wunderground-style 'green flash'
« Reply #10 on: November 25, 2006, 06:54:26 PM »
Thanks to krelvinaz's gentle nudge, I've reworked the code so it's XHTML 1.0-Strict compliant.  I'm just finishing up the packaging and docs on my scripts page, so stand by for the (hopefully final) version in an hour or so.

The major change with the new version is to use 'class="ajax"' attributes instead of 'name="ajax"' attributes as the markers on the <span id="ajax..."> tags.  That puts the XHTML 1.0-Strict validator at ease.  To find those tags with the class="ajax" attribute involved rewriting two functions and finding (and handling) all the silly differences in JavaScript between IE6-SP2, IE7, Firefox 2.0, Navigator 7 and Opera 8.  Sigh..  I think I've found the quirks and now to documentation and packaging.

Hang in there for V1.03 shortly :-)

Best regards,
Ken
Ken True/Saratoga, CA, USA main site: saratoga-weather.org
Davis VP1+ FARS, Blitzortung RED, GRLevel3, WD, WL, VWS, Cumulus, Meteobridge
Free weather PHP scripts/website templates - update notifications on Twitter saratogaWXPHP

Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 9722
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: WD + PHP + AJAX with Wunderground-style 'green flash'
« Reply #11 on: November 25, 2006, 07:50:37 PM »
EDITED:  added one line to set_ajax_obs to avoid JavaScript errors trying to update when a <span id="ajax..." class="ajax"> is missing in the HTML.
EDITED:  reflects V1.04 code with error checking
---------------------------------------------------------------------------
Whew!  Verstion 1.03 with XHTML 1.0-Strict compliant code is now available and tested with IE6-SP2, IE7, Firefox 2.0, Navigator 7, and Opera 8.  It also passes the validator at
http://validator.w3.org/check?uri=http%3A%2F%2Fsaratoga-weather.org%2Fajax-testpage.php

Download from http://saratoga-weather.org/scripts-WD-AJAX.php (look near the middle of the long page for the download link.

I've updated the sample instructions and sample file set for AJAX 'green-flash' for changed conditions only and added a section there on how to update your current AJAX template set to use the new green-flash code.

The bulk of the mod is to use a small function to update the page (instead of changing innerHTML directly).  The function (set_ajax_obs) will retrieve the prior value, set the new value and change the color if prior != current.  The prior value is stored as an attribute in the span tag as 'lastobs="value"' by the JavaScript setAttribute function.  Then a timer-driven reset_ajax_color('') routine locates all the <span class="ajax"> tags and removes the green color after 2 seconds (adjustable).

Note:  if you'd been an early adopter, and already changed your <span id="ajax..."> tags to have 'name="ajax", you'll have to change them again (sorry) to "class="ajax" and remove the 'name='.  And.. copy in the new main flash-green code below. This makes it XHTML 1.0-Strict compliant.


Here's the revised instructions V1.03 for how to fit 'green-flash-on-change' into your WD AJAX page:


First, change all of the <span id="..."> tags used for AJAX substitution in your page (that you want to 'green-flash') to also have a class="ajax" tag so something like
Code: [Select]
<span id="ajaxtemp"> becomes
Code: [Select]
<span class="ajax" id="ajaxtemp">

Second, copy this
Code: [Select]
// --- added flash-green on data update functions - saratoga-weather.org  24-Nov-2006
// -- begin settings
var flashcolor = '#00CC00'; // color to flash for changed observations
var flashtime  = '2000';    // miliseconds to keep flash color on (2000 = 2 seconds);
// -- end of settings

var ie4=document.all;
var browser = navigator.appName;

function get_ajax_tags ( ) {
// search all the span tags and return the list with class="ajax" in it
//
  if (ie4 && browser != "Opera") {
    var elem = document.body.getElementsByTagName('span');
var lookfor = 'className';
  } else {
    var elem = document.getElementsByTagName('span');
var lookfor = 'class';
  }
     var arr = new Array();
     for(i = 0,iarr = 0; i < elem.length; i++) {
          att = elem[i].getAttribute(lookfor);
          if(att == 'ajax') {
               arr[iarr] = elem[i];
               iarr++;
          }
     }

     return arr;
}

function reset_ajax_color( usecolor ) {
// reset all the <span class="ajax"...> styles to have no color override
      var elements = get_ajax_tags();
 var numelements = elements.length;
 for (var index=0;index!=numelements;index++) {
         var element = elements[index];
    element.style.color=usecolor;
 
      }
}

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; } // V1.04 -- don't set if missing the <span id=name> tag
var lastobs = element.getAttribute("lastobs");
element.setAttribute("lastobs",value);
if (value != lastobs) {
          element.style.color=flashcolor;
}
element.innerHTML =  value;
}
// --- end of flash-green functions
before the
Code: [Select]
// main AJAX routine .. load and format clientraw.txt
function ajaxLoader(url) {
  if (document.getElementById) {
    var x = (window.ActiveXObject) ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest(url);
  }
lines.


Then add this line
Code: [Select]

    setTimeout("reset_ajax_color('')",flashtime); // change text back to default color after 2 secs
 
just above the
Code: [Select]

    setTimeout("ajaxLoader('clientraw.txt?'+new Date())", 5000); // get new data after 5 secs
  }
} // end ajaxLoader function


Now the hard part.. you have to replace all of your lines in the JavaScript with assignment of .innerHTML with a call to the set_ajax_obs function to enable the green-flash to work.  So a line like this in the JavaScript
Code: [Select]
document.getElementById("ajaxgust").innerHTML = gust.toFixed(1); would be changed to
Code: [Select]
set_ajax_obs("ajaxgust",gust.toFixed(1));


Then your existing template should work with 'green flash' for changed conditions.

I did add a little feature - an '@' in front of the date/time stamp that ALWAYS turns green when the AJAX script has retrieved data.  It's nice to see the script is working even when WD clientraw update is pausing for main ftp update :-)

You can add this feature to your template too by adding
Code: [Select]
<span class="ajax" id="ajaxindicator"><strong>@</strong></span>&nbsp;&nbsp; in the HTML of the page where you'd like the indicator to appear, then add
Code: [Select]
element = document.getElementById("ajaxindicator");
if (element) { // V1.04 set indicator if <span id="ajaxindicator" class="ajax"> exists
          element.style.color = flashcolor;
}
just before the
Code: [Select]

   }
    }
    x.open("GET", url, true);
    x.send(null);

//get all of them every minute = 5000 milliseconds
//edit the location of your clienraw.txt twice!! (here and in the body onload)
setTimeout("reset_ajax_color()",flashtime); // change text back to default color
    setTimeout("ajaxLoader('clientraw.txt?'+new Date())", 5000); // get new data after 5 secs
  }
} // end ajaxLoader function


My homepage and conditions sidebar have been updated with green-flash-on-change.

Thanks again to krevinaz for the nudge to get it XHTML 1.0-Strict compliant.  

Best regards,
Ken
Ken True/Saratoga, CA, USA main site: saratoga-weather.org
Davis VP1+ FARS, Blitzortung RED, GRLevel3, WD, WL, VWS, Cumulus, Meteobridge
Free weather PHP scripts/website templates - update notifications on Twitter saratogaWXPHP

Offline carterlake

  • Senior Contributor
  • ****
  • Posts: 243
    • CarterLake.org
Re: WD + PHP + AJAX with Wunderground-style 'green flash'
« Reply #12 on: November 26, 2006, 03:51:28 PM »
Just a note to say that I figured out a way to add images to the AJAX mix... now the radar, webcam, and citycam images (on my main page) auto update if there is a change... using AJAX!

Davis VP2 6153; Weather Display (LIVE w/ Ajax); Quickcam for Notebooks Pro; Boltek w/ Nexstorm; GRLevel3; live NOAA Radio

Offline carterlake

  • Senior Contributor
  • ****
  • Posts: 243
    • CarterLake.org
Re: WD + PHP + AJAX with Wunderground-style 'green flash'
« Reply #13 on: November 28, 2006, 08:07:11 PM »
Yet another update on this just awesome tool... the original person who wrote up the code mentioned that you can this with other files... now I'm working on having the majority of values on my home page be entirely live... many of them update every 6 seconds... others every 5 minutes (more than enough for most values)... couple that with auto updating images and you've got a page which is very close to never needing reloaded.

Davis VP2 6153; Weather Display (LIVE w/ Ajax); Quickcam for Notebooks Pro; Boltek w/ Nexstorm; GRLevel3; live NOAA Radio

Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 9722
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: WD + PHP + AJAX with Wunderground-style 'green flash'
« Reply #14 on: November 29, 2006, 01:51:46 PM »
That's very cool Tom!!  8)

I've added error checking to V1.03 post (above) so it is easier for folks to adapt without causing JavaScript errors due to missing <span id="ajax...."> tags.

The two changed parts are the set_ajax_obs function which now reads
Code: [Select]
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; } // V1.04 -- don't set if missing the <span id=name> tag
var lastobs = element.getAttribute("lastobs");
element.setAttribute("lastobs",value);
if (value != lastobs) {
          element.style.color=flashcolor;
}
element.innerHTML =  value;
}


and the flashing indicator support which was
Code: [Select]
document.getElementById("ajaxindicator").style.color = flashcolor;
and is now
Code: [Select]
element = document.getElementById("ajaxindicator");
if (element) { // V1.04 set indicator if <span id="ajaxindicator" class="ajax"> exists
          element.style.color = flashcolor;
}

I've updated the instructions and sample files at http://saratoga-weather.org/scripts-WD-AJAX.php . Hopefully, this will make your addition of AJAX green-flash easier as you add/remove AJAX-driven variable updates.

Best regards,
Ken
Ken True/Saratoga, CA, USA main site: saratoga-weather.org
Davis VP1+ FARS, Blitzortung RED, GRLevel3, WD, WL, VWS, Cumulus, Meteobridge
Free weather PHP scripts/website templates - update notifications on Twitter saratogaWXPHP

Offline capeweather

  • Global Moderator
  • Forecaster
  • *****
  • Posts: 1309
    • http://www.capeweather.com
Re: WD + PHP + AJAX with Wunderground-style 'green flash'
« Reply #15 on: December 02, 2006, 05:55:45 PM »
Ken, is it possible to use this script with VWS?

Chris
Cape Coral, Florida
Website: http://www.capeweather.com
Website: http://www.fortmyersweather.net

Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 9722
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: WD + PHP + AJAX with Wunderground-style 'green flash'
« Reply #16 on: December 02, 2006, 10:09:17 PM »
If VWS can FTP up a delimited data file (text format) at 5 second intervals, then yes.. I don't know if VWS currently offers that.  I know there's a WeatherFlash add-on, but the format of the file(s) used is not documented as far as I can tell.

Let me know if you find a file-set uploaded by VWS to your website that has those conditions, then I could refit the AJAX code to use it :-)

Ken
Ken True/Saratoga, CA, USA main site: saratoga-weather.org
Davis VP1+ FARS, Blitzortung RED, GRLevel3, WD, WL, VWS, Cumulus, Meteobridge
Free weather PHP scripts/website templates - update notifications on Twitter saratogaWXPHP

Offline capeweather

  • Global Moderator
  • Forecaster
  • *****
  • Posts: 1309
    • http://www.capeweather.com
Re: WD + PHP + AJAX with Wunderground-style 'green flash'
« Reply #17 on: December 02, 2006, 10:14:40 PM »
Ken, I noticed there is a CSV file export which updates at 3 seconds at default settings. If you go to settings then CSV Export you should see it but I'm not sure if you use VWS or not.

Chris
Cape Coral, Florida
Website: http://www.capeweather.com
Website: http://www.fortmyersweather.net

Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 9722
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: WD + PHP + AJAX with Wunderground-style 'green flash'
« Reply #18 on: December 02, 2006, 10:25:14 PM »
Alas, I have no VWS.. just WeatherLink and Weather-Display.

If you could send me a sample of the .htx file template for the .csv and a sample of the uploaded .csv file (and the URL where you upload it on your site), I'll take a look.. should be easy to adapt :-)

Ken
Ken True/Saratoga, CA, USA main site: saratoga-weather.org
Davis VP1+ FARS, Blitzortung RED, GRLevel3, WD, WL, VWS, Cumulus, Meteobridge
Free weather PHP scripts/website templates - update notifications on Twitter saratogaWXPHP

Offline kray1000

  • Purveyor of wry
  • Forecaster
  • *****
  • Posts: 1336
    • http://www.roanokevalleyweather.com
Re: WD + PHP + AJAX with Wunderground-style 'green flash'
« Reply #19 on: December 02, 2006, 10:31:19 PM »
The trick would be to upload that .csv file at 5 second intervals... guess we're looking at a third-party app to do that... unless you're running your own server, I suppose...

Just a caveat to Ken... VWS changed the format of its .csv file a couple of years ago... worth mentioning if/when you get to the documentation phase...

Offline capeweather

  • Global Moderator
  • Forecaster
  • *****
  • Posts: 1309
    • http://www.capeweather.com
Re: WD + PHP + AJAX with Wunderground-style 'green flash'
« Reply #20 on: December 02, 2006, 10:35:17 PM »
I actually run webdrive for all of my FTP transfers and it seems to be pushing at 5 second intervals to my host or whenever the file updates. What I don't get is when I created the export file I'm actually getting data.csv and data2.csv. You can take a look at the files here if you wish ken.

http://www.capeweather.com/data.csv

http://www.capeweather.com/data2.csv

Chris
Cape Coral, Florida
Website: http://www.capeweather.com
Website: http://www.fortmyersweather.net

Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 9722
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: WD + PHP + AJAX with Wunderground-style 'green flash'
« Reply #21 on: December 03, 2006, 01:02:56 AM »
After much searching, I found the docs for the data.csv/data2.csv on pages 45-47 of the VWS manual ( http://www.wunderground.com/autoasp/downloads/vwsmanual.PDF )

It DOES look possible.. let me code a bit and post a sample for you to try.

Ken
Ken True/Saratoga, CA, USA main site: saratoga-weather.org
Davis VP1+ FARS, Blitzortung RED, GRLevel3, WD, WL, VWS, Cumulus, Meteobridge
Free weather PHP scripts/website templates - update notifications on Twitter saratogaWXPHP

Offline capeweather

  • Global Moderator
  • Forecaster
  • *****
  • Posts: 1309
    • http://www.capeweather.com
Re: WD + PHP + AJAX with Wunderground-style 'green flash'
« Reply #22 on: December 03, 2006, 01:08:25 AM »
Very cool Ken. I just peeked at the manual and it does state the following...

Quote
Real-time data can be exported to a csv file for other programs to utilize


Lookin good so far. Can you tell if my files are updating quickly? Right now they are set for 5 seconds.

Chris
Cape Coral, Florida
Website: http://www.capeweather.com
Website: http://www.fortmyersweather.net

Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 9722
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: WD + PHP + AJAX with Wunderground-style 'green flash'
« Reply #23 on: December 03, 2006, 02:12:44 AM »
Yes, your data.csv and data2.csv do update about every 5 seconds.

Ken
Ken True/Saratoga, CA, USA main site: saratoga-weather.org
Davis VP1+ FARS, Blitzortung RED, GRLevel3, WD, WL, VWS, Cumulus, Meteobridge
Free weather PHP scripts/website templates - update notifications on Twitter saratogaWXPHP

Offline capeweather

  • Global Moderator
  • Forecaster
  • *****
  • Posts: 1309
    • http://www.capeweather.com
Re: WD + PHP + AJAX with Wunderground-style 'green flash'
« Reply #24 on: December 05, 2006, 01:25:34 AM »
AJAX is the absolute bomb!!! Thanks Ken for all your help!!!!  =D&gt; I was really happy to get it working with VWS.

http://www.capeweather.com

Chris
Cape Coral, Florida
Website: http://www.capeweather.com
Website: http://www.fortmyersweather.net

 

anything