Php webtags: Difference between revisions

From Cumulus Wiki
Jump to navigationJump to search
2,545 bytes added ,  20:27, 17 May 2021
m
 
(7 intermediate revisions by the same user not shown)
Line 72: Line 72:


== Option 3: JavaScript Object Notation ==
== Option 3: JavaScript Object Notation ==
Anybody using Cumulus MX is already using this option if they are set up to use the example web pages provided in the software package.


This is a lightweight data-interchange format (JSON) that is easy for humans to read and write, but critically it is easy for machines to parse and generate for transferring the variables in a portable way.
This is a lightweight data-interchange format (JSON) that is easy for humans to read and write, but critically it is easy for machines to parse and generate for transferring the variables in a portable way.


Cumulus MX uses this approach to provide variables for plotting the charts on your web site (Trends web page).
The 3.10.1 release of MX has functionality to optionally generate and upload many more json files for transfers to the external web server - see [[:Category:JSON_Files#Data_Transfer_Format]].
 
<div style="background: LemonChiffon;padding:5px; margin:2px;">
[[File:Crystal Clear info.png|40px]] This document was written for a MX release that is no longer latest!
 
'''The 3.10.1 release of MX changes the settings referenced below'''
</div>
 
Cumulus MX beta (and releases up to 3.9.8) uses this approach solely to provide variables for plotting the charts on your web site (Trends web page).
*To have the json files uploaded to your web site, you must enable '''Include standard files''' within the ''Web/FTP settings'' section of '''Internet Settings'''.
*To have the json files uploaded to your web site, you must enable '''Include standard files''' within the ''Web/FTP settings'' section of '''Internet Settings'''.
*Cumulus MX has one json file per weather chart
*Cumulus MX has one json file per weather chart
Line 82: Line 92:
*The interval between sub-arrays (time and value pairs) depends on the chart, for daily rain and daily temperature there is a sub array for each day; but for most there is a sub-array for every minute (assuming Cumulus is left running for long enough) for a full 24 hours.  
*The interval between sub-arrays (time and value pairs) depends on the chart, for daily rain and daily temperature there is a sub array for each day; but for most there is a sub-array for every minute (assuming Cumulus is left running for long enough) for a full 24 hours.  


For the admin interface, the Cumulus MX engine has to pass information to and from the admin interface, this is done using an application programming interface for each transfer (and each interface uses json format).
For the admin interface, the Cumulus MX engine has to pass information to and from the admin interface, this is done using an [[MX_Administrative_Interface#The_API_interface|application programming interface]] for each transfer (and each interface uses json format).


If you want to set up your own json files, you may follow the same approach but need to choose the interval between such sub-arrays that suits your use in your web pages.
If you want to set up your own json files, you may follow the same approach but need to choose the interval between such sub-arrays that suits your use in your web pages.
Line 159: Line 169:
** Check your choice of read-made script can output dates in the format you prefer.
** Check your choice of read-made script can output dates in the format you prefer.


==== Time format =====
==== Time format ====
*Do you prefer 24-hour clock (some call this timetable format or military format) or 12 hour clock with am/pm?
*Do you prefer 24-hour clock (some call this timetable format or military format) or 12 hour clock with am/pm?
**Some ready made scripts may express times in both formats so you can choose the format you want
**Some ready made scripts may express times in both formats so you can choose the format you want
Line 404: Line 414:
#Edit the screen columns as indicated by red in the figure:
#Edit the screen columns as indicated by red in the figure:
#*in one of the local side boxes (under the 'Local filenames' header), enter the path (directory\file) to where you have stored the template:<br>e.g. '''your_customised_template_location\cumuluswebtags.txt'''<br> (you can use the 'Browse' button to find and select the exact location of the file);<br><br>
#*in one of the local side boxes (under the 'Local filenames' header), enter the path (directory\file) to where you have stored the template:<br>e.g. '''your_customised_template_location\cumuluswebtags.txt'''<br> (you can use the 'Browse' button to find and select the exact location of the file);<br><br>
#*in one of the remote side boxes (under the 'Remote filenames' header), enter the name '''cumuluswebtags.inc''':
#*in one of the remote side boxes (under the 'Remote filenames' header), enter the name '''cumuluswebtags.inc''' (in image it shows ''cumuluswebtags.php'', both are acceptable as explained above):
#** -- if needed add the relative server path (see Cumulus Help for explanation) before the file name;
#** -- if needed add the relative server path (see Cumulus 1 Help for explanation) before the file name;
#** (-- if you are using a local server, and want Cumulus to do a 'copy' instead of using 'FTP' then specify the full path for the destination file here);
#** (-- if you are using a local server, and want Cumulus to do a 'copy' instead of using 'FTP' then specify the full path for the destination file here);
#** -- ''notice that the file extension has been changed from'' '''txt''' (on the left side) to '''inc''' (on the right side) ''simply to help the remote file to be recognised on the web server;''
#** -- ''notice that the file extension has been changed from'' '''txt''' (on the left side) to '''inc''' (on the right side) ''simply to help the remote file to be recognised on the web server;''
Line 420: Line 430:


=== Cumulus MX ===
=== Cumulus MX ===
It is broadly similar for Cumulus MX.
It is broadly similar for Cumulus MX.
# Select '''Settings''' menu in the user interface, then select the ''Extra Files'' page. Scroll through to a page with empty rows if necessary.[[File:Extra.PNG|right|'Screenshot Cumulus v3.5.3']]
 
# The local file name column does not have the browse selection available in the equivalent Cumulus 1 feature. So be very careful that you type in the full path correctly. You don't need a drive selector, Cumulus will assume the file is on same drive as the MX executable, so only specify drive if it is somewhere else. You might have a feature that allows you to do a list of files and for the file picked show its path, if so you can copy that path into the box in the Local files column.
# Select '''Settings''' menu in the admin interface, then select the ''Extra Files'' page.  
#Scroll through to a page with empty rows if necessary.[[File:Extra.PNG|right|'Screenshot Cumulus v3.5.3']]
#*The local file name column does not have the browse selection available in the equivalent Cumulus 1 feature. So be very careful that you type in the full path correctly. You don't need a drive selector, Cumulus will assume the file is on same drive as the MX executable, so only specify drive if it is somewhere else.  
#*You might have a feature that allows you to do a list of files and for the file picked show its path, if so you can copy that path into the box in the Local files column.
#*In the illustration (that does not have the default background for admin interface, but ignore that) each local filename uses ".cum" extension, but as already mentioned just match whatever file(s) you are using.
#* In the example illustrated there are 4 web tag templates, each containing the web tags that are to be processed at a different frequency, all following advice on this page:
#* In the example illustrated there are 4 web tag templates, each containing the web tags that are to be processed at a different frequency, all following advice on this page:
#*# one ('static') only needs to be processed once, it is shown as using EOD here, but actually you would use real-time once, and then delete the local name so Cumulus did not try to process it again.
#*# one ('static') only needs to be processed once, it is shown as using EOD here, but actually you would use real-time once, and then delete the local name so Cumulus did not try to process it again.
Line 428: Line 443:
#*# one ('standard_update') is processed and uploaded at the standard uploading interval
#*# one ('standard_update') is processed and uploaded at the standard uploading interval
#*# the remaining one is processed and uploaded at the last task when [[Cumulus_MX#MX_End_of_Day_Process|the MX_End_of_Day_Process]] runs.
#*# the remaining one is processed and uploaded at the last task when [[Cumulus_MX#MX_End_of_Day_Process|the MX_End_of_Day_Process]] runs.
# The remote filename column needs to contain the FTP path and required destination file name if you want Cumulus MX to FTP the processed file to your web server. If you have your web server on the same local network as the device where you run the MX engine, then MX can use copy to transfer the file to your web server and you need the full path and file name relative to where the Cumulus executable is stored (again you don't need the drive if same drive).
# The remote filename column needs to contain the FTP path and required destination file name if you want Cumulus MX to FTP the processed file to your web server.
# You must have a tick in the process column, your template file (or files) will not be valid PHP until Cumulus MX has processed it and each PHP variable has a value.
#*As already said, the filename used here needs to match what you will use in your includes, the file extension could be ".inc" to make its usage clear or (as illustrated) it could be ".php" to remind you of the language used in the file.
# If you want your file processed and uploaded at the real-time interval you put a tick in the realtime column.
#*If you have your web server on the same local network as the device where you run the MX engine, then MX can use copy to transfer the file to your web server and you need the full path and file name relative to where the Cumulus executable is stored (again you don't need the drive if same drive as executable).
# You must have a tick in the process column, your template file (or files) will not contain any values until Cumulus MX has processed it and replaced each web tag.
#If you have followed the instructions above and saved your file in UTF-8 encoding, tick the '''UTF8''' column.
#Leave the '''Binary''' column unticked.
#Unless your web server is on the same local network as your Cumulus software, tick the '''FTP''' column.
 
'''Choosing the uploading interval'''
# If you want your file processed and uploaded at the real-time interval you put a tick in the real-time column. You would choose this for all tags representing current conditions or related to today and so likely to keep updating during the day.
#*Note that Cumulus cannot process a file at the real-time interval unless you have enabled the real-time timer ('''Internet settings''' page, ''Web/FTP settings'' section, tick '''Enable Realtime''')
#*Note that Cumulus cannot process a file at the real-time interval unless you have enabled the real-time timer ('''Internet settings''' page, ''Web/FTP settings'' section, tick '''Enable Realtime''')
#*Note that Cumulus cannot upload a file by FTP at the real-time interval unless you have set a FTP process to happen at real-time interval ('''Internet settings''' page, ''Web/FTP settings'' section, tick '''Enable realtime FTP''')
#*Note that Cumulus cannot upload a file by FTP at the real-time interval unless you have set a FTP process to happen at real-time interval ('''Internet settings''' page, ''Web/FTP settings'' section, tick '''Enable realtime FTP''')
#Unless your web server is on the same local network as your Cumulus software, tick the '''FTP''' column.
#If you want your file processed and uploaded at the start of a new meteorological day (when the end of previous day has been completed) you put a tick in the '''End of Day''' column. Remember, at this stage Cumulus will have the new date in every date type tag, it will have initialised the monthly tags to be empty (so don't include those tags if processing at this interval), and the yesterday tags will have been set (so those tags should be processed at this interval).
#If you have followed the instructions above and saved your file in UTF-8 encoding, tick the '''UTF8''' column.
#If you have not ticked the real-time column, nor ticked the EOD column, your file will be uploaded at the normal uploading interval. You will probably use this interval for tags relating to month and year that would benefit from being updated more trhan just at end of day, but don't really need to be updated as often as web tags for current conditions.
#Leave the '''Binary''' column unticked.
#If you have not ticked the real-time column, your file will be uploaded at the normal uploading interval unless you tick the '''End of Day''' column. If you do tick here, then your file will be uploaded right at the end of the rollover process, at this stage Cumulus will have the new date in every date type tag, it will have initialised the monthly tags to be empty, and the yesterday tags will have been set. In other words, you will only use this option if you have other web tag templates being uploaded during the day.


==Example==
==Example==
Line 444: Line 464:
<pre>
<pre>
<?php  
<?php  
  require_once("cumuluswebtags.php");
  require_once("cumuluswebtags.inc");
  echo $time;
  echo $time;
  echo "<br/>";
  echo "<br/>";
Line 460: Line 480:
See [[Sensor_Contact_PHP]] for another example script that uses this file.
See [[Sensor_Contact_PHP]] for another example script that uses this file.


==Debugging==
==Viewing the PHP==
 
Any PHP only exists on the web server, all a browser can see is the generated HTML, so this is what you see if you use the web browser's View Source option. As explained in [[PHP]] article not showing PHP has security advantages protecting content that might include stuff you don't want the public to see and preventing unauthorised changing of the script file. (Javascript files can be seen normally and most browsers provide an option to edit them).
 
Some authors when writing a script using PHP do include a downloading option at the start of the script before any other output. These downloaders allow you to see the actual PHP script. Unfortunately, there is no rule on how you invoke this downloader. I tried hard to get standardisation; see [https://cumulus.hosiene.co.uk/viewtopic.php?f=14&t=16425 Source Listing suggestion] in the forum. Another problem my suggestion addressed was the possibility that a web page includes multiple PHP scripts, and the downloader may list a different one to that you wanted to see.
 
Here are some querystrings you might try, in the brandon script download the PHP by appending the querystring <tt>?source=view</tt> to the end of the URL. Other templates might expect you to add the querystring <tt>?parse=source</tt>, <tt>download=source</tt>, <tt>sce=view</tt>,  or reversing the first idea <tt>?view=source</tt>. There are several other variants including <tt>"?view=getorfmiland</tt>.
 


If you wish to view all the values contained within a template file , some files (e.g. the brandon script) let you do this by appending the querystring <tt>?source=view</tt> to the end of the URL. Other templates expect you to add the querystring <code>?parse=source</code> and still others use <tt>?view=source</tt>. There may even be other variants. I tried hard to get standardisation see [https://cumulus.hosiene.co.uk/viewtopic.php?f=14&t=16425 Source Listing suggestion] in the forum, but I know of at least five other variants, source is abbreviated to 'sce' or 'src', and as well as parse, people use 'download'.


Example
Example
Line 469: Line 495:
This will display the source code of the file, listing all the variable names and the values Cumulus has assigned to the web tags during it's processing cycle. It won't show you the original template with web tags in it.
This will display the source code of the file, listing all the variable names and the values Cumulus has assigned to the web tags during it's processing cycle. It won't show you the original template with web tags in it.


[[Category:WebTools]][[Category:User Contributions]]
[[Category:WebTools]][[Category:User Contributions]][[Category:WebTips]]
5,838

edits

Navigation menu