Page 2 of 7

Re: PHP script to display monthly/yearly snow depth totals from diary.db

Posted: Thu 05 Jan 2023 1:54 pm
by surban21
@PaulMy - More logistics for me to think about. I guess the simple solution would be to install just the php program and reference that directory. For example where I have C:\xamp\php\php-win.exe, you'd likely put C:\php\php-win.exe. However, as I have just recently discovered CumulusMX only allows one program to be placed in each of the external program slots. I haven't tried this, but I suppose a way around that would be to make one .bat file to run php and the parameter for my file along with CUtils and its parameter then put the .bat file in CumulusMX external program to run. BUT that makes things a bit more complicated. I see now where it would be nice to have CMX be able to run more than one external program with its parameters. Unless I'm missing something. Still I wouldn't use anything other than CMX for my weather recording.

Thanks for giving it a go Paul. I'll have to rethink this but not so sure I can implement mine any differently as I need to parse snowSumData.php to grab the data from the db and do the other things needed.

Regards,
Steve

Re: PHP script to display monthly/yearly snow depth totals from diary.db

Posted: Fri 06 Jan 2023 12:27 am
by PaulMy
Hi,
Anything I can test for you, just let me know.

If I am able to get it working I'd see about adding the data from my Cumulus1 Log (going back to 2008) into CumulusMX diary which started in Dec 2019.

Enjoy,
Paul

Re: PHP script to display monthly/yearly snow depth totals from diary.db

Posted: Fri 06 Jan 2023 10:56 am
by surban21
I just might take you up on that @PaulMy. I'll continue to do some code cleaning but in the meantime here's hoping to a pain free install.Thank you.

Regards,
Steve

Re: PHP script to display monthly/yearly snow depth totals from diary.db

Posted: Mon 09 Jan 2023 8:28 pm
by surban21
Updated to ver 0.5 - Cleaned up some of the code in snowSummary.php making it easier reading and a bit more efficient. Same features as ver 0.4. If interested the zip file can be downloaded from the first post. Thanks

Re: PHP script to display monthly/yearly snow depth totals from diary.db

Posted: Sat 14 Jan 2023 7:57 pm
by Dador
I downloaded and installed the script according to the instructions. Everything seems to be working:

https://cmx.pogodarybnik.pl/snow/snowSummary.php

However, I'm having trouble getting it to work in a CMX page template. The script doesn't work with the include function. I do not know why. I have several different scripts, but only this one doesn't work properly for me.

https://cmx.pogodarybnik.pl/snieg.htm

Re: PHP script to display monthly/yearly snow depth totals from diary.db

Posted: Sun 15 Jan 2023 4:21 pm
by surban21
However, I'm having trouble getting it to work in a CMX page template. The script doesn't work with the include function. I do not know why. I have several different scripts, but only this one doesn't work properly for me.
@Dador - I haven't really run this using the CMX supplied webfiles as I use Silver Acorns MXUI Template v 2.2.5. However, I believe if you rename snieg.htm to snieg.php and include the snowSummary.php file where you need it inside your template it should work with some minor tweaking needed. The include should look something like this <?php include_once("./snowSummary.php"); ?>

Change your menu to call snieg.php instead of snieg.htm.

Good luck and thanks,
Steve

Re: PHP script to display monthly/yearly snow depth totals from diary.db

Posted: Sun 15 Jan 2023 4:41 pm
by Dador
surban21 wrote: Sun 15 Jan 2023 4:21 pm @Dador - I haven't really run this using the CMX supplied webfiles as I use Silver Acorns MXUI Template v 2.2.5. However, I believe if you rename snieg.htm to snieg.php and include the snowSummary.php file where you need it inside your template it should work with some minor tweaking needed. The include should look something like this <?php include_once("./snowSummary.php"); ?>

Change your menu to call snieg.php instead of snieg.htm.

Good luck and thanks,
Steve
Due to the fact that I have the entire CMX template in htm, I forgot about php. :bash:

Thanks for the hint, now everything works. ;)

Sometimes the simplest solutions are the hardest to come up with.

Re: PHP script to display monthly/yearly snow depth totals from diary.db

Posted: Sun 15 Jan 2023 4:56 pm
by surban21
Glad you have it working @Dador! BTW - there was a minor glitch in snowSummary.php where the days snowfall over amounts ie; >=1 and < 3 section is actually for inches. I have fixed this and it is in the zip file on the first page. You only need to grab the snowSummary.php file and replace it with the one you already have. If you want since you have done some modifications just go to the section in the snowSummary.php that you already have and go to the section commented as "# Displays Total Number of Days with Snowfall Amounts for each Month Summed Over All Years" change the code as below:

All ($hemi == 'N') to ($unit == 'in') and all ($hemi == 'S') to ($unit == 'cm')

OR - what you are doing works too. LOL :D


Thanks
Steve

Re: PHP script to display monthly/yearly snow depth totals from diary.db

Posted: Sun 15 Jan 2023 6:10 pm
by Dador
surban21 wrote: Sun 15 Jan 2023 4:56 pm
OR - what you are doing works too. LOL :D
Yes, I decided to copy some of the code and add my ranges. As you can see, I also translated everything into Polish.
I'll have a snowfall in a couple of days and see how that works out as I complete the weather diary.

Looks good, doesn't it? :D

As you can see your script works. :clap:
Add a footer with the author, that is with you.

Re: PHP script to display monthly/yearly snow depth totals from diary.db

Posted: Tue 17 Jan 2023 4:13 pm
by PaulMy
Hi Steve,
Still looking how I can run this script.
From the How to:
After deciding which one you're going to use enter the path and filename to your php executable file. ie; c:\xampp\php\php-win.exe. Inside the php folder there is usually a php.exe and a php-win.exe. php-win.exe will run silently whereas php.exe will briefly display a command window each time it is run. (alternatively, if the php path is included in your operating system variables path then you only need to enter php or php-win and not the entire path).
What do I need to download/install for that xampp\php\php-win.exe to be added to my PC so I can run it in External Programs? Or is there another way?

Enjoy,
Paul

Re: PHP script to display monthly/yearly snow depth totals from diary.db

Posted: Tue 17 Jan 2023 4:38 pm
by Dador
Paul,
take a look at it.

Settings -> Internet settings -> External Programs.

The script is executed once a day. And it works :)

Re: PHP script to display monthly/yearly snow depth totals from diary.db

Posted: Tue 17 Jan 2023 4:46 pm
by surban21
@PaulMy
I guess the simple solution would be to install just the php program and reference that directory. For example where I have C:\xamp\php\php-win.exe, you'd likely put C:\php\php-win.exe.
You can grab php at https://windows.php.net/download#php-8.2 and chose the appropriate install. I recommend the "Thread Safe" version.

As far as I know snowSummary.php must be processed on your local computer so it can grab your diary.db info. That's where the php program comes in.

Regards,
Steve

Re: PHP script to display monthly/yearly snow depth totals from diary.db

Posted: Tue 17 Jan 2023 10:46 pm
by PaulMy
Thanks Steve,
That is exactly what I needed. I have downloaded the program and have it set to run, and MXdiags indicate it does,

Code: Select all

2023-01-17 17:05:01.770 Interval: Processing extra file[14] - C:\KomokaWeather\CumulusMXwll\web-additions\ecowitt-extrasensorsT.txt
2023-01-17 17:05:01.773 Interval: Processing extra file[15] - C:\KomokaWeather\CumulusMXwll\webMX\snowSumDataT.txt
2023-01-17 17:05:01.774 Interval: Executing program C:\Programs-Added\PHP\php-8.2.1-nts-Win32-vs16-x64\php-win.exe C:\KomokaWeather\CumulusMXwll\webMX\snowSumData.php
2023-01-17 17:05:01.779 Interval: External program started
CMX is updating snowSumData.txt to my remote but it is empty http://www.komokaweather.com/cumulusmxw ... umData.txt
The cumulusmx.db is in the usual \CumulusMXwll\data folder and I add to it every day.
Nothing else in MXdiags that I can detect.

Any thoughts?

Enjoy,
Paul

Re: PHP script to display monthly/yearly snow depth totals from diary.db

Posted: Wed 18 Jan 2023 2:34 am
by surban21
@PaulMy
The cumulusmx.db is in the usual \CumulusMXwll\data folder and I add to it every day
Is this cumulusmx.db just the diary.db renamed? Does your db have the same data table/structure as diary db? If both of these are true then maybe some adjustment is needed in snowSumData.php in the user settings area at the top. Take a look at the database line "$myDbase = 'sqlite:\CumulusMX\data\diary.db';" and see if adjustments are necessary. In your screenshots your entries appear correct.

It appears to me there is no connection to your db. Also grab the updated snowSummary.php version from the zip file as there was a minor glitch in the way cm was called. This was the only file in the zip that was updated. Just copy it to your remote server directory and overwrite the existing one.

Steve

Re: PHP script to display monthly/yearly snow depth totals from diary.db

Posted: Wed 18 Jan 2023 4:02 pm
by PaulMy
Hi Steve,
That was my error in mentioning cumulusmx.db, The diary is in C:\KomokaWeather\CumulusMX\data\diary.db.

I have updated all the files from v_0_5. I have been trying but not successful as yet. One CMX that I have been trying is C:\KomokaWeather\CumulusMX which uploads to website www.komokaweather.com/cumulusmx. The CMX External Program - Interval has

Code: Select all

C:\KomokaWeather\CumulusMX\webMX\snowSumData.php
the default downloaded \webMX\snowSumData.php file had:

Code: Select all

$myDbase = 'sqlite:\CumulusMX\data\diary.db'; // <-- enter directory where diary.db located. DO NOT remove sqlite:
After an Interval run there was no new snowSumData.txt created in \webMX\, only the copied-in empty snowSumDataT.txt and snowSumData.php
MXdiags shows:

Code: Select all

2023-01-18 10:20:02.060 Interval: Executing program C:\Programs-Added\PHP\php-8.2.1-nts-Win32-vs16-x64\php-win.exe C:\KomokaWeather\CumulusMX\webMX\snowSumData.php

I then edited the \webMX\snowSumData.php by adding KomokaWeather\:

Code: Select all

$myDbase = 'sqlite:\KomokaWeather\CumulusMX\data\diary.db'; // <-- enter directory where diary.db located. DO NOT remove sqlite:
After the next Interval run again no new snowSumData.txt created in \webMX.
The MXdiags shows:

Code: Select all

2023-01-18 10:25:01.692 Interval: Executing program C:\Programs-Added\PHP\php-8.2.1-nts-Win32-vs16-x64\php-win.exe C:\KomokaWeather\CumulusMX\webMX\snowSumData.php
I have also tried other edits in the snowSumData.php like:

Code: Select all

$myDbase = 'sqlite:C:\KomokaWeather\CumulusMX\data\diary.db'; ...
And after the next interval Run the same result, no new snowSumData.txt created.

Maybe I've overlooked the obvious but have double/triple checked.

Is it possible that my install of CMX in C:\KomokaWeather\CumulusMX is the issue?
I have not found any other logging of the External Program activity so can't determine what the issue may be. Is there any setting possible to log the process of the External Program or the script?

Enjoy,
Paul