Welcome to the Cumulus Support forum.

Latest Cumulus MX V4 release 4.3.3 (build 4070) - 04 January 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 on an error or if you need help PLEASE read this first viewtopic.php?p=164080#p164080

PHP Script for Website Seasonal Snowfall Data for CMX 4.3+

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

Moderator: daj

Post Reply
surban21
Posts: 49
Joined: Wed 07 Dec 2016 1:22 pm
Weather Station: Davis Vantage Vue
Operating System: Windows 10

PHP Script for Website Seasonal Snowfall Data for CMX 4.3+

Post by surban21 »

This script replaces a previous version that stopped working in CMX ver. 4.3 and above due to restructuring of the tables in diary.db.

Initial Release: version 1.0 Jan. 6, 2025 (use only with CMX 4.3 and above)

snowDisplay_v_1_0.zip

As some of you know, I'm not a dedicated programmer but I do enjoy tinkering around and sometimes come up with something I feel is useful. This project is one of those. I wanted a nice visual webpage to display seasonal snow fall information and thought, maybe, somebody else might find it useful. Please see image below which was using sample data at the time for testing. Constructive opinions, thoughts or feedback welcomed.

Thanks to PaulMy as portions of this script is inspired from komokaweather.com snowfall-log.pdf.

MUST have php installed on the same computer running CumulusMX to use this script. The zip contains the files necessary and a read_me text with install instructions.

Runs successfully in Cumulus MXUI web template and the standard CMX website template. Hasn't been tested on other templates but shouldn't be any reason it wouldn't work. For templates just add <?php include_once "./snowDisplay.php";?> where you want it to be displayed. Then for the standard CMX template just change the webpage extension from .htm to .php and update your menu to point to the .php page. The script can also be run as a standalone webpage.

Some key features in this program include;
  • Setting user defined variables such as; timezone, whether northern or southern hemisphere, unit of measure (inches or centimeter), the use of using a comma or dot (period) for decimal places
  • Setting a preferred language (default language is english).
  • Daily, Monthly and yearly cumulative snowfall and event totals
  • Cumulative days with snowfall
  • Cumulative snowfall depth
  • Average annual snowfall depth
  • Probability of snowfall %
pic of it used as an include in a template
Screenshot_snowDisplay_1_0.png
You do not have the required permissions to view the files attached to this post.
User avatar
PaulMy
Posts: 4230
Joined: Sun 28 Sep 2008 11:54 pm
Weather Station: Davis VP2 Plus 24-Hour FARS
Operating System: Windows8 and Windows10
Location: Komoka, ON Canada
Contact:

Re: PHP Script for Website Seasonal Snowfall Data for CMX 4.3+

Post by PaulMy »

MUST have php installed on the same computer running CumulusMX to use this script.
From where and how would I install PHP?

Enjoy,
Paul
VP2+
C1 www.komokaweather.com/komokaweather-ca
MX https://komokaweather.com/cumulusmx/index.htm /index.html /index.php
MX https://komokaweather.com/cumulusmxwll/index.htm /index.html /index.php
MX https:// komokaweather.com/cumulusmx4/index.htm
Image
water01
Posts: 3605
Joined: Sat 13 Aug 2011 9:33 am
Weather Station: Ecowitt HP2551
Operating System: Windows 10/11 64bit Synology NAS
Location: Burnham-on-Sea
Contact:

Re: PHP Script for Website Seasonal Snowfall Data for CMX 4.3+

Post by water01 »

David
Image
sutne
Posts: 488
Joined: Sun 14 Oct 2012 4:23 pm
Weather Station: HP2553 (WS80) and HP2564 (WS90)
Operating System: Raspbian Bullseye and Bookworm
Location: Rjoanddalen and Kronstad, Norway
Contact:

Re: PHP Script for Website Seasonal Snowfall Data for CMX 4.3+

Post by sutne »

Does it have to be run on the local CMX computer?
If the diary.db is uploaded to the web-server, I suppose this script can be included in the web-pages?
User avatar
lse-cumulus
Posts: 80
Joined: Mon 11 Jul 2022 3:39 am
Weather Station: Fine Offset Ecowitt
Operating System: Windows 11
Location: Austria
Contact:

Re: SnowDisplay.php js functions for monthly totals and cumulative totals seem only to work for latest year

Post by lse-cumulus »

Hi Steve,
I like your new scripts (espcially the streamlined snowQuery.php and wanted to integrate them into my site.
I adapted your scripts for php 5.3.x, but I had to remove the month name formatter for international calendar from snowDisplay.php as function IntlDateFormatter is not available before PHP 5.5.

Basically working fine, as seen here on my webpage https://leonas.ddns.net/Wetterstation.S ... isplay.php
But the Monthly totals and cumulative Totals are only shown during startup or when I select the latest year 2024/2025 (or when I refresh the browser)
See screenshot:
Leo.SnowDisplay.monthly.cumulative.Totals.ok.jpg
When I switch the years e.g. to 2023/2024 the daily data is switching to the correct yearly data, but the monthly totals and cumulative totals are not displayed.
See 2nd screenshot:
Leo.SnowDisplay.monthly.cumulative.Totals.NOK.jpg
.
When I go back to 2024/2025 the totals also remain empty, but with a browser refresh the totals are shown again.

Seems to be an issue in the javascript code. In that JS part of your snowDisplay.php script a did not make changes (only added a Number().toFixed(1) to solve an error reported in the F12 browser Console). Now I do not see any errors in F12 Console.
So I am wondering if this JS aggregation is working for you on your site (could not find a link to check it out) and the problem is only in my (modified) scripts, or if this is a general issue in the JS part of the code.
You do not have the required permissions to view the files attached to this post.
Leo

Ecowitt GW2000/WS90/Wittboy/GW1000/WS2910/WH65/WH31/WH34S/WH41/WH45/WH51/WH57/HP10/WN35
AWEKAS/CWOP/PWS/Weathercloud/Windy/WOW/WU/WxSim/CMX/CU
http://leonas.ddns.net/Wetterstation.Su ... CumulusMX/

Image
surban21
Posts: 49
Joined: Wed 07 Dec 2016 1:22 pm
Weather Station: Davis Vantage Vue
Operating System: Windows 10

Re: PHP Script for Website Seasonal Snowfall Data for CMX 4.3+

Post by surban21 »

sutne wrote: Sat 11 Jan 2025 7:45 am Does it have to be run on the local CMX computer?
If the diary.db is uploaded to the web-server, I suppose this script can be included in the web-pages?
I don't have the ability to try that so I can't say for sure. snowQuery.php does need access to the diary.db and I'm sure the paths in both files will need to be adjusted but with some tweaking I feel it could work. Unless I'm missing something.
surban21
Posts: 49
Joined: Wed 07 Dec 2016 1:22 pm
Weather Station: Davis Vantage Vue
Operating System: Windows 10

Re: SnowDisplay.php js functions for monthly totals and cumulative totals seem only to work for latest year

Post by surban21 »

lse-cumulus wrote: Sat 11 Jan 2025 1:14 pm Seems to be an issue in the javascript code. In that JS part of your snowDisplay.php script a did not make changes (only added a Number().toFixed(1) to solve an error reported in the F12 browser Console). Now I do not see any errors in F12 Console.
So I am wondering if this JS aggregation is working for you on your site (could not find a link to check it out) and the problem is only in my (modified) scripts, or if this is a general issue in the JS part of the code.
I don't have a public site but it is working for me on my local machine as well as other sites that I know have been using this publicly. I do have some time available if you want to attach a zip of the modified snowDisplay.php. I'll take a look at it and see what I can find. As a side note, I thought intlDateFormatter was available starting in php version 5.3. But I suppose i could easily have been mistaken.

Steve
Last edited by surban21 on Sat 11 Jan 2025 2:39 pm, edited 1 time in total.
User avatar
PaulMy
Posts: 4230
Joined: Sun 28 Sep 2008 11:54 pm
Weather Station: Davis VP2 Plus 24-Hour FARS
Operating System: Windows8 and Windows10
Location: Komoka, ON Canada
Contact:

Re: PHP Script for Website Seasonal Snowfall Data for CMX 4.3+

Post by PaulMy »

Thanks David,
https://windows.php.net/download/
I don 't think I have it on my Windows 10 PC yet, and so many options from that link. Which one(s) would be good to download, and any specific instructions?

Enjoy,
Paul
VP2+
C1 www.komokaweather.com/komokaweather-ca
MX https://komokaweather.com/cumulusmx/index.htm /index.html /index.php
MX https://komokaweather.com/cumulusmxwll/index.htm /index.html /index.php
MX https:// komokaweather.com/cumulusmx4/index.htm
Image
water01
Posts: 3605
Joined: Sat 13 Aug 2011 9:33 am
Weather Station: Ecowitt HP2551
Operating System: Windows 10/11 64bit Synology NAS
Location: Burnham-on-Sea
Contact:

Re: PHP Script for Website Seasonal Snowfall Data for CMX 4.3+

Post by water01 »

PaulMy wrote: Sat 11 Jan 2025 2:26 pm Thanks David,
https://windows.php.net/download/
I don 't think I have it on my Windows 10 PC yet, and so many options from that link. Which one(s) would be good to download, and any specific instructions?

Enjoy,
Paul
I use it to integrate with my web designer software so I can test it on the windows machine before I use it where it naturally resides on your website server.

To that end I always use the Non Thread safe version which is the one they advise to use with an ISS (Internet Information Services i.e. a web server).

The program I use uses the base php.exe which it calls from within it, so not having looked at this code (chances of me getting snow are fairly small, even in our current cold spell!!) so I do not know how it is used, but that is usual way i.e. calling the .exe.
David
Image
User avatar
lse-cumulus
Posts: 80
Joined: Mon 11 Jul 2022 3:39 am
Weather Station: Fine Offset Ecowitt
Operating System: Windows 11
Location: Austria
Contact:

Re: SnowDisplay.php js functions for monthly totals and cumulative totals seem only to work for latest year

Post by lse-cumulus »

surban21 wrote: Sat 11 Jan 2025 2:21 pm
lse-cumulus wrote: Sat 11 Jan 2025 1:14 pm Seems to be an issue in the javascript code. In that JS part of your snowDisplay.php script a did not make changes (only added a Number().toFixed(1) to solve an error reported in the F12 browser Console). Now I do not see any errors in F12 Console.
So I am wondering if this JS aggregation is working for you on your site (could not find a link to check it out) and the problem is only in my (modified) scripts, or if this is a general issue in the JS part of the code.
I don't have a public site but it is working for me on my local machine as well as other sites that I know have been using this publicly. I do have some time available if you want to attach a zip of the modified snowDisplay.php. I'll take a look at it and see what I can find. As a side note, I thought intlDateFormatter was available starting in php version 5.3. But I suppose i could easily have been mistaken.

Steve
Hi steve,
please find attached my modified version 1.1 ofr snowDisplay.php
You do not have the required permissions to view the files attached to this post.
Leo

Ecowitt GW2000/WS90/Wittboy/GW1000/WS2910/WH65/WH31/WH34S/WH41/WH45/WH51/WH57/HP10/WN35
AWEKAS/CWOP/PWS/Weathercloud/Windy/WOW/WU/WxSim/CMX/CU
http://leonas.ddns.net/Wetterstation.Su ... CumulusMX/

Image
User avatar
lse-cumulus
Posts: 80
Joined: Mon 11 Jul 2022 3:39 am
Weather Station: Fine Offset Ecowitt
Operating System: Windows 11
Location: Austria
Contact:

Re: PHP Script for Website Seasonal Snowfall Data for CMX 4.3+ (php 5.3 version 1.2 now accumuluates also)

Post by lse-cumulus »

Steve,
I think I solved my problem.
After debugging in Chrome F12 Console, I saw that the data in the snowDepthArray and snow24hrArray is not stored as Number but as String.
Therefore I added some Number() conversions in js function updateMonthlyAndCumulativeTables() before the typeof check was made to avoid that nothing was accumulated.

Code: Select all

// Accumulate data for the month
            for (let day = 1; day <= 31; day++) {
                const snowDepth = snowDepthArray[selectedYear]?. [monthStr]?. [
                    day
                ]; // Get snow depth for the day
                const snow24hr = snow24hrArray[selectedYear]?. [monthStr]?. [day]; // Get 24hr snow for the day

                // If there is snow on this day, accumulate the snow depth
                // leo: use Number() as data in snowDepthArray is stored as string and not as number; so that typeof works
                if (typeof Number(snowDepth) === 'number' && Number(snowDepth) > 0) {
                    totalSnowDepth = (totalSnowDepth || 0) + Number(snowDepth);
                    monthlyEventCount++; // Increase event count if snowDepth > 0
                }

                // If there is snow in the last 24 hours, accumulate the snow24hr
                // leo: use Number() as data in snow24hrArray is stored as string and not as number; so that typeof works
                if (typeof Number(snow24hr) === 'number' && Number(snow24hr) >= 0) {
                    totalSnow24hr = (totalSnow24hr || 0) + Number(snow24hr);
                    monthly24hrEventCount++; // Increase event count for 24hr snow if snow24hr > 0
                }
            }
The script now works on my CU website as intended
https://leonas.ddns.net/Wetterstation.S ... isplay.php

Attached my version 1.2 of snowDisplay.php.
You do not have the required permissions to view the files attached to this post.
Leo

Ecowitt GW2000/WS90/Wittboy/GW1000/WS2910/WH65/WH31/WH34S/WH41/WH45/WH51/WH57/HP10/WN35
AWEKAS/CWOP/PWS/Weathercloud/Windy/WOW/WU/WxSim/CMX/CU
http://leonas.ddns.net/Wetterstation.Su ... CumulusMX/

Image
surban21
Posts: 49
Joined: Wed 07 Dec 2016 1:22 pm
Weather Station: Davis Vantage Vue
Operating System: Windows 10

Re: PHP Script for Website Seasonal Snowfall Data for CMX 4.3+ (php 5.3 version 1.2 now accumuluates also)

Post by surban21 »

lse-cumulus wrote: Sat 11 Jan 2025 8:19 pm I think I solved my problem.
After debugging in Chrome F12 Console, I saw that the data in the snowDepthArray and snow24hrArray is not stored as Number but as String.
Therefore I added some Number() conversions in js function updateMonthlyAndCumulativeTables() before the typeof check was made to avoid that nothing was accumulated.
It's like trying to find a needle in a haystack. Glad it worked - but - I'm afraid this will count null as a number since it will treat null as 0. This will give you a false "Event" count. Look in the monthly totals for Jan in the NS column. you'll notice the count shows 4 when actually it should be 2. This will happen when either NS or TD contains a value but the other doesn't. When this happens, null has to be treated an object so it is not given a value of 0 and then counted in the "Events" row. This gave me all sorts of fits when I was writing the code and settled with what I had written. There may be other ways around this but I'm not sure, and I don't want to break what I have as it is working.

As a side note, may I ask why not upgrade php?

Steve
User avatar
lse-cumulus
Posts: 80
Joined: Mon 11 Jul 2022 3:39 am
Weather Station: Fine Offset Ecowitt
Operating System: Windows 11
Location: Austria
Contact:

Re: PHP Script for Website Seasonal Snowfall Data for CMX 4.3+

Post by lse-cumulus »

Steve,
thx for the hint that JS Number(null) gives 0. Now I understand your JS code better. I found a way to fix now also my event counters.
You are right that is a tricky coding, and the root cause is that the json_encode() from script snowQueury.php works differently in your and my PHP environment. So you need your JS code and I need my adaptations (and I introduced this transient problem by changing the snowQueury.php script in the first place ...).
I am happy that it works now also for me in my PWS environment: https://leonas.ddns.net/Wetterstation.S ... isplay.php
I appreciate your support.
The PHP Upgrade is on my backlog to do list but has to take into account some special dependencies in my web server environment.
Leo

Ecowitt GW2000/WS90/Wittboy/GW1000/WS2910/WH65/WH31/WH34S/WH41/WH45/WH51/WH57/HP10/WN35
AWEKAS/CWOP/PWS/Weathercloud/Windy/WOW/WU/WxSim/CMX/CU
http://leonas.ddns.net/Wetterstation.Su ... CumulusMX/

Image
Post Reply