Welcome to the Cumulus Support forum.

Latest Cumulus MX release 3.6.10 (build 3086) - 24 June 2020 (please see important announcement regarding releases since 3.5.0)
Legacy Cumulus 1 release v1.9.4 (build 1099) - 28 November 2014 (a patch is available for 1.9.4 build 1099 that extends the date range of the NOAA report and Snow Index drop-down menus to 2030)

See the Wiki to download the software or click on the Downloads link in the Forum Banner.

Lightning notification

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

Moderator: daj

Post Reply
Mapantz
Posts: 748
Joined: Sat 17 Dec 2011 11:55 am
Weather Station: Davis Vantage Pro2
Operating System: Windows 10 x64
Location: Dorset - UK
Contact:

Lightning notification

Post by Mapantz »

I'm trying to get text on my website to flash when get a lightning strike. It does work, and then it doesn't.

I've tried to do it so that text will flash for 30 minutes after the last strike has been detected. I thought I had it solved, but it fails too often and i'm not sure why.

Here's what I get CMX to upload for the lightning flash stuff:

Code: Select all

$lightningtimenum = "<#LightningTime format="yyyMMddHHmmss">";
$currenttime= date('ymjhi');
$lightningalert=date('ymjhi', strtotime($lightningtimenum));
$lightningtimeago= $lightningalert - $currenttime;
Here's what outputs:

https://warehamwx.co.uk/gw1000.php?sce=view

I then used this on my webpage:

Code: Select all

<?php if ($lightningtimeago > -30) { echo '<span class="lightning_alert">&nbsp;&nbsp;Lightning Nearby</span> '; } else { echo '&nbsp;&nbsp;Lightning'; }?>
$lightningtimeago was originally showing -1 for 1 minutes, -2 for 2 minutes and so on. However, within 5 minutes of a strike being detected, $lightningtimeago then showed -50.

As it stands now, the last strike detected was 20 minutes ago, and $lightningtimeago shows -61.

I know the coding is a fudge, but I don't understand why $lightningtimeago is not being reset correctly?

Any help would be greatly appreciated. :oops:
Image

sfws
Posts: 898
Joined: Fri 27 Jul 2012 11:29 am
Weather Station: Modified Fine Offset
Operating System: Win. 10 PC
Location: The Marches, UK

Re: Lightning notification

Post by sfws »

Mapantz wrote:
Thu 25 Jun 2020 7:17 pm
$lightningtimeago= $lightningalert - $currenttime;
That is not the right way to subtract times!

Have you forgotten that there are 60 seconds in minute and 60 minutes in an hour, you are mixing base 60 and base 10. No wonder the result jumps when the minute changes!

Why not use something like

Code: Select all

$lightningtime = new DateTime( "<#LightningTime format="yyy-MM-dd HH:mm:ss">");
$currenttime= new DateTime(date());
$lightningtimeago= $lightningtime ->diff($currenttime);
if($lightningtimeago -> format("i") < 30)  /* convert to minutes,  runs beyond 60 I think */
{
    flash text action
}
There are other ways of coding this, and this might not be best, but it gives you an idea. You can look up the date_diff, date_sub etc. functions on php.net yourself to find out more.
I have not tested this exact code although I use a similar construct for checking whether today when reporting last rain time, you might need something a little more complicated in condition because I am unsure if the convert to minutes works for multiple days. (In general, these PHP functions work for short periods like days, but not for longer periods like months or years, as I commented, in the forum, back when we had the leap day, so this might fail when no lightning for months).

Edit: Corrected my typos, saying data when I meant date!
Last edited by sfws on Fri 26 Jun 2020 6:41 am, edited 1 time in total.

freddie
Posts: 764
Joined: Wed 08 Jun 2011 11:19 am
Weather Station: Davis Vantage Pro 2
Operating System: Ubuntu 18.04 (LXC container)
Location: Dorrington, Shropshire, UK
Contact:

Re: Lightning notification

Post by freddie »

Probably best to do your subtraction and comparisons using epoch time, as subtraction using date objects and their fields is a bit of a minefield.
Freddie
Image

User avatar
mcrossley
Posts: 6587
Joined: Thu 07 Jan 2010 9:44 pm
Weather Station: Davis VP2
Operating System: Buster Lite rPi
Location: Wilmslow, Cheshire, UK
Contact:

Re: Lightning notification

Post by mcrossley »

Plus 1 for using Unix timestamp.
But if you were to use dates, I'd create the two date object and use date_diff() (or the equivalent arrow function as sfw has above).

User avatar
beteljuice
Posts: 2950
Joined: Tue 09 Dec 2008 1:37 pm
Weather Station: None !
Operating System: ex XP SP3 - now W10 laptop grr
Location: Dudley, West Midlands, UK

Re: Lightning notification

Post by beteljuice »

It won't have helped having 3 y instead of 4

Code: Select all

$lightningtimenum = "<#LightningTime format="yyyMMddHHmmss">";
You could also try ...

Code: Select all

$lightningMinAgo = (time() - mktime(<#LightningTime format="H,m,s,MM,d,yyyy">)) / 60;

<?php if ($lightningMinAgo <= 30) { echo '<span class="ligh .....
Image
......................Imagine, what you will KNOW tomorrow !

Mapantz
Posts: 748
Joined: Sat 17 Dec 2011 11:55 am
Weather Station: Davis Vantage Pro2
Operating System: Windows 10 x64
Location: Dorset - UK
Contact:

Re: Lightning notification

Post by Mapantz »

Thank you for the replies! :D

I went with the beteljuice's as it was the most simplified for my small hippocampus, but it works!

I suppose the next question is; Can the text flash without refreshing the page, when a strike is detected?
Image

User avatar
beteljuice
Posts: 2950
Joined: Tue 09 Dec 2008 1:37 pm
Weather Station: None !
Operating System: ex XP SP3 - now W10 laptop grr
Location: Dudley, West Midlands, UK

Re: Lightning notification

Post by beteljuice »

I suppose the next question is; Can the text flash without refreshing the page, when a strike is detected?
I suppose the answer is yes
... but not with the smb_ajax.js you are using :cry:

You would have to create a new looping 'ajax' code that could interrogate a different custom upload file (such as cuwebtags or a much smaller one with only the things you want in), and then do the logic in javascript or instruct the webtags.php to create the var you want. ... easier than it sounds :?
Image
......................Imagine, what you will KNOW tomorrow !

Mapantz
Posts: 748
Joined: Sat 17 Dec 2011 11:55 am
Weather Station: Davis Vantage Pro2
Operating System: Windows 10 x64
Location: Dorset - UK
Contact:

Re: Lightning notification

Post by Mapantz »

I've ran in to a bit of a problem..

I updated the firmware of the GW1000 which resets lightning data. Cumulus MX defaults to show hyphens when there's no data.

$lightningMinAgo = (time() - mktime(<#LightningTime format="H,m,s,MM,d,yyyy">)) / 60;

becomes

$lightningMinAgo = (time() - mktime(---)) / 60;

It obviously stops my whole page from loading.

Is there a workaround to counter it? :oops:
Image

User avatar
beteljuice
Posts: 2950
Joined: Tue 09 Dec 2008 1:37 pm
Weather Station: None !
Operating System: ex XP SP3 - now W10 laptop grr
Location: Dudley, West Midlands, UK

Re: Lightning notification

Post by beteljuice »

Code: Select all

$lightningMinAgo = "<#LightningTime format="H,m,s,MM,d,yyyy">";
if($lightningMinAgo != "---") $lightningMinAgo = (time() - mktime($lightningMinAgo)) / 60;


<?php if ($lightningMinAgo != "---" && $lightningMinAgo <= 30) { echo '<span class="ligh .....
Image
......................Imagine, what you will KNOW tomorrow !

Mapantz
Posts: 748
Joined: Sat 17 Dec 2011 11:55 am
Weather Station: Davis Vantage Pro2
Operating System: Windows 10 x64
Location: Dorset - UK
Contact:

Re: Lightning notification

Post by Mapantz »

Thank you beteljuice!

You helped me fix a couple of other small issues with that too. :)
Image

Post Reply