Welcome to the Cumulus Support forum.

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

Cumulus MX V4 beta test release 4.0.0 (build 4019) - 03 April 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

online / offline webtag for htm

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

Moderator: daj

User avatar
Darknstormy
Posts: 168
Joined: Wed 28 Apr 2010 1:01 pm
Weather Station: Davis Vantage Pro 2 Plus
Operating System: Windows 11
Location: Australia

Re: online / offline webtag for htm

Post by Darknstormy »

Ok... since I'm completely dumb at code and its a little confusing.... have we got a final code that can be added once the new build comes out...

sorry

is there anything I need to change apart from online offline gif?

because its not working :(

Lyle :D

EDIT : sorry I see Steve has already done an update :D:D
ImageImage
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: online / offline webtag for htm

Post by beteljuice »

Oops - the beteljuice always has headaches with coding time functions no matter what the language is !

Try the edited code now (V1.2)

PS. your output is in a <table> but NOT within <TR><TD>

B*gger! - forgot UTCdate

now (V1.3)
Image
......................Imagine, what you will KNOW tomorrow !
User avatar
Darknstormy
Posts: 168
Joined: Wed 28 Apr 2010 1:01 pm
Weather Station: Davis Vantage Pro 2 Plus
Operating System: Windows 11
Location: Australia

Re: online / offline webtag for htm

Post by Darknstormy »

awww... i dont know what ive done wrong... mines just saying station offline and the image isnt coming up:(
ImageImage
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: online / offline webtag for htm

Post by beteljuice »

You have still 'broken' the table, if you want it below your other sensors
then:

Code: Select all

<tr>
<td colspan="4" class="tableseparator_pressure"><div align="center">
<script type="text/javascript">
<!--
// for the image (when / where required)
document.write("<img src=\"" + status_pic + "\" alt=\"test\" title=\"" + status_txt + "\" />");
//for the text (when / where required)
document.write( " " + status_txt);
-->
</script>
</div></td>
</tr> 
Note the o/p code has been rewritten, your image is rather large, so either resize it or 'force' a different size by adding at least a width attribute along the lines of:

Code: Select all

document.write("<img src=\"" + status_pic + "\" alt=\"test\" title=\"" + status_txt + "\" width=\"40\" />");
Image
......................Imagine, what you will KNOW tomorrow !
User avatar
Darknstormy
Posts: 168
Joined: Wed 28 Apr 2010 1:01 pm
Weather Station: Davis Vantage Pro 2 Plus
Operating System: Windows 11
Location: Australia

Re: online / offline webtag for htm

Post by Darknstormy »

Sorry It's prob frustrating.. ok so Ive re-sized the pictures and they are working now...

but when you say I have 'broken' the table... what part of the code have I got in the wrong spot for that to happen.. Cheers sorry again
ImageImage
User avatar
mcrossley
Posts: 12766
Joined: Thu 07 Jan 2010 9:44 pm
Weather Station: Davis VP2/WLL
Operating System: Bullseye Lite rPi
Location: Wilmslow, Cheshire, UK
Contact:

Re: online / offline webtag for htm

Post by mcrossley »

beteljuice, I still think this is wrong or over complicated.

The problem is the browser is using 'local' time somewhere in the world, we don't know where.
Cumulus is providing UTC time to get around this.

So we want to compare 'now':

Code: Select all

var now = new Date();
with the time Cumulus provides in UTC:

Code: Select all

var then = Date.UTC(<#timeUTC format=yyyy>, <#timeUTC format=mm>-1, <#timeUTC format="dd', 'hh', 'mm', 'ss">);
so:

Code: Select all

if (now - then < timetodie)  //simplified, could strictly use now.getTime()
  //we're online
else
  //we're offline
Or am I off track here?
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: online / offline webtag for htm

Post by beteljuice »

I might well be overdoing things, or even got my logic backward - as I said before I've always had problems with what is UTC and what doesn't need to be (for comparative purposes).

I certainly seem to have got something wrong as Darknstormys page is always showing off-line to me, but if I test the code locally it seems to work :bash:

As I see your code suggestion, 'now' is a browser local time object which you have left alone, but then you have converted 'then' which is already a UTC time to UTC (again) milliseconds.

Does it work ?
Image
......................Imagine, what you will KNOW tomorrow !
User avatar
mcrossley
Posts: 12766
Joined: Thu 07 Jan 2010 9:44 pm
Weather Station: Davis VP2/WLL
Operating System: Bullseye Lite rPi
Location: Wilmslow, Cheshire, UK
Contact:

Re: online / offline webtag for htm

Post by mcrossley »

My previous code is largely untested, but I think the Date object always stores the raw millisecond value in 'UTC'.
I did play around in the debugger and...

if you set...
var now = new Date();
var utc = Date.UTC(now.getUTCFullYear, now.getUTCMonth, [...etc including ms])

then...
now == utc --> true
User avatar
Darknstormy
Posts: 168
Joined: Wed 28 Apr 2010 1:01 pm
Weather Station: Davis Vantage Pro 2 Plus
Operating System: Windows 11
Location: Australia

Re: online / offline webtag for htm

Post by Darknstormy »

Glad you guys know what your doing, can u guys post the new code complete, and ill test it tonight when I get home.

Cheers guys
ImageImage
User avatar
mcrossley
Posts: 12766
Joined: Thu 07 Jan 2010 9:44 pm
Weather Station: Davis VP2/WLL
Operating System: Bullseye Lite rPi
Location: Wilmslow, Cheshire, UK
Contact:

Re: online / offline webtag for htm

Post by mcrossley »

If I get a chance I'll have a play around sometime today - I'd like to implement this myself :)
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: online / offline webtag for htm

Post by beteljuice »

It would seem Mark had it right and the beteljuice both applied the UTC to the wrong variable and effectively did it twice ! (I think)

So here is the revised code that seems to work (Unless someone proves different :? )
In the <head> section of your xxxxT.htm

Code: Select all

<script type="text/javascript">
<!--
// Javascript Cumulus update checker - betejuice v2.0 July 2011
// set these variables to suit
var missed = 2; // Number of updates to miss before deciding "offline", MUST be > 1, fractions allowed (eg. 1.5)
var online_pic = "myimages/online.gif"; // location of ONline image
var online_txt = "Station ON-line"; // your ONline text
var offline_pic = "myimages/offline.gif"; // location of OFFline image
var offline_txt = "Station OFF-line"; // your OFFline text
// END user vars

var now = new Date();

var then_month = <#timeUTC format=mm> -1;
var then = Date.UTC(<#timeUTC format=yyyy>, then_month, <#timeUTC format="dd', 'hh', 'mm', 'ss">);
var timetodie = <#interval> * missed * 60000; // milliseconds per minute

if(now - then < timetodie){
	status_pic = online_pic;
	status_txt = online_txt;
} else {
	status_pic = offline_pic;
	status_txt = offline_txt;
}
-->
</script>
Then somewhere to suit in the <body> section:

Code: Select all

<script type="text/javascript">
<!--
// for the image (when / where required)
document.write("<img src=\"" + status_pic + "\" alt=\"" + status_txt + "\" title=\"" + status_txt + "\" />");
//for the text (when / where required)
document.write(status_txt);
-->
</script>
You may wish to put the output script(s) in between <span> .. </span> to enable 'formatting' via CSS.

If it works ;) Kudos to Mark for proving that the beteljuice still has a long misunderstanding of comparative time conversions Image
Last edited by beteljuice on Thu 07 Jul 2011 12:02 pm, edited 3 times in total.
Image
......................Imagine, what you will KNOW tomorrow !
User avatar
Darknstormy
Posts: 168
Joined: Wed 28 Apr 2010 1:01 pm
Weather Station: Davis Vantage Pro 2 Plus
Operating System: Windows 11
Location: Australia

Re: online / offline webtag for htm

Post by Darknstormy »

Cheers guys, I tried mcrossley last night that he sent me and it worked but ive stuffed up my style so ill need to edit it tonight and put it where u said. Oops thanks again.
ImageImage
User avatar
GTB
Posts: 75
Joined: Thu 06 Nov 2008 12:14 am
Weather Station: ws1081 with Cumulus
Operating System: win 2000
Location: Terrigal NSW
Contact:

Re: online / offline webtag for htm

Post by GTB »

yes well - that works fine beteljuice

thank you very much

geoff
Image
User avatar
Darknstormy
Posts: 168
Joined: Wed 28 Apr 2010 1:01 pm
Weather Station: Davis Vantage Pro 2 Plus
Operating System: Windows 11
Location: Australia

Re: online / offline webtag for htm

Post by Darknstormy »

Thanks heaps guys, I have it all up and running now, not once has it failed :D


Cheers :D
ImageImage
User avatar
Ned
Posts: 258
Joined: Mon 19 Jul 2010 11:15 am
Weather Station: WS2083 (aspirated)
Operating System: Win 10
Location: Auckland NZ

Re: online / offline webtag for htm

Post by Ned »

And another vote of thanks from me :clap:
Very nice and just what my site needed when it nods off every night.... ;)
Post Reply