Hi all
It has been a while since this topic has been used but I hope someone can help out. I have been using a modified version of this script, the one which Mark (mcrossley) mentioned on September 03, 2011, which until now has been working great. But for some reason it has stopped working with out any known modification.
I liked the one he produced because it indicated by colour which values had been modified.
As this code has not been working for a while, I have gone back to the original posted in this forum to temporary measures.
If anyone has any clues as to why this code no longer works, they would be most appreciated or alternatively a different method of updating data on a page without needing to refresh the page.
Code: Select all
var tick_counter=0;
var j = 8;
var first_run=true;
setInterval('getlivedata()', 1000);
function getlivedata() {
if (j >= 0) {
if (tick_counter <= 0) {
// read realtime.txt file and parse it using a space
j--;
var rawdata = $.ajax({
url: "http://palmyweather.co.nz/realtime.txt",
async: false
}).responseText.split(' ');
// Get current values on the page
var temp_out = $("#temp_out").text();
var temp_trend = $("#temp_trend").text();
var hum = $("#hum").text();
var rain_rate = $("#rain_rate").text();
var rain_today = $("#rain_today").text();
var rain_hour = $("#rain_hour").text();
var wind_latest = $("#wind_latest").text();
var wind_avg = $("#wind_avg").text();
var bearing = $("#bearing").text();
var pressure = $("#pressure").text();
var press_trend = $("#press_trend").text();
var wind_gust = $("#wind_gust").text();
// Set all Spans to their values
$("#temp_out").html(rawdata[2]);
$("#temp_trend").html(rawdata[25]);
$("#hum").html(rawdata[3]);
$("#rain_rate").html(rawdata[8]);
$("#rain_today").html(rawdata[9]);
$("#rain_hour").html(rawdata[47]);
$("#wind_avg").html(rawdata[5]);
$("#wind_latest").html(rawdata[5]);
$("#bearing").html(rawdata[11]);
$("#pressure").html(rawdata[10]);
$("#press_trend").html(rawdata[18]);
$("#wind_gust").html(rawdata[6]);
$("#last_contact").html(rawdata[0] +" "+ rawdata[1]);
// is it currently raining, show the icon
if ($("#rain_rate").text() != "0.0") { $("#israining").show();} else { $("#israining").hide();}
// Calculate the Beaufort desc
var beau = rawdata[12];
if (beau=="0"){var bdesc="(Calm)";} else
if (beau=="1"){var bdesc="(Light Air)";} else
if (beau=="2"){var bdesc="(Fresh breeze)";} else
if (beau=="3"){var bdesc="(Moderate breeze)";} else
if (beau=="4"){var bdesc="(Strong breeze)";} else
if (beau=="5"){var bdesc="(Near gale)";} else
if (beau=="6"){var bdesc="(Gale)";} else
if (beau=="7"){var bdesc="(Strong Gale)";} else
if (beau=="8"){var bdesc="(Storm)";} else
if (beau=="9"){var bdesc="(Violent Storm)";} else
if (beau=="10"){var bdesc="(Hurricane)";} else
{ var bdesc="";}
$("#beaufort").html(bdesc);
// highlight if there was a change and show last values
if (first_run==false) {
if (temp_out != $("#temp_out").text()) {$("#temp_out").css("background","yellow"); $("#last_temp_out").text(temp_out);} else {$("#temp_out").css("background","");}
if (temp_trend != $("#temp_trend").text()) {$("#temp_trend").css("background","yellow");$("#last_temp_trend").text(temp_trend);} else {$("#temp_trend").css("background","");}
if (hum != $("#hum").text()) {$("#hum").css("background","yellow"); $("#last_hum").text(hum);} else {$("#hum").css("background","");}
if (rain_rate != $("#rain_rate").text()) {$("#rain_rate").css("background","yellow"); $("#last_rain_rate").text(rain_rate);} else {$("#rain_rate").css("background","");}
if (rain_today != $("#rain_today").text()) {$("#rain_today").css("background","yellow"); $("#last_rain_today").text(rain_today);} else {$("#rain_today").css("background","");}
if (rain_hour != $("#rain_hour").text()) {$("#rain_hour").css("background","yellow"); $("#last_rain_hour").text(rain_hour);} else {$("#rain_hour").css("background","");}
if (wind_avg != $("#wind_avg").text()) {$("#wind_avg").css("background","yellow"); $("#last_wind_avg").text(wind_avg);} else {$("#wind_avg").css("background","");}
if (wind_latest != $("#wind_latest").text()) {$("#wind_latest").css("background","yellow"); $("#last_wind_latest").text(wind_latest); } else {$("#wind_latest").css("background","");}
if (bearing != $("#bearing").text()) {$("#bearing").css("background","yellow"); $("#last_bearing").text(bearing);} else {$("#bearing").css("background","");}
if (pressure != $("#pressure").text()) {$("#pressure").css("background","yellow"); $("#last_pressure").text(pressure);} else {$("#pressure").css("background","");}
if (press_trend != $("#press_trend").text()) {$("#press_trend").css("background","yellow"); $("#last_press_trend").text(press_trend);} else {$("#press_trend").css("background","");}
if (wind_gust != $("#wind_gust").text()) {$("#wind_gust").css("background","yellow"); $("#last_wind_gust").text(wind_gust); } else {$("#wind_gust").css("background","");}
}
else
{
first_run=false;
}
tick_counter=30;
}
else
{
tick_counter--;
$("#refresh_in").html(tick_counter);
}
}
else
{
tick_counter--;
$("#refresh_in").html('<br/> TIMER PAUSED. PLEASE RELOAD PAGE TO GET THE LATEST DATA.');$("#refresh_in").css("background","orange");
}
}
When this code runs, it will not jump back in time for at least one upload and not retrieve any fresh data; the last retrieval of data information will stay static. Upon load, it will also change other environmental factors (such as temperature) to what ever the readings were at the previous time when it jumps back. EG: Current time might be 8pm. Initial load of page shows last contact with station was at 7:59pm before the script takes hold and it will change the time and other data to 7:58pm.
Thanks for your help,
Matt