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

PHP Error

Discussion of Ken True's web site templates

Moderator: saratogaWX

User avatar
sparkynerd
Posts: 36
Joined: Wed 14 Jan 2015 10:08 pm
Weather Station: Davis Vantage Vue
Operating System: Windows, Linux (various)
Location: United States

PHP Error

Post by sparkynerd »

I have my website up and running other than a few errors in the "Moon" section of the webpage:

Notice: Undefined offset: 1 in F:\xampp\htdocs\weather3\ajax-dashboard.php on line 1153
Notice: Undefined offset: 2 in F:\xampp\htdocs\weather3\ajax-dashboard.php on line 1154
Notice: Undefined offset: 3 in F:\xampp\htdocs\weather3\ajax-dashboard.php on line 1155


It seems to load the moon section on the very first load of the webpage, but when it is refreshed, the errors pop up.

... and the code from ajax-dashboard.php, lines 1148-1157

Code: Select all

1148 function moonphase ($WDmoonage) {
1149  
1150 preg_match_all('|(\d+)|is',$WDmoonage,$matches);
1151 print "<!-- matches=\n" . print_r($matches,true) . "-->\n";
1152 $mdays = $matches[1][0];
1153 $mhours = $matches[1][1];
1154 $mmins = $matches[1][2];
1155  $mpct  = $matches[1][3];
1156 
1157 $mdaysd = $mdays + ($mhours / 24) + ($mmins / 1440);
Can anyone help me with this problem? Thanks!
__________
Davis Vantage Vue
Cumulus MX 3.25.2 b3245
User avatar
sparkynerd
Posts: 36
Joined: Wed 14 Jan 2015 10:08 pm
Weather Station: Davis Vantage Vue
Operating System: Windows, Linux (various)
Location: United States

Re: PHP Error

Post by sparkynerd »

Something else I noticed that may be related- the page does not automatically update. Not sure if this is related?
__________
Davis Vantage Vue
Cumulus MX 3.25.2 b3245
uncle_bob
Posts: 505
Joined: Wed 17 Aug 2011 2:58 pm
Weather Station: WeatherDuino Pro2
Operating System: 2008
Location: Canberra

Re: PHP Error

Post by uncle_bob »

Xampp has strict error reporting on by default.
Comment out this line in your php.in:

Code: Select all

E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED
or the like and add this line

Code: Select all

error_reporting = E_COMPILE_ERROR|E_ERROR|E_CORE_ERROR
display_errors = Off
(I've just been through this one :) )
Last edited by uncle_bob on Thu 19 Feb 2015 12:37 pm, edited 3 times in total.
Interested in building your own Weather Station? Maybe check out the WeatherDuino Pro Project Here
Conder, Canberra Weather
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: PHP Error

Post by beteljuice »

Is it my eyes or aren't they both the same ?
... and where are the closing ; ?
Image
......................Imagine, what you will KNOW tomorrow !
uncle_bob
Posts: 505
Joined: Wed 17 Aug 2011 2:58 pm
Weather Station: WeatherDuino Pro2
Operating System: 2008
Location: Canberra

Re: PHP Error

Post by uncle_bob »

beteljuice wrote:Is it my eyes or aren't they both the same ?
... and where are the closing ; ?
It's your eyes ;)
There's no closing ";"s in my php.ini (I'm no expert on this stuff though)
Interested in building your own Weather Station? Maybe check out the WeatherDuino Pro Project Here
Conder, Canberra Weather
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: PHP Error

Post by beteljuice »

Yup - It's my eyes :bash:

Didn't notice the reference to .ini, and didn't notice the negation - sorry :oops:

Definately need a lie down in a darkened room ....
Image
......................Imagine, what you will KNOW tomorrow !
User avatar
SpaceWalker
Posts: 67
Joined: Sun 04 Mar 2012 2:54 am
Weather Station: Davis Vantage
Operating System: Windows XP
Location: Eastern-Canada
Contact:

Re: PHP Error

Post by SpaceWalker »

Xampp has strict error reporting on by default.
Comment out this line in your php.in:...
This is probably ONE OF THE worst suggestion one could make: Preventing PHP from displaying running errors! :shock:

If there are errors in a script, they have to be corrected and not simply hidden from display! One can learn from seeing script errors and making an effort to correct them! :roll:


'sparkynerd' I had a very quick look at the 'ajax-dashboard.php' script for a possibly reason why those errors are displayed. A multi-dimensional array is supposed to be created at line 1150 and its elements are then extracted in lines 1152, 1153, 1154 and 1155. It appears the multi-dimensional array is empty (is not created) and thus contains no element to be extracted.

I could not reproduce your problem as my version of the 'ajax-dashboard.php' script is highly modified and the function used to extract the information about the moon phase is getting its data from another function (rather than trying to get that data from an external source).

I will check later on if I can find anything additional.

Oh, 'sparkynerd', one last comment before submitting this reply: If you want to learn more about PHP programming, such as on an XAMPP local server, I strongly suggest that you do not deactivate the PHP error reporting, otherwise, you will not know when there are errors within your scripts that need to be corrected in order for the scripts to produced the expected results...
R_o_B
There are no Time and Movement if there is no Space.
There are no Movement and Space without Time.
There are no Space and Time without Movement.
But if one of the three exists also the other two exist.
User avatar
sparkynerd
Posts: 36
Joined: Wed 14 Jan 2015 10:08 pm
Weather Station: Davis Vantage Vue
Operating System: Windows, Linux (various)
Location: United States

Re: PHP Error

Post by sparkynerd »

Thanks to everyone for the suggestions! I tend to agree with not disabling error reporting, as its sort of a "band-aid." I am sort of new still at PHP programming, and this error is not anything I have seen before. I always try to reverse engineer the code and figure out the problem that way, but this one I cant seem to solve. I am using the stock template with no custom code... yet...
__________
Davis Vantage Vue
Cumulus MX 3.25.2 b3245
User avatar
SpaceWalker
Posts: 67
Joined: Sun 04 Mar 2012 2:54 am
Weather Station: Davis Vantage
Operating System: Windows XP
Location: Eastern-Canada
Contact:

Re: PHP Error

Post by SpaceWalker »

sparkynerd wrote:...I tend to agree with not disabling error reporting, as its sort of a "band-aid."
Good decision - as you wrote, deactivating the reporting of errors/warnings by PHP is a really poor technique in dealing with poorly written PHP scripts and designers too lazy to make their code error free.

And no one will ever learn anything about PHP if errors/warnings are not displayed and the code producing those same errors/warnings is not corrected to, not just hide the errors/warnings, but eliminate those errors/warnings.
I always try to reverse engineer the code and figure out the problem that way...
This is your only way to learn something about PHP. You must also make good use of the documentation from the PHP which can be downloaded from the PHP website in the '.chm' Windows compatible help file - I suggest that you download the larger size 'Help file (with user notes)' as it is nice to see all those examples/suggestions by many users.

You might also want to have a look at the W3Schools web site - a good place with good references and many tutorials.
I am using the stock template with no custom code... yet...
Well, I installed a new copy of the templates and did some basic settings. Unfortunately, I could not reproduce the errors. I looked at the function 'moonphase' (starting at line # 1148); I looked at the locations where that function is called (or used) (at lines # 835 and 841); I then looked at the location where the variable '$moonage' comes from (is produced); since you are probably using Cumulus to produce the data files required by the templates, the variable '$moonage' is created at line # 285 but, indeed, there is a 'but' the variable '$moonage' is only created if it does not already exists, meaning that another script has not already produced a variable with the name '$moonage'. YOu can easily check for that possibility by temporarily inserting a new line of code, such as:

Code: Select all

  if(!isset($moonagedays))  {$moonagedays = $mooninfo->pic; }
  if(!isset($moonage))      {$moonage = 'Moon age: '.$mooninfo->age.','.$mooninfo->ill.'%'; }
to:

Code: Select all

  if(!isset($moonagedays))  {$moonagedays = $mooninfo->pic; }
echo '<br>isset($moonage) == '.(isset($moonage)?'true':'false'); // new/temporary line
  if(!isset($moonage))      {$moonage = 'Moon age: '.$mooninfo->age.','.$mooninfo->ill.'%'; }
Note: Before editing any script, make sure you make a backup copy of that script.
Once that line has been added and the script has been save, using your browser, call the 'ajax-dashboard.php', such as:

Code: Select all

http://localhost/weather3/ajax-dashboard.php
If the variable '$moonage' has not already been created by another script, on the top left side of the display, you should see the following:

Code: Select all

isset($moonage) == false
If the display shows:

Code: Select all

isset($moonage) == true
then you know a setting somewhere or another script is creating the variable '$moonage' and possibly putting a value into it.

This ends 'Part One' of the 'reverse engineering' of the code of the 'ajax-dashboard.php' script... ;)
R_o_B
There are no Time and Movement if there is no Space.
There are no Movement and Space without Time.
There are no Space and Time without Movement.
But if one of the three exists also the other two exist.
User avatar
sparkynerd
Posts: 36
Joined: Wed 14 Jan 2015 10:08 pm
Weather Station: Davis Vantage Vue
Operating System: Windows, Linux (various)
Location: United States

Re: PHP Error

Post by sparkynerd »

Well explained response! You are correct, I am using cumulus. It seems like on the first load of the page, there are no errors, but refreshing the page causes the errors. I am going to try the code change and see what I can find out. Great suggestion making a backup first! I have learned this the hard way too many times... as a "tweaker", I am always tinkering with a new device, firmware, etc. I will have something 99% working, and then a bad code change borks everything! :o Good reminder to all... Make a backup first! I have looked at W3schools before and it is a great reference. I dabbled in php slightly when I made a TP-Link router host a home-made home automation website. LOTS of trial and error! Anyways, I will change the code and see what's going on with that variable, and I will post the results. Thanks!
__________
Davis Vantage Vue
Cumulus MX 3.25.2 b3245
User avatar
sparkynerd
Posts: 36
Joined: Wed 14 Jan 2015 10:08 pm
Weather Station: Davis Vantage Vue
Operating System: Windows, Linux (various)
Location: United States

Re: PHP Error

Post by sparkynerd »

Ok- I put the "echo" code into ajax-dashboard.php. I had to put it all the way at the end of the script for it to display on the page. I loaded the page and it returns "isset($moonage) == true". So this tells me that the variable $moonage already has a value when the page is loaded. Since this problem seems to happen mainly on a manual page refresh, could this be because the variable was already assigned a value before the page was refreshed? The page never refreshes automatically at the time listed, which is why I manually refreshed it. Should I be tracking down why the page (data) doesn't update automatically? In my limited understanding, I would think the variable is assigned a value, the page is loaded. Then the variable is updated, and the page (data) is refreshed at the preset interval. Am I on the right track here, or way off base?
__________
Davis Vantage Vue
Cumulus MX 3.25.2 b3245
User avatar
sparkynerd
Posts: 36
Joined: Wed 14 Jan 2015 10:08 pm
Weather Station: Davis Vantage Vue
Operating System: Windows, Linux (various)
Location: United States

Re: PHP Error

Post by sparkynerd »

I just verified the behavior on another pc. When the ajax-dashboard.php page first loads, there are no errors in the "moon" section. When I refresh, the error pops up. I also have errors at the top of the page:

Notice: Undefined variable: temperature in F:\xampp\htdocs\weather\ajax-dashboard.php on line 131
Notice: Undefined offset: 1 in F:\xampp\htdocs\weather\ajax-dashboard.php on line 1142
__________
Davis Vantage Vue
Cumulus MX 3.25.2 b3245
User avatar
MackerelSky
Posts: 141
Joined: Fri 01 Apr 2011 8:14 pm
Weather Station: Davis VP2 w/FARS
Operating System: Toshiba Laptop Windows 7 x64
Location: Smethport, Pa.
Contact:

Re: PHP Error

Post by MackerelSky »

On the problem with the moon data and refresh, did you configure 'get-USNO-sunmoon.php' properly?

Brad
Davis VP2/FARS
Cumulus 1.9.4(1092)

McKean Weather
'cause not everyone lives at the airport

Image
User avatar
SpaceWalker
Posts: 67
Joined: Sun 04 Mar 2012 2:54 am
Weather Station: Davis Vantage
Operating System: Windows XP
Location: Eastern-Canada
Contact:

Re: PHP Error

Post by SpaceWalker »

I put the "echo" code into ajax-dashboard.php. I had to put it all the way at the end of the script for it to display on the page.
You cannot do that and expect the appropriate results! ;)

I should have been 'clearer' (more clear) that you had to load the 'ajax-dashboard.php' script only and not the 'wxindex.php' script (main page). Since the error/warning messages are coming from the 'ajax-dashboard.php' script, to find out which part of the code is creating those messages, there is no need to load anything else.

Note: You probably will have to adjust some of the settings inside the 'ajax-dashboard.php' script before you can using it in a 'stand-alone' mode.

I suggested the specific location (just before line # 284) because this is where the variable '$moonage' is seen by the script for the first time.
Since this problem seems to happen mainly on a manual page refresh, could this be because the variable was already assigned a value before the page was refreshed?
The first time the 'ajax-dashboard.php' script is processed (or run) through PHP, if the variable '$moonage' has not yet been set (meaning that the variable contains no data), then, at line # 284 of the 'ajax-dashboard.php' script, the variable '$moonage' is being set with some data:

Code: Select all

$moonage <=> Moon age: 1 days, 13 hours, 21 minutes,3%
When the page is refreshed, since the variable '$moonage' contains some data, it is being ignored - the PHP function 'isset()' will check a variable (such as '$moonage') and will return 'true' if that variable exists and that variable contains some data (other than NULL or FALSE).
Should I be tracking down why the page (data) doesn't update automatically?
That is another experiment that should take place once you have solve the present problems... ;)

Now, to answer Brad's message: The 'get-USNO-sunmoon.php' script does not produce the variable '$moonage' - the 'get-USNO-sunmoon.php' script downloads and produces mostly sun and moon related variables. The different phases of the moon as well as its age and illumination are produced by the PHP function 'cGetMoonInfo()' - that function is located inside the 'common.php' script.
R_o_B
There are no Time and Movement if there is no Space.
There are no Movement and Space without Time.
There are no Space and Time without Movement.
But if one of the three exists also the other two exist.
User avatar
sparkynerd
Posts: 36
Joined: Wed 14 Jan 2015 10:08 pm
Weather Station: Davis Vantage Vue
Operating System: Windows, Linux (various)
Location: United States

Re: PHP Error

Post by sparkynerd »

Brad-

I did not change the 'get-USNO-sunmoon.php' script, but I just did. I wasn't aware of the settings in there... thanks!

SpaceWalker-
You cannot do that and expect the appropriate results!
If I put the "echo" in at line 284, it doesnt seem to display anything? I removed the "echo" from the end of the script and inserted it at line #284, but it doesnt display anything. Here are lines 283-285:

Code: Select all

if(!isset($moonagedays))  {$moonagedays = $mooninfo->pic; }
    echo '<br>isset($moonage) == '.(isset($moonage)?'true':'false'); // new/temporary line
    if(!isset($moonage))      {$moonage = 'Moon age: '.$mooninfo->age.','.$mooninfo->ill.'%'; }
I should have been 'clearer' (more clear) that you had to load the 'ajax-dashboard.php' script only and not the 'wxindex.php' script (main page). Since the error/warning messages are coming from the 'ajax-dashboard.php' script, to find out which part of the code is creating those messages, there is no need to load anything else.
Actually, I did understand that part, and I did load just the ajax-dashboard.php.
The first time the 'ajax-dashboard.php' script is processed (or run) through PHP, if the variable '$moonage' has not yet been set (meaning that the variable contains no data), then, at line # 284 of the 'ajax-dashboard.php' script, the variable '$moonage' is being set with some data:
Code:
$moonage <=> Moon age: 1 days, 13 hours, 21 minutes,3%
My line #284 has the following code:

Code: Select all

if(!isset($moonage))      {$moonage = 'Moon age: '.$mooninfo->age.','.$mooninfo->ill.'%'; }
I am not sure where to go from here- thanks for your patience!
__________
Davis Vantage Vue
Cumulus MX 3.25.2 b3245
Post Reply