This is what I ultimately came up with, in case anyone ever comes across this in the future... A quick way to frequently update individual table fields from realtime.txt. I went with two functions, one for each update cycle interval; the thought being to minimize GET requests to realtime.txt. I have it updating every 2 seconds for wind and rain rate (I'm actually not even sure how often CRT updates this value in realtime.txt), and 30 seconds for everything else. Just have to give the data tags unique IDs in the HTML and then reference them here in the getElementById methods. Then the output is a matter of parsing CRT realtime.txt. Not sure if any of this is poor form, but it seems to be working well.
Thanks again for the push in the right direction.
function update_cycle1() {
windcellobj = document.getElementById("rt_wind");
rainratecellobj = document.getElementById("rt_rainrate");
xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
rt = this.responseText.split(" ");
if (rt[2]) {
// Start Wind
if (rt[6] != ("0.0")){
rtstr = rt[6].split(".")[0]+" "+rt[13]+" °"+rt[11];
} else {
rtstr = rt[6].split(".")[0]+" "+rt[13];
}
if ((parseInt(rt[6], 10) < 10)) {
windcellobj.innerHTML = rtstr;
} else if ((parseInt(rt[6], 10) >= 20)) {
windcellobj.innerHTML = rtstr.fontcolor("red");
} else {
windcellobj.innerHTML = rtstr.fontcolor("green");
}
// End Wind
rtstr = rt[8]+" "+rt[16]+"/hr";
rainratecellobj.innerHTML = rtstr;
}
}
};
xhttp.open("GET", "realtime.txt", true);
xhttp.send();
}
function update_cycle2() {
outtempcellobj = document.getElementById("rt_outtemp");
dewpointcellobj = document.getElementById("rt_dewpoint");
humiditycellobj = document.getElementById("rt_humidity");
barocellobj = document.getElementById("rt_baro");
windruncellobj = document.getElementById("rt_windrun");
heatindexcellobj = document.getElementById("rt_heatindex");
windchillcellobj = document.getElementById("rt_windchill");
raintodaycellobj = document.getElementById("rt_raintoday");
intempcellobj = document.getElementById("rt_intemp");
xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
rt = this.responseText.split(" ");
if (rt[2]) {
rtstr = rt[2]+" °"+rt[14];
outtempcellobj.innerHTML = rtstr;
rtstr = rt[4]+" °"+rt[14];
dewpointcellobj.innerHTML = rtstr;
rtstr = rt[3]+"%";
humiditycellobj.innerHTML = rtstr;
rtstr = rt[10]+" "+rt[15];
barocellobj.innerHTML = rtstr;
rtstr = rt[17]+" mile";
windruncellobj.innerHTML = rtstr;
rtstr = rt[41]+" °"+rt[14];
heatindexcellobj.innerHTML = rtstr;
rtstr = rt[24]+" °"+rt[14];
windchillcellobj.innerHTML = rtstr;
rtstr = rt[9]+" "+rt[16];
raintodaycellobj.innerHTML = rtstr;
rtstr = rt[22]+" °"+rt[14];
intempcellobj.innerHTML = rtstr;
}
}
};
xhttp.open("GET", "realtime.txt", true);
xhttp.send();
}
// Run everything once, immediately.
update_cycle1();
update_cycle2();
// Start update intervals.
window.setInterval(function(){update_cycle1();}, 2000);
window.setInterval(function(){update_cycle2();}, 30000);