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 4018) - 28 March 2024

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 drop-down menus to 2030)

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

Lightning notification

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

Moderator: daj

Mapantz
Posts: 1778
Joined: Sat 17 Dec 2011 11:55 am
Weather Station: Davis Vantage Pro2
Operating System: Windows 11 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: 1183
Joined: Fri 27 Jul 2012 11:29 am
Weather Station: Chas O, Maplin N96FY, N25FR
Operating System: rPi 3B+ with Buster (full)

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: 2434
Joined: Wed 08 Jun 2011 11:19 am
Weather Station: Davis Vantage Pro 2 + Ecowitt
Operating System: GNU/Linux Ubuntu 22.04 LXC
Location: Alcaston, 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: 12695
Joined: Thu 07 Jan 2010 9:44 pm
Weather Station: Davis VP2/WLL
Operating System: Bullseye 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: 3292
Joined: Tue 09 Dec 2008 1:37 pm
Weather Station: None !
Operating System: W10 - Threadripper 16core, etc
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">";
Edit: see viewtopic.php?p=145191#p145191 for 'final' code
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 .....
Last edited by beteljuice on Thu 13 Aug 2020 12:53 pm, edited 1 time in total.
Image
......................Imagine, what you will KNOW tomorrow !
Mapantz
Posts: 1778
Joined: Sat 17 Dec 2011 11:55 am
Weather Station: Davis Vantage Pro2
Operating System: Windows 11 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: 3292
Joined: Tue 09 Dec 2008 1:37 pm
Weather Station: None !
Operating System: W10 - Threadripper 16core, etc
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: 1778
Joined: Sat 17 Dec 2011 11:55 am
Weather Station: Davis Vantage Pro2
Operating System: Windows 11 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: 3292
Joined: Tue 09 Dec 2008 1:37 pm
Weather Station: None !
Operating System: W10 - Threadripper 16core, etc
Location: Dudley, West Midlands, UK

Re: Lightning notification

Post by beteljuice »

Edit: see viewtopic.php?p=145191#p145191 for 'final' code

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 .....
Last edited by beteljuice on Thu 13 Aug 2020 12:53 pm, edited 1 time in total.
Image
......................Imagine, what you will KNOW tomorrow !
Mapantz
Posts: 1778
Joined: Sat 17 Dec 2011 11:55 am
Weather Station: Davis Vantage Pro2
Operating System: Windows 11 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
Mapantz
Posts: 1778
Joined: Sat 17 Dec 2011 11:55 am
Weather Station: Davis Vantage Pro2
Operating System: Windows 11 x64
Location: Dorset - UK
Contact:

Re: Lightning notification

Post by Mapantz »

Slight issue..

It's just started flashing even though lightning was detected 16 hours ago. :shock:

Code: Select all

$lightningMinAgo = "8,5,5,07,27,2020";
Image
Mapantz
Posts: 1778
Joined: Sat 17 Dec 2011 11:55 am
Weather Station: Davis Vantage Pro2
Operating System: Windows 11 x64
Location: Dorset - UK
Contact:

Re: Lightning notification

Post by Mapantz »

It's flashing after midnight, every single night now. I'm not sure what time it stops, somewhere between 3 and 6am, I think?!
Image
User avatar
ConligWX
Posts: 1573
Joined: Mon 19 May 2014 10:45 pm
Weather Station: Davis vPro2+ w/DFARS + AirLink
Operating System: Ubuntu 22.04 LTS
Location: Bangor, NI
Contact:

Re: Lightning notification

Post by ConligWX »

Mapantz wrote: Thu 30 Jul 2020 11:03 pm It's flashing after midnight, every single night now. I'm not sure what time it stops, somewhere between 3 and 6am, I think?!
Is there any caching of the values perhaps? are you running opcache at all?
Regards Simon

https://www.conligwx.org - @conligwx
Davis Vantage Pro2 Plus with Daytime FARS • WeatherLink Live • Davis AirLink • PurpleAir •

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

Re: Lightning notification

Post by Mapantz »

Definitely not a caching issue. The last code that beteljuice produced wasn't able to be tested until a close lightning strike 3 days ago, and so that's when it started occurring. It should only flash if the time of the last recorded strike is within the last 30 minutes. It now starts flashing each day, from midnight. I have a feeling it stops at 3am, but I am usually asleep by then. :lol:

Code: Select all

<?php if ($lightningMinAgo != "---" && $lightningMinAgo <= 30) { ..
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: Lightning notification

Post by beteljuice »

Sounds like something strange with Cumulus on date change ....
Edit: see viewtopic.php?p=145191#p145191 for 'final' codeTime for some debug :o

Code: Select all

$lightningMinAgo = "<#LightningTime format="H,m,s,MM,d,yyyy">";
echo "\n<!-- Cu H,m,s,MM,d,yyyy = ".$lightningMinAgo." -->\n; // debug
if($lightningMinAgo != "---") $lightningMinAgo = (time() - mktime($lightningMinAgo)) / 60;
echo "\n<!-- Now: ".date(DATE_RFC822)." -->\n<!-- actual mins ago = ".$lightningMinAgo." -->\n; // debug


<?php if ($lightningMinAgo != "---" && $lightningMinAgo <= 30) { echo '<span class="ligh .....
When it goes wrong - just view page source to see what's happening.
Last edited by beteljuice on Thu 13 Aug 2020 12:53 pm, edited 1 time in total.
Image
......................Imagine, what you will KNOW tomorrow !
Post Reply