Page 3 of 4

Re: Default Cumulus web page working in PHP using realtime.t

Posted: Wed 09 Feb 2011 10:36 am
by Synewave
daj wrote:
fractonimbus wrote:And also (3) the Last Rainfall data, which is not part of the realtime.txt. Is there a way to get Cumulus to add parameters to realtime.txt, or to some small text file to upload at the same time?

Ideally the dawn dusk, sun and moon etc data would be nice to include, too, but I may have to let the regular upload process do that (which is what I did with the PHP page).

DN
You don't need to use the default realtime.txt file, you could build your own using webtags or create a second one. Example

realtime-extras.txt
<#sunrise> <#sunset> <#dawn> <#dusk>

Get Cumulus to process this file in realtime and it will upload too. Your code can then parse this additional file for the extra data
Just a little tip here! Davids existing script parses the realtime.txt file and splits the data when it finds a space. A lot of the extra webtags available for use have spaces in (i.e. "Rising Rapidly"). So the script would treat this as two tags, and sometimes one if it was "Steady" for example, therefore resulting in unpredictable data positions.

I've overcome this by creating the extra realtime file and placed a ~ (tilda) after each webtag like this:

Code: Select all

<#temptrendtext>~
<#presstrend>~
<#dawn>~
<#dusk>~
<#daylightlength format="h'hrs' n'min'">~
<#sunrise>~
<#sunset>~
<#daylength format="h'hrs' n'min'">~
<#moonrise>~ ... and so on
Then in the Javascript use var rawdataextras=realdataextras.split("~");

Re: Default Cumulus web page working in PHP using realtime.t

Posted: Wed 09 Feb 2011 10:40 am
by fractonimbus
Splendid! Thanks, David.

And I have the FDI maths working too. It's amazing how many different ways there are to express a simple equation -- eg IDL, Python, FORTRAN, PHP and Javascript all do it differently :-(

DN

Re: Default Cumulus web page working in PHP using realtime.t

Posted: Wed 09 Feb 2011 10:43 am
by fractonimbus
Paul, thanks, great tip

DN

Re: Default Cumulus web page working in PHP using realtime.t

Posted: Wed 09 Feb 2011 10:49 am
by daj
Good point Paul. The original script was to parse the standard realtime file, but I forgot extra tags may have a space

Re: Default Cumulus web page working in PHP using realtime.t

Posted: Wed 09 Feb 2011 12:35 pm
by fractonimbus
Well, I've now got the whole page working, including using a "loading..." warning. http://www.dcnicholls.com/wx/ind_test.html

DN

Re: Default Cumulus web page working in PHP using realtime.t

Posted: Wed 09 Feb 2011 12:50 pm
by Synewave
fractonimbus wrote:Well, I've now got the whole page working, including using a "loading..." warning. http://www.dcnicholls.com/wx/ind_test.html

DN
Working great. You're most welcome to look at the source of my script and use any of it. There is some code in there to make the Last Rain a bit more friendly. i.e. Last Rain: 4 Days Ago

Re: Default Cumulus web page working in PHP using realtime.t

Posted: Wed 09 Feb 2011 1:08 pm
by laulau
Thanks Paul,
Is it possible to have the "webtags" source of your realtimeextras.txt file ? :oops:
BTW where did you get the gauges of your "Gauge dashboard" :oops: ;)

Re: Default Cumulus web page working in PHP using realtime.t

Posted: Wed 09 Feb 2011 1:18 pm
by Synewave
laulau wrote:Thanks Paul,
Is it possible to have the "webtags" source of your realtimeextras.txt file ? :oops:
BTW where did you get the gauges of your "Gauge dashboard" :oops: ;)
I'll send the file to you via PM.

The gauges, I made them - based on the Bindows Free gauges. They also work from the realtime files.

Re: Default Cumulus web page working in PHP using realtime.t

Posted: Wed 09 Feb 2011 1:22 pm
by mcrossley
Paul, you may want to test your gauges in IE :roll: , I had to implement a few work-arounds to get Bindows reliable in IE.

Re: Default Cumulus web page working in PHP using realtime.t

Posted: Wed 09 Feb 2011 1:31 pm
by Synewave
mcrossley wrote:Paul, you may want to test your gauges in IE :roll: , I had to implement a few work-arounds to get Bindows reliable in IE.
Yes, I'm struggling to get them working in IE, hence I have a bit of Javascript to direct IE users to my old gauges page. If you can give me any help to get them working in IE I would very much appreciate it.

Re: Default Cumulus web page working in PHP using realtime.t

Posted: Wed 09 Feb 2011 1:35 pm
by beteljuice
FAO Daj.

You may remember sometime ago the 'old' beteljuice Ajax where the problem of initial data population suddenly appeared.

The problems seem to be the way 'modern' browsers load CSS (usually applied last, depending upon the browser, amd wether it's in-line, in page or seperate page !)

We are manipulating elements, and (again) depending upon browser, the onLoad is usually executing BEFORE all the CSS properties have been 'declared' !

The Ajax loop actually fails, but as you have probably discovered, it's rare for an error to escape from Ajax :D

The beteljuice got around this by creating an invisible <div id= > at the bottom of the html.
Dumped the Onload and just have code link in <header> and let JS run itself.

The Ajax has several attempts to find the (last) <div> before running the loop.

html:

Code: Select all


<!-- IMPORTANT, you must ALWAYS having the following line before the closing </body> tag !!!! -->
<div id="ajaxEND" style="display; none:"></div>

  </body>
Ajax <div> check

Code: Select all

// invoke when first loaded on page
var ajax_attempt = 0;

function start_up() {
	if(document.getElementById('ajaxEND')) {
		ajaxLoader(currdatFile + '?' + new Date().getTime());
 		window.setInterval("ajax_countup()", 1000); // run the counter for seconds since update
	} else {
		ajax_attempt++;
		if(ajax_attempt >= 50) {
			betel('Page has failed to download fully'); // 50 attempts for page to format
		} else {
			setTimeout('start_up()', 200);
		}
	}
}

start_up();
Not elegant, but it works !

Edit: forgot to mention fuction betel(), simply calls 'alert' outside of the Ajax loop, sometimes it actually works for debugging ;)

Haven't looked at Kens latest work, but the original (PHP mix) version used php duplication of all calculated variable and pre-populated the loaded page, which also keeps the purists happy for PCs not running JS.

... but it's a lot of work to code correctly :?

All gone a bit off topic, but at least we have given a guiding light. :idea:

Note to Ajax newbies:
You don't HAVE to have the 'html templates' of someomes Ajax, just follow the element naming structure and make the pages how you want.

Re: Default Cumulus web page working in PHP using realtime.t

Posted: Wed 09 Feb 2011 1:45 pm
by fractonimbus
Synewave wrote: Working great. You're most welcome to look at the source of my script and use any of it. There is some code in there to make the Last Rain a bit more friendly. i.e. Last Rain: 4 Days Ago
Thanks, Paul I might do that. It's getting a tad late here and I'm supposed to be writing a research paper (but Cumulus is much more fun :-)

DN

Re: Default Cumulus web page working in PHP using realtime.t

Posted: Wed 09 Feb 2011 2:29 pm
by fractonimbus
I'm noticing the occasional data corruption when the Javascript tries to load an page that's being updated by Cumulus (mentioned earlier in this thread, I think).

A Javascript question for the gurus on this list: who something like the following work to reload the page?

window.onerror=function(){
window.location.reload();}


DN

Re: Default Cumulus web page working in PHP using realtime.t

Posted: Wed 09 Feb 2011 7:41 pm
by daj
fractonimbus wrote:A Javascript question for the gurus on this list: who something like the following work to reload the page?

window.onerror=function(){
window.location.reload();}
No, as you are never reloading the page -- what you are actually doing is updating small bits of the HTML document in the browser. A bit like you having a sheet of paper in front of you, already full of words. You then rub out a few works and write something else. No one takes the page away and gives it to you again, you just tweaked it

You should not get the 'corruption' too much if you get your timings correct. How often is Cumulus updating realtime? And howoftenis jQuery Ajax reading the file?

I'm sure I did write something to check the rawdata variable to ensure it was valid data -- must look it out.

Re: Default Cumulus web page working in PHP using realtime.t

Posted: Wed 09 Feb 2011 8:07 pm
by Synewave
daj wrote:I'm sure I did write something to check the rawdata variable to ensure it was valid data -- must look it out.
I made a change to my script today and it seems to have made a difference. If the data tries to reload at the same time as the realtime.txt being uploaded by Cumulus, I would get the strange HTML characters instead of the data. If I then waited for the interval time to elapse (i.e 15 secs), the data returns to the real data.

So I removed the line:

Code: Select all

if (realdata.indexOf(realtime_location) == -1 ) { .......
and the corresponding  }
The effect is that the script doesn't wait for the interval time to elapse but refreshes the data as soon as it is available i.e a few secs.

David, I am wondering the reason why you coded this line?