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

Ver 3.7.0 web tag API

From build 3044 the development baton passed to Mark Crossley. Mark has been responsible for all the Builds since. He has made the code available on GitHub. It is Mark's hope that others will join in this development, but at the very least he welcomes your ideas for future developments (see Cumulus MX Development suggestions).

Moderator: mcrossley

Post Reply
User avatar
mcrossley
Posts: 12756
Joined: Thu 07 Jan 2010 9:44 pm
Weather Station: Davis VP2/WLL
Operating System: Bullseye Lite rPi
Location: Wilmslow, Cheshire, UK
Contact:

Ver 3.7.0 web tag API

Post by mcrossley »

The tag processor API means that you no longer have to generate files to use web tags, you can request web tags values on demand. Obviously this creates an overhead on Cumulus so use this feature wisely.

There are two methods of calling the new API (note the tag names are case sensitive just like normal):

HTTP GET
This provides a quick and simple method of getting data, you just provide the web tag names in the GET URL and MX returns a simple JSON string with the tag-name:tag-value pairs.
The tags are always returned with the default format. You can specify a special parameter "rc" (which must be the first URL parameter) to apply the usual remove commas format to all the tags.

eg.
http: //localhost:8998/api/tags/process.json?temp&hum&dew
or
http: //localhost:8998/api/tags/process.json?rc&temp&hum&dew

Which will return the following format string in the body...

Code: Select all

{"temp":"15.8","hum":"73","dew":"10.5"}
Note, ALL values are quoted as strings as it is difficult to know which are numeric and which are not.



HTTP POST
The POST method allows you to put whatever text you like in the request body - and include any web tags plus formatting you wish. The string returned will be exactly the same text with the tags substituted with data.
So you could send a simple comma separated list, or some JSON text, or XML, whatever.

eg.
http: //localhost:8998/api/tags/process.txt

With a POST body text of..

Code: Select all

<#time format="yy/MM/dd hh:mm:ss">,<#temp>,<#RecentFeelsLike d=1>
would return...

Code: Select all

20/07/14 01:48:11,15.7,18.4

Another example

Code: Select all

{
    "DateTime:"<#time format="yy/MM/dd hh:mm:ss">",
    "OutsideTemp":<#temp>,
    "FeelsLikeYest":<#RecentFeelsLike d=1>
}
would return...

Code: Select all

{
    "DateTime:"20/07/14 01:50:56",
    "OutsideTemp":15.7,
    "FeelsLikeYest":18.4
}
Have fun!
User avatar
HansR
Posts: 5957
Joined: Sat 20 Oct 2012 6:53 am
Weather Station: GW1100 (WS80/WH40)
Operating System: Raspberry OS/Bookworm
Location: Wagenborgen (NL)
Contact:

Re: Ver 3.7.0 web tag API

Post by HansR »

Working fine and smooth! Thanks, great addition. :D :clap:
(can be set resolved in the Suggestions Thread)
Hans

https://meteo-wagenborgen.nl
CMX build 4017+ ● RPi 3B+ ● Raspbian Linux 6.1.21-v7+ armv7l ● dotnet 8.0.3
water01
Posts: 3246
Joined: Sat 13 Aug 2011 9:33 am
Weather Station: Ecowitt HP2551
Operating System: Windows 10 64bit
Location: Burnham-on-Sea
Contact:

Re: Ver 3.7.0 web tag API

Post by water01 »

OK I will be the one to ask the dumb question.

I get how you do this but doesn't this mean I have to allow access from my website to my router and then port forward it to CumulusMX computer?
David
Image
User avatar
mcrossley
Posts: 12756
Joined: Thu 07 Jan 2010 9:44 pm
Weather Station: Davis VP2/WLL
Operating System: Bullseye Lite rPi
Location: Wilmslow, Cheshire, UK
Contact:

Re: Ver 3.7.0 web tag API

Post by mcrossley »

water01 wrote: Tue 28 Jul 2020 6:32 pm OK I will be the one to ask the dumb question.

I get how you do this but doesn't this mean I have to allow access from my website to my router and then port forward it to CumulusMX computer?
If you wanted to use it from a remote web server, yes. But not recommended for the obvious reason that the API interface is not secure.

It is meant for services either on the same computer as Cumulus or on your local network.
water01
Posts: 3246
Joined: Sat 13 Aug 2011 9:33 am
Weather Station: Ecowitt HP2551
Operating System: Windows 10 64bit
Location: Burnham-on-Sea
Contact:

Re: Ver 3.7.0 web tag API

Post by water01 »

OK that's what I thought, so dumb question number two what is this useful for? IOT?
David
Image
User avatar
HansR
Posts: 5957
Joined: Sat 20 Oct 2012 6:53 am
Weather Station: GW1100 (WS80/WH40)
Operating System: Raspberry OS/Bookworm
Location: Wagenborgen (NL)
Contact:

Re: Ver 3.7.0 web tag API

Post by HansR »

If I may answer that last question as requester of this feature.

If I am not thinking about realtime (that would require direct access from the website to Cumulus as you just discussed with Mark), but about history data, especially aggregated data or just informational data, it sometimes is easier to get them through direct communication. As my CumulusUtils avoids any type of file processing by Cumulus it was very difficult e.g. to get the version information or Davis info. Now I can handle it all at runtime, no more processing required.

All I need to do now is look what more info CMX has in store.
Hans

https://meteo-wagenborgen.nl
CMX build 4017+ ● RPi 3B+ ● Raspbian Linux 6.1.21-v7+ armv7l ● dotnet 8.0.3
freddie
Posts: 2473
Joined: Wed 08 Jun 2011 11:19 am
Weather Station: Davis Vantage Pro 2 + Ecowitt
Operating System: GNU/Linux Ubuntu 22.04 LXC
Location: Alcaston, Shropshire, UK
Contact:

Re: Ver 3.7.0 web tag API

Post by freddie »

You can expose the API to the internet via reverse proxying. I do this with my trends graphs on my external website, plus many of my pages and data files are hosted and generated internally and are proxied using the same mechanism. I don't send any data to my external site - it is all pulled. Obviously you have to do this carefully.

Advantages: no regular data transfer that takes up bandwidth (that may never be accessed by anybody). Exposure of only defined data and API calls.
Disadvantages: it leaves you open to DOS if your website is too popular (mine isn't :lol: ). Misconfiguration may expose more of your internal functions than you think! If your internet link goes down then your proxied calls will not work (return 502/503 codes) - but if your internet link is down then your external website won't be up-to-date anyway. Swings and roundabouts.
Freddie
Image
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: Ver 3.7.0 web tag API

Post by sfws »

I have today replaced 3 api get calls I had in a script (it was making a novel use of api used by an admin interface page for another purpose) by one api call using the new get functionality. I was staggered by how easy it was to implement this new feature that I documented in Wiki yesterday (dodging Mark's updates of same page). But the main joy was that it greatly simplified my script making many script lines and variables redundant. So thank you Mark for implementing this.
freddie wrote: Tue 28 Jul 2020 8:21 pm I do this with my trends graphs on my external website
Is that why your trends page is showing beta 2 "powered by Cumulusv3.7.0-beta2 (3089)" whilst your other pages are showing beta 3 "powered by Cumulus v3.7.0-beta3 (3089)"?

I can understand you might not had time to update from beta to public release, but I struggle to understand how you could use a different MX for just one page.
freddie
Posts: 2473
Joined: Wed 08 Jun 2011 11:19 am
Weather Station: Davis Vantage Pro 2 + Ecowitt
Operating System: GNU/Linux Ubuntu 22.04 LXC
Location: Alcaston, Shropshire, UK
Contact:

Re: Ver 3.7.0 web tag API

Post by freddie »

sfws wrote: Wed 29 Jul 2020 6:23 am
freddie wrote: Tue 28 Jul 2020 8:21 pm I do this with my trends graphs on my external website
Is that why your trends page is showing beta 2 "powered by Cumulusv3.7.0-beta2 (3089)" whilst your other pages are showing beta 3 "powered by Cumulus v3.7.0-beta3 (3089)"?

I can understand you might not had time to update from beta to public release, but I struggle to understand how you could use a different MX for just one page.
The version and build numbers on that one page are static, and I either have to make them dynamic or remember to update them when I update MX. I haven't done either as yet :D
Freddie
Image
Post Reply