Code: Select all
$(function () {
var chart, options, rawRealtime, interval,
// countdown timer, 60 secs/1 min
count = 60,
// location of the realtime.txt file
realtimeFile = './realtime.txt',
// The various delimiters used in your version of realtime.txt
dateDelimiter = '/',
timeDelimiter = ':',
// 120 = 2 hours at 1 minute per data point
numDisplayRecs = 480,
// Fields of realtime.txt file
// Use the same names as the corresponding web tags
fields = {
date: 0, time: 1, temp: 2, hum: 3, dew: 4, wspeed: 5, wlatest: 6, bearing: 7, rrate: 8, rfall: 9,
press: 10, currentwdir: 11, beaufortnumber: 12, windunit: 13, tempunitnodeg: 14, pressunit: 15,
rainunit: 16, windrun: 17, presstrendval: 18, rmonth: 19, ryear: 20, rfallY: 21, intemp: 22,
inhum: 23, wchill: 24, temptrend: 25, tempTH: 26, TtempTH: 27, tempTL: 28, TtempTL: 29, windTM: 30,
TwindTM: 31, wgustTM: 32, TwgustTM: 33, pressTH: 34, TpressTH: 35, pressTL: 36, TpressTL: 37,
version: 38, build: 39, wgust: 40, heatindex: 41, humidex: 42, UV: 43, ET: 44, SolarRad: 45,
avgbearing: 46, rhour: 47, forecastnumber: 48, isdaylight: 49, SensorContactLost: 50, wdir: 51,
cloudbasevalue: 52, cloudbaseunit: 53, apptemp: 54, SunshineHours: 55, CurrentSolarMax: 56, IsSunny: 57
},
// Fetch the realtime.txt file
getRealtime = function () {
$.ajax({
url: realtimeFile,
datatype: 'text',
success: function (data) { parseRealtime(data); },
cache: false
});
},
// Extract the fields from realtime.txt and update graph
parseRealtime = function (data) {
var tim,
shift = chart.series[0].data.length < numDisplayRecs ? false : true;
rawRealtime = data.split(' ');
tim = getDate(rawRealtime[0], rawRealtime[1]);
chart.series[0].addPoint([tim, +getRealtimeValue('rfall')], false, shift);
chart.series[1].addPoint([tim, +getRealtimeValue('press')], false, shift);
chart.series[2].addPoint([tim, +getRealtimeValue('wspeed')], false, shift);
chart.series[3].addPoint([tim, +getRealtimeValue('temp')], false, shift);
chart.redraw();
},
// Returns the value from realtime.txt given the field name
getRealtimeValue = function (field) {
return rawRealtime[fields[field]];
},
// Returns a UTC date value from date & time strings
getDate = function (strDate, strTime) {
var d = strDate.split(dateDelimiter),
t = strTime.split(timeDelimiter);
return Date.UTC('20' + d[2], +d[1] - 1, d[0], t[0], t[1], t[2]);
};
Sorry, still can't make it work "live" without using realtime.txt.