Welcome to the Cumulus Support forum.

Latest Cumulus MX V4 release 4.4.2 (build 4085) - 12 March 2025

Latest Cumulus MX V3 release 3.28.6 (build 3283) - 21 March 2024

Legacy Cumulus 1 release 1.9.4 (build 1099) - 28 November 2014
(a patch is available for 1.9.4 build 1099 that extends the date range of drop-down menus to 2030)

Download the Software (Cumulus MX / Cumulus 1 and other related items) from the Wiki

If you are posting a new Topic about an error or if you need help PLEASE read this first viewtopic.php?p=164080#p164080

need a hand with some JSscript

Other discussion about creating web sites for Cumulus that doesn't have a specific subforum

Moderator: daj

Post Reply
User avatar
ace2
Posts: 679
Joined: Tue 14 Jan 2014 12:38 pm
Weather Station: maxkon ws-1081pc
Operating System: windows 7 & 8
Location: Adelaide, south Australia, Australia
Contact:

need a hand with some JSscript

Post by ace2 »

I have located a Jsscript to reload a text file on open, but having a little issue with adding more that one source file into it

Code: Select all

var req;

function reloadData()
{
   var now = new Date();
   url = 'lapseoff.txt?' + now.getTime();

   try {
      req = new XMLHttpRequest();
   } catch (e) {
      try {
         req = new ActiveXObject("Msxml2.XMLHTTP");
      } catch (e) {
         try {
            req = new ActiveXObject("Microsoft.XMLHTTP");
         } catch (oc) {
            alert("No AJAX Support");
            return;
         }
      }
   }

   req.onreadystatechange = processReqChange;
   req.open("GET", url, true);
   req.send(null);
}

function processReqChange()
{
   // If req shows "complete"
   if (req.readyState == 4)
   {
      dataDiv = document.getElementById('currentData');

      // If "OK"
      if (req.status == 200)
      {
         // Set current data text
         dataDiv.innerHTML = req.responseText;

         // Start new timer (1 min)
         timeoutID = setTimeout('reloadData()', 60000);
      }
      else
      {
         // Flag error
         dataDiv.innerHTML = '<p>There was a problem retrieving data: ' + req.statusText + '</p>';
      }
   }
}
Now i have 2 text files that need refreshing lapseon and lapseoff txt
How can i added to sources and change the //flag error to display text or another text file

sorry i'm not to good with JS scripts :cry:
CHRIS
Image
web site
http://www.ace2weather.com
Follow me on Twitter
http://tinyurl.com/kwlr9re
YouTube channel
http://tinyurl.com/lehwpgp
Facebook page
http://tinyurl.com/k3sap4s
Tiny URL links used
User avatar
ace2
Posts: 679
Joined: Tue 14 Jan 2014 12:38 pm
Weather Station: maxkon ws-1081pc
Operating System: windows 7 & 8
Location: Adelaide, south Australia, Australia
Contact:

Re: need a hand with some JSscript

Post by ace2 »

No one???
I would have thought this would be simple to do.
like on load, write the text files in **here** id ID=

<td><abbr title="Time-lapse turned off at this time">***here***</script></abbr></td>
I know have 2 text files does make it a little harder....
CHRIS
Image
web site
http://www.ace2weather.com
Follow me on Twitter
http://tinyurl.com/kwlr9re
YouTube channel
http://tinyurl.com/lehwpgp
Facebook page
http://tinyurl.com/k3sap4s
Tiny URL links used
uncle_bob
Posts: 505
Joined: Wed 17 Aug 2011 2:58 pm
Weather Station: WeatherDuino Pro2
Operating System: 2008
Location: Canberra

Re: need a hand with some JSscript

Post by uncle_bob »

ace2 wrote:No one???
It's the weekend, so folks ain't at work with spare time to read forums ;)
Interested in building your own Weather Station? Maybe check out the WeatherDuino Pro Project Here
Conder, Canberra Weather
Image
User avatar
ace2
Posts: 679
Joined: Tue 14 Jan 2014 12:38 pm
Weather Station: maxkon ws-1081pc
Operating System: windows 7 & 8
Location: Adelaide, south Australia, Australia
Contact:

Re: need a hand with some JSscript

Post by ace2 »

uncle_bob wrote:
ace2 wrote:No one???
It's the weekend, so folks ain't at work with spare time to read forums ;)
Am I the only one that doesn't have a life?
CHRIS
Image
web site
http://www.ace2weather.com
Follow me on Twitter
http://tinyurl.com/kwlr9re
YouTube channel
http://tinyurl.com/lehwpgp
Facebook page
http://tinyurl.com/k3sap4s
Tiny URL links used
uncle_bob
Posts: 505
Joined: Wed 17 Aug 2011 2:58 pm
Weather Station: WeatherDuino Pro2
Operating System: 2008
Location: Canberra

Re: need a hand with some JSscript

Post by uncle_bob »

ace2 wrote:
Am I the only one that doesn't have a life?
Nah, I'm here too :)
Interested in building your own Weather Station? Maybe check out the WeatherDuino Pro Project Here
Conder, Canberra Weather
Image
User avatar
beteljuice
Posts: 3292
Joined: Tue 09 Dec 2008 1:37 pm
Weather Station: None !
Operating System: W10 - Threadripper 16core, etc
Location: Dudley, West Midlands, UK

Re: need a hand with some JSscript

Post by beteljuice »

This is not a coding on demand service, nor is it even a coding forum.
Members may assist others if they are in the mood or it is pertinent.

TESTED javascript (which is NOT JScript)

Code: Select all

<html>
<head>
<script>
/*
beteljuice JavaScript for multiple asynchronous file grabs
  TESTED !!
  If you break it - YOU fix it !!!!
 */

var reports_url = ["myfile1.txt", "myfile2.txt"];
var reports_span = ["report1", "report2"];
var xx = reports_url.length;

var ajax_attempt = 0;

start_up();

function start_up() { // make sure at least first DOM element is recognized before running main code
	if(document.getElementById(reports_span[0])) {
		doIt();
	} else {
		ajax_attempt++;
		if(ajax_attempt >= 50) {
			document.write('Page has failed to download fully'); // 50 attempts for page to format
		} else {
			setTimeout('start_up()', 200);
		}
	}
} // END function start-up()


function doIt(){
	for(reportNum = 0 ; reportNum < xx ; reportNum++) { // step through arrays
		if(document.getElementById(reports_span[reportNum])) betelLoader(reportNum); // existance check then process
	} // END step through arrays
	setTimeout('doIt()', 60000); // start all over again
} // END function doIt()


// ------------------------------------------------------------------------------------------
//  Using this function to check existance and grab / display
// ------------------------------------------------------------------------------------------
function betelLoader(thisnum) {
  if (document.getElementById) {
    var now = new Date();
    var x = (window.ActiveXObject) ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest(reports_url[thisnum]+ "?" +now.getTime());
  }
  if (x) { // got something back

    x.onreadystatechange = function() {

    try { if (x.readyState == 4 && x.status == 200) { // file exists and received 
			var repdat = x.responseText
			document.getElementById(reports_span[thisnum]).innerHTML = repdat; // o/p the txt file

		} else  // END if (x.readyState == 4 && x.status == 200)

		if(x.readyState == 4 && x.status == 404) { // file does not exist
			document.getElementById(reports_span[thisnum]).innerHTML = "!#**@**!"; // o/p ERROR
		}  
	} // END try

   	catch(e){}  

    } // END x.onreadystatechange = function() 

    x.open("GET", reports_url[thisnum]+ '?' + now.getTime(), true);
    x.send(null);

  } // END if(x)
  
} // END betelLoader function
</script>
</head>
<body>
Here are the contents of myfile1.txt<br />
<span id="report1"></span>
<br /><br />
Here are the contents of myfile2.txt<br />
<span id="report2"></span>
<br /><br />
So what's the problem ?
</body>
</html>
EDIT: It was very easy to make an unforced error with this "must be simple" code - I did miss a bracket, use the wrong kind of bracket, and had a logic sequence error - all now fixed and working.
ace2 test
Last edited by beteljuice on Mon 13 Oct 2014 3:11 am, edited 2 times in total.
Image
......................Imagine, what you will KNOW tomorrow !
User avatar
ace2
Posts: 679
Joined: Tue 14 Jan 2014 12:38 pm
Weather Station: maxkon ws-1081pc
Operating System: windows 7 & 8
Location: Adelaide, south Australia, Australia
Contact:

Re: need a hand with some JSscript

Post by ace2 »

Thanks betejuice, I was just getting frustrated with attempt after attempts trying to get it to do what I wanted....
I shall try this at my own risk as I understand it could and might KILL me.. :D
CHRIS
Image
web site
http://www.ace2weather.com
Follow me on Twitter
http://tinyurl.com/kwlr9re
YouTube channel
http://tinyurl.com/lehwpgp
Facebook page
http://tinyurl.com/k3sap4s
Tiny URL links used
User avatar
ace2
Posts: 679
Joined: Tue 14 Jan 2014 12:38 pm
Weather Station: maxkon ws-1081pc
Operating System: windows 7 & 8
Location: Adelaide, south Australia, Australia
Contact:

Re: need a hand with some JSscript

Post by ace2 »

:(
CHRIS
Image
web site
http://www.ace2weather.com
Follow me on Twitter
http://tinyurl.com/kwlr9re
YouTube channel
http://tinyurl.com/lehwpgp
Facebook page
http://tinyurl.com/k3sap4s
Tiny URL links used
User avatar
beteljuice
Posts: 3292
Joined: Tue 09 Dec 2008 1:37 pm
Weather Station: None !
Operating System: W10 - Threadripper 16core, etc
Location: Dudley, West Midlands, UK

Re: need a hand with some JSscript

Post by beteljuice »

C'est la guerre !
Image
......................Imagine, what you will KNOW tomorrow !
User avatar
beteljuice
Posts: 3292
Joined: Tue 09 Dec 2008 1:37 pm
Weather Station: None !
Operating System: W10 - Threadripper 16core, etc
Location: Dudley, West Midlands, UK

Re: need a hand with some JSscript

Post by beteljuice »

beteljuice code fixed and tested in early solution post ....
Image
......................Imagine, what you will KNOW tomorrow !
User avatar
ace2
Posts: 679
Joined: Tue 14 Jan 2014 12:38 pm
Weather Station: maxkon ws-1081pc
Operating System: windows 7 & 8
Location: Adelaide, south Australia, Australia
Contact:

Re: need a hand with some JSscript

Post by ace2 »

beteljuice wrote:beteljuice code fixed and tested in early solution post ....
I hate to do this.....But i'm getting some strange outputs
http://www.users.on.net/~ace2/status.htm
called as beteloader.js
http://www.users.on.net/~ace2/statustest.htm
added onto page its self..

I think after this Betejuice needs to have a donation button!!!!!
CHRIS
Image
web site
http://www.ace2weather.com
Follow me on Twitter
http://tinyurl.com/kwlr9re
YouTube channel
http://tinyurl.com/lehwpgp
Facebook page
http://tinyurl.com/k3sap4s
Tiny URL links used
User avatar
beteljuice
Posts: 3292
Joined: Tue 09 Dec 2008 1:37 pm
Weather Station: None !
Operating System: W10 - Threadripper 16core, etc
Location: Dudley, West Midlands, UK

Re: need a hand with some JSscript

Post by beteljuice »

You have 'hidden' characters in your txt file (possibly UTF-8)
Image
......................Imagine, what you will KNOW tomorrow !
User avatar
ace2
Posts: 679
Joined: Tue 14 Jan 2014 12:38 pm
Weather Station: maxkon ws-1081pc
Operating System: windows 7 & 8
Location: Adelaide, south Australia, Australia
Contact:

Re: need a hand with some JSscript

Post by ace2 »

Your right, my powershell script is to blame

Code: Select all

$a = Get-Date
$time =$a.ToShortTimeString()
$time|Out-File C:\Cumulus\scripts\lapseresult.txt
Time to nut this one out!!!!

So where is your donate button????
CHRIS
Image
web site
http://www.ace2weather.com
Follow me on Twitter
http://tinyurl.com/kwlr9re
YouTube channel
http://tinyurl.com/lehwpgp
Facebook page
http://tinyurl.com/k3sap4s
Tiny URL links used
User avatar
beteljuice
Posts: 3292
Joined: Tue 09 Dec 2008 1:37 pm
Weather Station: None !
Operating System: W10 - Threadripper 16core, etc
Location: Dudley, West Midlands, UK

Re: need a hand with some JSscript

Post by beteljuice »

Just noticed an oooops:

Code: Select all

function doIt(){
	for(reportNum = 0 ; reportNum < xx ; reportNum++) { // step through arrays
		if(document.getElementById(reports_span[0])) betelLoader(reportNum); // existance check then process
	} // END step through arrays
	setTimeout('doIt()', 60000); // start all over again
} // END function doIt()
Should be:

Code: Select all

function doIt(){
	for(reportNum = 0 ; reportNum < xx ; reportNum++) { // step through arrays
		if(document.getElementById(reports_span[reportNum])) betelLoader(reportNum); // existance check then process
	} // END step through arrays
	setTimeout('doIt()', 60000); // start all over again
} // END function doIt()
Corrected in orginal post
Image
......................Imagine, what you will KNOW tomorrow !
User avatar
ace2
Posts: 679
Joined: Tue 14 Jan 2014 12:38 pm
Weather Station: maxkon ws-1081pc
Operating System: windows 7 & 8
Location: Adelaide, south Australia, Australia
Contact:

Re: need a hand with some JSscript

Post by ace2 »

Brilliant Betejuice, your a legend, like a knight in Java-armour!!!!

Also fixed the powershell issue, added -Encoding utf8 switch which sorted that out!!!
Instead of having all that code on the page, i added a line to call the Java Scripts called, wait for......beteljuiceloader.js :lol:

So once again...thank you thank you
CHRIS
Image
web site
http://www.ace2weather.com
Follow me on Twitter
http://tinyurl.com/kwlr9re
YouTube channel
http://tinyurl.com/lehwpgp
Facebook page
http://tinyurl.com/k3sap4s
Tiny URL links used
Post Reply