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 4019) - 03 April 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

Multiple "web tags to PHP variables" templates

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

Moderator: daj

Post Reply
sfws
Posts: 1183
Joined: Fri 27 Jul 2012 11:29 am
Weather Station: Chas O, Maplin N96FY, N25FR
Operating System: rPi 3B+ with Buster (full)

Multiple "web tags to PHP variables" templates

Post by sfws »

AS some of you may be aware, I have been writing a script that outputs web tags as PHP variables for those whose locale uses decimal commas, using the PHP replace function to find if a comma exists and if it does change it to a full stop. My script was using the "No Commas" (RC) tags where they existed and applying the function to other standard tags such as those for "Yesterday" where no RC's exist. Anyway, I was writing it to work with Cumulus 1 or MX, but I have (for the moment) given up on that script using replace because of danger it might encounter a comma used as a thousand separator.

Meanwhile, someone has moved the goal posts! From version 3.5.4, one can simply duplicate all the real number tags using e.g. <#rfallY rc=y> style. So that suggests the script should be totally different for Cumulus 1 and MX. It means I must rethink what I was previously doing. EDIT: Since I originally posted this, I have added a template to the zip described below, for MX only, that just contains web tags where the normal output for some locales has a decimal comma, in this template the decimal point is used instead, making it suitable for scripts written in JavaScript (includes Ajax routines and HighStocks coding). The script covers only "Now" and "Today" web tags at present.

https://cumuluswiki.org/a/File:Web_tag_templates.zip
Consequently, in the first Zip I took the decision to only release the other templates I had designed, these were for those using decimal point locales.

The zip has been uploaded into the Wiki rather than here, partly because I wanted to test if my wiki rights allow me to upload a file again now, because I started with those rights, then apparently lost those rights when I wanted to do an update, so it is good to see I have them again.
Also I put it in the Wiki because I want to encourage people to read the background on this Wiki page https://cumuluswiki.org/a/Php_webtags.

I have written one template for static web tags (process and upload once), one to process and upload at real time interval, one to process and upload at standard uploading interval, and one which (if you are using MX) you can process and upload at end of day. The last template in Cumulus 1 will need to be processed at real-time interval and uploaded by an external process at end of day.


I have started a new topic, because I am not trying to compete with Water01, instead I am seeking to show a different approach to inspire people to think a bit more widely and not assume there is only one way to do things. When Steve Loft was developing Cumulus 1, he added different web tags in different versions, and consequently he has not used a consistent naming standard for all today, yesterday, yearly tags. In my own version of these templates I have made a lot of effort to have a standardised consistent logical naming approach. In some cases, I have carried this through to the files I have shared. For example a web tag that starts with T is a time-stamp not a today value, so those web tags that start with a T and are values are assigned to a PHP variable that has T at the end. Equally Y sometimes means Yearly sometimes yesterday in web tags and I'm trying to spell year out in PHP variable names.

I am not claiming I have achieved perfection, but I have tried to produce something useful in the very disjointed odd moments I can spare from all my daylight hours outside dealing with a garden neglected by previous owner. Before you criticise what I have done, consider whether you can do better. Also remember I have had to change scripts that worked very well for my needs into more general scripts that might meet a wider range of needs, and I do not have the hardware or the web pages to test all the different variables, so my new scripts are only partially tested.
Last edited by sfws on Sun 26 Apr 2020 2:00 pm, edited 2 times in total.
User avatar
mcrossley
Posts: 12766
Joined: Thu 07 Jan 2010 9:44 pm
Weather Station: Davis VP2/WLL
Operating System: Bullseye Lite rPi
Location: Wilmslow, Cheshire, UK
Contact:

Re: Multiple "web tags to PHP variables" templates

Post by mcrossley »

Have you tested using the "rc=y" in Cumulus 1? In CMX if you use it in a web tag that isn't a decimal it just gets ignored, I wonder if C1 is the same?

And the RCxxx tags haven't gone away - they remain the same as before.
sfws
Posts: 1183
Joined: Fri 27 Jul 2012 11:29 am
Weather Station: Chas O, Maplin N96FY, N25FR
Operating System: rPi 3B+ with Buster (full)

Re: Multiple "web tags to PHP variables" templates

Post by sfws »

mcrossley wrote: Sat 25 Apr 2020 7:34 pm In CMX if you use it in a web tag that isn't a decimal it just gets ignored
That is useful to know, I would not have guessed that. I noticed when I first swapped to MX, it was very fussy on input formats for recent history tags and on output formats for dates, and I got lots of errors.

Do you actually have a list of all tags where rc=y does change the format now? Or is the way you coded it like my preg_replace, i.e. it ignores any contents that do not have a comma?

I have only one PC and only a USB weather station, so testing something in C1 while I'm running MX is difficult for me.

In general C1 ignores any web tags it does not understand (i.e. because they are introduced at later build, I'm sure Steve loft did that deliberately), and yes it is same with parameters it does not understand. I have taken advantage of that ignoring, in that I expect Cumulus of whatever flavour to process tags that only other flavour understands. When the PHP is parsed, it picks the right definition for the build.
mcrossley wrote: Sat 25 Apr 2020 7:34 pm And the RCxxx tags haven't gone away - they remain the same as before.
Yes, I know that. My script, as it currently exists, uses RC tags where they exist and preg_replace('~[,]~','.',<#tag_name>); where they don't. While that will still work with MX, there is part of me that says my script will be better if it does not use PHP functions, so could work with other script languages, by changing it to use rc=y in all those cases.

It won't take that long to do that for MX only, I can use a global replace in Notepad++ if I only want it to work in MX. However, if I still want it to work with C1 too, I keep all the preg_replace('~[,]~','.',<#tag_name>);. That is why I said I need to consider the way forward.

Just for the record, I took decision to deal with removing comma in a separate file, because that means I can do arithmetic easily by not enclosing numeric values in quotes.
Other approaches have to enclose numeric values in quotes so they are treated as strings. Normally, the locale expects to either see decimal commas or to see decimal full-stops for valid numerics, so one file can't suit both locale numeric styles unless there are no numerics, only strings.
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: Multiple "web tags to PHP variables" templates

Post by beteljuice »

If we are talking 'locale' format vars ...
Have you considered any large numbers. ie. a thousands delimiter. 1,123.23 or even 1.123.23 (nasty one)
Image
......................Imagine, what you will KNOW tomorrow !
sfws
Posts: 1183
Joined: Fri 27 Jul 2012 11:29 am
Weather Station: Chas O, Maplin N96FY, N25FR
Operating System: rPi 3B+ with Buster (full)

Re: Multiple "web tags to PHP variables" templates

Post by sfws »

beteljuice wrote: Sat 25 Apr 2020 11:29 pm a thousands delimiter
Yes, I have thought about that issue. Chill hours, wind run, pressure (unless in Hg), and potentially other yearly cumulative parameters, have output in thousands, and potentially could use thousands comma. I did wonder about counting digits, most (but not all) numeric tags output only to 1 or 2 decimal places, so you could only replace a comma with full stop when there are either 1 or 2 digits after it, and remove comma entirely in other cases to avoid your example with 2 full stops; that could be coded in preg_replace. Obviously, the same script languages that cannot handle decimal comma cannot handle thousands separators. Debating whether to use that complexity is another reason why my remove commas script version is not yet shared.

I am being very ambitious, I want to produce scripts that will work for anybody, without forcing them to use my choices of locale, PHP version, or C1/MX version. A tall order, that so far I have failed to achieve, despite making sufficient progress that I felt I could share what I have done for decimal point users. You know very well from all your wonderful scripts over the years that is very difficult to write code that will work whatever the end user chooses as their context.

Mark says, unknown parameters in MX web tags are ignored, but any unknown web tags are removed without substitution. I could take the approach that others have taken, and enclose even numeric tags in quotes so an unknown tag sets the PHP variable to an empty string.
Instead I am perhaps making life more difficult for me, by trying to avoid strings for numeric values. I have used

Code: Select all

$php_variable = <#numeric_web_tag_name> +0;
to avoid a

Code: Select all

$php_variable = ;
situation where unknown tag removal leaves RHS empty, and PHP error (unexpected ';') is reported. But in the scripts shared, I have not yet done that for every numeric web tag.

I am also using

Code: Select all

if(build number > X)
to select between ways of defining a PHP variable depending on what web tags are available, in my attempt to produce a universal script.

I should not really have tried this task now, because my main focus is on another task (digging out unwanted tree seedlings and trying to uncover overgrown paths in a garden the previous elderly owner neglected), so I'm often rather tired when I do my coding in odd moments.
Last edited by sfws on Sun 26 Apr 2020 2:03 pm, edited 2 times in total.
User avatar
mcrossley
Posts: 12766
Joined: Thu 07 Jan 2010 9:44 pm
Weather Station: Davis VP2/WLL
Operating System: Bullseye Lite rPi
Location: Wilmslow, Cheshire, UK
Contact:

Re: Multiple "web tags to PHP variables" templates

Post by mcrossley »

sfws wrote: Sun 26 Apr 2020 5:22 am
Mark says, unknown tags are ignored, but that is not perfectly accurate, actually they are removed without substitution.
I think I said, unknown tag parameters are ignored.
sfws
Posts: 1183
Joined: Fri 27 Jul 2012 11:29 am
Weather Station: Chas O, Maplin N96FY, N25FR
Operating System: rPi 3B+ with Buster (full)

Re: Multiple "web tags to PHP variables" templates

Post by sfws »

UPDATE
I have now added a new template to my zip referenced earlier,
"web_tags_MXRCreal_timeT.cum" contains all the "No comma" web tags that use format "<#RC_web_tag_name>" plus all the other numeric web tags with the "rc=y" parameter.

As Mark says, if I have inadvertently put a "rc=y" parameter on a tag that does not accept it, then it should ignore the parameter and report as normal.

Note that I have not added the MOON tags that take rc=y, as they also take dp=x and I don't know what x will suit people. If you tell me what x you find useful in this topic, I will add the moon tags to my new template.

Those using the water01 template that does not yet have rc=y tags, might want to add the above template while still ignoring the others I have produced.

If anyone can find a fault in any of my templates, or believes there is a variant of any tags with different parameters that would be widely useful, then please let me know by PM or a post here, whichever seems more appropriate for severity. Please don't contact me if you just want to complain that my more consistent (and I would argue more sensible) naming standard does not match Steve Loft's more inconsistent names where a T prefix can mean today or time-stamp, where a Y can mean yesterday or yearly and so on.

mcrossley wrote: Sun 26 Apr 2020 8:36 am I think I said, unknown tag parameters are ignored.
Apologies for misquote.
sfws
Posts: 1183
Joined: Fri 27 Jul 2012 11:29 am
Weather Station: Chas O, Maplin N96FY, N25FR
Operating System: rPi 3B+ with Buster (full)

Re: Multiple "web tags to PHP variables" templates

Post by sfws »

beteljuice wrote: Sat 25 Apr 2020 11:29 pm If we are talking 'locale' format vars ...
Have you considered any large numbers. ie. a thousands delimiter. 1,123.23 or even 1.123.23 (nasty one)
Since I made earlier reply to this question, I have looked at the MX c# code, its remove comma option does just what I proposed to do in PHP, it does a replace of any comma by a full stop. We can safely infer that Cumulus will not use thousands delimiters in any output, so beteluice your potential issue is not a problem. This also means I can do a template for Cumulus 1 uses that PHP replace quite safely. So I will be updating my zip on Wiki shortly.
sfws
Posts: 1183
Joined: Fri 27 Jul 2012 11:29 am
Weather Station: Chas O, Maplin N96FY, N25FR
Operating System: rPi 3B+ with Buster (full)

Re: Multiple "web tags to PHP variables" templates

Post by sfws »

New zip recently uploaded to Wiki at https://cumuluswiki.org/a/File:Web_tag_templates.zip. For usage see https://cumuluswiki.org/a/Php_webtags

This includes all new web tags up to version 3.6.1. Please note that because I use consistent naming and Steve Loft did not, plus because I use output and input modifiers, my PHP variables names are not always an exact match to Steve's web tag names.


I realise as I don't have the required Davis hardware, I can't test the new Davis tags in 3.6.0, so I would welcome feedback from somebody that my scripts work correctly with those new tags.
Post Reply