This page describes one way to let PHP reference data known to WeeWX, as well as a few other hints for how to make upgrading to new versions of WeeWX simpler. It is current as of WeeWX 5.1.
#raw $from_cheetah_month_wind_max_unclean = <<<EOS #end raw $month.wind.max #raw EOS; $from_cheetah_month_wind_max = month_clean_cheetah_string($from_cheetah_month_wind_max_unclean); #end raw
$from_cheetah_month_wind_max_unclean = <<<EOS 22 mph EOS; $from_cheetah_month_wind_max = month_clean_cheetah_string($from_cheetah_month_wind_max_unclean);
[[ToDate]]
[[[php_example]]]
template = php_example.php.tmpl
<html> <head> <title>PHP EXAMPLE Test</title> </head> <body> <!-- The include below helps grab WeeWX 'data' that you need to reference in your PHP file. The include file puts the data into PHP variables. --> #include "./private_extensions/php_example_cheetah_vars_to_php.tmpl" <p>Hi this would be part of a standard WeeWX HTML file, to be generated every five minutes. Pretend this is a 'standard skin file' from a WeeWX skin, extended to work with PHP.</p> <br> <p>Below, should be the extra information from PHP.</p> <br> #include "./private_extensions/php_example_extra.tmpl" <p>Did you see the information about the current temperature, above?</p> </body> </html>
## Note that including a file must reference its path from the top level ## skin directory, in this case /root/weewx-data/skins/Standard #include "./private_extensions/all_cheetah_vars_head.tmpl" #raw <?php #end raw ## ########################################################################## ## ## php_example_clean_cheetah_string ($theinputstring) ## ## Cleans up an input string #raw function php_example_clean_cheetah_string ($theinputstring) { return str_replace(str_split('\n\r'), '', $theinputstring); } #end raw ## ########################################################################## ## ## from_cheetah_latest_out_temperature <= ## $latest('purpleair_binding').purple_humidity ## #raw $from_cheetah_latest_out_temp_unclean = <<<EOS #end raw $current.outTemp.formatted #raw EOS; $from_cheetah_latest_out_temp = php_example_clean_cheetah_string ($from_cheetah_latest_out_temp_unclean); #end raw #raw ?> #end raw
#raw <?php echo "<p>The current temperature is " . strval($from_cheetah_latest_out_temp) . ".</p><br>"; echo "<p>Twice that value is " . strval($from_cheetah_latest_out_temp * 2) . ".</p><br>" ?> #end raw
<html> <head> <title>PHP EXAMPLE Test</title> </head> <body> <!-- The include below helps grab WeeWX 'data' that you need to reference in your PHP file. The include file puts the data into PHP variables. --> <?php function php_example_clean_cheetah_string ($theinputstring) { return str_replace(str_split('\n\r'), '', $theinputstring); } $from_cheetah_latest_out_temp_unclean = <<<EOS 71.1 EOS; $from_cheetah_latest_out_temp = php_example_clean_cheetah_string ($from_cheetah_latest_out_temp_unclean); ?> <p>Hi this would be part of a standard WeeWX HTML file, to be generated every five minutes. Pretend this is a 'standard skin file' from a WeeWX skin, extended to work with PHP.</p> <br> <p>Below, should be the extra information from PHP.</p> <br> <?php echo "<p>The current temperature is " . strval($from_cheetah_latest_out_temp) . ".</p><br>"; echo "<p>Twice that value is " . strval($from_cheetah_latest_out_temp * 2) . ".</p><br>" ?> <p>Did you see the information about the current temperature, above?</p> </body> </html>