Difference between revisions of "Add-On Services"

From meteoplug
Jump to: navigation, search
(Selectors)
 
(83 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
__NOTOC__
 
__NOTOC__
Meteobridge provides some additional services, which might be interesting, when you also want to use received data with your own postprocessing IT. Live data can be derived in two ways. Meteobridge client can be asked by a HTTP request to return data (pull mode) or can send data as HTTP-GET requests with user-defined URL parameters to a user-defined Internet address (push mode).  
+
<languages /><translate>
 +
<!--T:1-->
 +
<br />Web server of Meteobridge client, which presents web interface for adminstration to you, can also deliver weather data. There are three URLs defined that can be polled to get most recent sensor data in a standard XML or plain text format or in user-defined format. Although we don't recommend this for security reasons, you can make that URLs accessible from the Internet by configuring your router appropriately. However, when you want to bring sensor data to one of your own servers in the Internet we recommend to make use of Meteobridge's [[Push Services]], which will not need you to open up your firewall.
 +
Remark: In order to reach these HTTP services you need to handle basic authentification by adding "<username>:<password>@" in front of the URL.
  
==Pull Mode==
+
===Live Data as XML=== <!--T:12-->
Web server of Meteobridge client, which presents web interface for adminstration to you, can also deliver weather data. There are two URLs defined that can be polled to get most recent sensor data in XML or plain text. Although we don't recommend this for security reasons, you can make that URLs accessible from the Internet by configuring your router appropriately. However, when you want to bring sensor data to one of your own servers in the Internet we recommend to make use of Meteobridge's push mode, which will not need you to open up your firewall.
+
By sending the meteobridge a HTTP request like "http://ip-of-meteobridge/cgi-bin/livedataxml.cgi" (where "ip-of-meteobridge" must be replaced by the IP itself) meteobridge returns current weather data in XML notation. Each reply starts witch tag <logger> and ends with </logger> with the sensor data as records with sensor specific tags "THB", "TH", "SOIL", "LEAF", "WIND", "RAIN", "UV", "SOLAR". Example below illustrates the XML format:
+
===Live Data as XML===
+
By sending the meteobridge a HTTP request like "http://ip-of-meteobridge/cgi-bin/livedataxml.cgi" (where "ip-of-meteobridge" must be replaced by the IP itself) meteobridge returns current weather data in XML notation. Each reply starts witch tag <logger> and ends with </logger> with the sensor data as records with sensor specific tags "THB", "TH", "WIND", "RAIN", "UV", "SOLAR". Example below illustrates the XML format:
+
  
 +
<!--T:2-->
 
<pre><logger>
 
<pre><logger>
 
   <THB date="20121227224318" id="thb0" temp="26.0" hum="37" dew="10.2"  
 
   <THB date="20121227224318" id="thb0" temp="26.0" hum="37" dew="10.2"  
       press="1008.8" seapress="1010.1" fc="2"/>
+
       press="1008.8" seapress="1010.1" fc="2" lowbat="0" />
   <TH date="20130104141909" id="th0" temp="9.1" hum="95" dew="8.3"/>
+
   <TH date="20130104141909" id="th0" temp="9.1" hum="95" dew="8.3" lowbat="0" />
   <RAIN date="20130104141856" id="rain0" rate="0.0" total="3.0" delta="0.0"/>
+
   <RAIN date="20130104141856" id="rain0" rate="0.0" total="3.0" delta="0.0" lowbat="0" />
   <WIND date="20130104141916" id="wind0" dir="109" gust="0.9" wind="2.2" chill="9.1"/>
+
   <WIND date="20130104141916" id="wind0" dir="109" gust="0.9" wind="2.2" chill="9.1" lowbat="0" />
 
</logger></pre>
 
</logger></pre>
  
 +
<!--T:3-->
 
Each sensor data record has a mandatory "date" and "id" parameter. The other parameters are sensor specific. Meaning of parameters is:
 
Each sensor data record has a mandatory "date" and "id" parameter. The other parameters are sensor specific. Meaning of parameters is:
 
* '''date''': UTC timestamp of reception of sensor data in format "YYYYMMDDhhmmss"
 
* '''date''': UTC timestamp of reception of sensor data in format "YYYYMMDDhhmmss"
 
* '''id''': Unique ID of sensor, consists of a sensor type description shortcut followed by a number, which is always "0" in Meteobridge, as additional sensors are not supported
 
* '''id''': Unique ID of sensor, consists of a sensor type description shortcut followed by a number, which is always "0" in Meteobridge, as additional sensors are not supported
 
* '''temp''': temperature in degrees Celsius (with one decimal)
 
* '''temp''': temperature in degrees Celsius (with one decimal)
* '''hum''': relative humidity in percent (no decimals)
+
* '''hum''': relative humidity in percent (no decimals) with humidity sensors. With leaf and soil sensors unit is wetness or centibar.
 
* '''dew''': dew point temperature in degrees Celsius (with one decimal)
 
* '''dew''': dew point temperature in degrees Celsius (with one decimal)
 
* '''press''': station pressure (without altitude correction) in hPa (with one decimal)
 
* '''press''': station pressure (without altitude correction) in hPa (with one decimal)
Line 32: Line 34:
 
* '''dir''': wind direction in degrees (0-359, no decimals).
 
* '''dir''': wind direction in degrees (0-359, no decimals).
 
* '''chill''': wind chill temperature in degrees Celsius (with one decimal).
 
* '''chill''': wind chill temperature in degrees Celsius (with one decimal).
 +
* '''lowbat''': indicates if battery status of sensor is low (value 1) or normal (value 0).
 
* more to come...
 
* more to come...
  
===Live Data as Plain Text===
+
===Live Data as Plain Text=== <!--T:4-->
 
By sending the meteobridge a HTTP request like "http://ip-of-meteobridge/cgi-bin/livedata.cgi" (where "ip-of-meteobridge" must be replaced by the IP itself) meteobridge returns current weather data as plain text. Each reply consists of a series of lines, where each line represnets a sensor. Lines do start with a time stamp and a unique sensor id followed by sensor specific parameters. Example below illustrates the format:
 
By sending the meteobridge a HTTP request like "http://ip-of-meteobridge/cgi-bin/livedata.cgi" (where "ip-of-meteobridge" must be replaced by the IP itself) meteobridge returns current weather data as plain text. Each reply consists of a series of lines, where each line represnets a sensor. Lines do start with a time stamp and a unique sensor id followed by sensor specific parameters. Example below illustrates the format:
  
<pre>20130104142614 thb0 26.9 38 11.4 1020.4 1021.7 2
+
<!--T:5-->
20130104142610 rain0 0.0 3.0 0.0
+
<pre>20130104142614 thb0 26.9 38 11.4 1020.4 1021.7 2 0
20130104142636 th0 9.1 95 8.3
+
20130104142610 rain0 0.0 3.0 0.0 0
20130104142652 wind0 160 2.2 1.8 8.0</pre>
+
20130104142636 th0 9.1 95 8.3 0
 +
20130104142652 wind0 160 2.2 1.8 8.0 0</pre>
  
==Push Mode==
+
===Live Data via Socket Connection=== <!--T:6-->
When you select expert mode at the bottom of "Upload Data" tab, you will see an additional entry that allows you to send sensor data to a user-defined server.
+
Methods introduced above do need HTTP authentification like all elements of Meteobridge web interface. A look at the script "livedataxml.cgi" shows that this just reads data from socket 5557, gives it a suitable HTTP header and returns that to the requesting browser:
  
===Individual HTTP Upload===
+
<!--T:7-->
Data will be sent as HTTP GET requests with URL parmeters you can define to your liking. Parameters of a URL consist of name-value pairs seperated by '&'. You can define names yourself and can use a certain set of variables provided by Meteobridge to be used as values. Variable names will be automatically replaced by their current values, each time a HTTP request is sent. Please have a look at the example below.
+
<pre>#!/bin/sh
 +
echo -ne "Content-type: text/xml; charset=UTF-8\n\n"
 +
nc 127.0.0.1 5557 2>/dev/null
 +
</pre>
  
 +
<!--T:8-->
 +
Therefore, reading data from socket 5557 is equivalent to calling "livedataxml.cgi" and socket 5556 reports same data as delivered by "livedata.cgi".
  
[[file:http-upload.png]]
+
===Template-based Individual Data=== <!--T:9-->
 +
Scripts presented before return data in a standard format. As a variant you can also define a template like explained in Template section of this wiki, hand that over to "template.cgi" script and get a filled template in return.
  
 +
<!--T:10-->
 +
URL to call is "http://ip-of-meteobridge/cgi-bin/template.cgi" with mandatory parameter "template=YOUR_TEMPLATE_TEXT" and optional paramater "contenttype=CONTENT_TYPE". Both parameters have to be URL-encoded with special characters represented as "%XX" (where XX is a two digit hex code) and spaces are represented by "+".
  
Upload schedule is defined to every 5 seconds. URL specifies server address, where to deliver data ("http://myserver.com/upload.php" in the example above). "Success Condition" allows to specify a matching string which is compared to to the return message from the server to decide if upload was successful or not.
+
<!--T:11-->
 +
Example: In oder to get current outdoor temp and humidity this URL<pre>http://ip-of-meteobridge/cgi-bin/template.cgi?template=[DD].[MM].[YY]+[HH]:[mm][APM]%0D[th0temp-act]%BAC%0d[th0hum-act]%25&contenttype=text/plain;charset=iso-8859-1</pre>
 +
returns <pre>01.06.13 04:55PM
 +
23.2ºC
 +
61.0%</pre>
  
Weather data is transported to the server by means of URL parameters. Meteobridge provides a large set of variables that can be used to feed URL parameters with current sensor data. Each variable starts with an opening square bracket "[" and is terminated by a closing square bracket "]". The structure auf the variable name between these brackets is as follows: <pre>sensor-selector.decimals:replacement</pre>
+
==Additional Features of Meteobridge PRO== <!--T:13-->
"decimals" and "replacement" can be omitted, "sensor" and "type" are mandatory.
+
Meteobridge PRO allows to store templates in the PC network share "/data/templates/". By calling "http://ip-of-meteobridge/cgi-bin/template.cgi?templatefile=mydata.http" the file "mydata.http" from share "/data/templates" is filled with data and returned to the requestor.
  
====Sensors====
+
<!--T:14-->
These sensors are defined in Meteobridge.
+
Example: There is a template file "mydata.http" defined in the templates folder:
* '''th0temp''': outdoor temperature in degrees Celsius
+
<pre>[DD].[MM].[YY] [HH]:[mm][APM]
* '''th0hum''': relative outdoor humidity as percentage
+
[th0temp-act]°C
* '''th0dew''': outdoor dew point in degrees Celsius
+
[th0hum-act]%</pre>
* '''thb0temp''': indoor temperature in degrees Celsius
+
Request "http://ip-of-meteobridge/cgi-bin/template.cgi?templatefile=mydata.http&contenttype=text/plain;charset=utf-8" returns this:
* '''thb0hum''': indoor humidity as percentage
+
<pre>08.01.16 11:00AM
* '''thb0dew''': indoor dewpoint in degrees Celsius
+
3.5°C
* '''thb0press''': station pressure in hPa
+
94.0%</pre>
* '''thb0seapress''': normalized pressure (computed to sea level) in hPa
+
</translate>
* '''wind0wind''': wind speed in m/s
+
* '''wind0avrwind''': average windspeed in m/s (time used for average depends on station)
+
* '''wind0dir''': wind direction in degress (0° is North)
+
* '''wind0chill''': wind chill temperature in degrees Celsius
+
* '''rain0rate''': rain rate in mm/h
+
* '''rain0total''': rain fall in mm
+
* '''uv0index''': uv index
+
* '''sol0rad''': solar radiation in W/m^2
+
If a sensor is not there or data of sensor has passed the "tolerated data age" interval, Meteobridge will not provide data for it and will present the value defined as "replacement". If no replacement is given, variable will not be converted into data but will stay as is.
+
 
+
====Selectors====
+
Sensors are followed by a selector (syntactically separated by a dash) that specifies what period in time should be used for evaluation. Valid selectors are:
+
* '''act''': most recent data
+
* '''hmin''': minimum value of this hour
+
* '''hmax''': maximum value of this hour
+
* '''dmin''': minimum value of today
+
* '''dmax''': maximum value of today
+
* '''mmin''': minimum value of this month
+
* '''mmax''': maximum value of this month
+
* '''hmin''': minimum value of this year
+
* '''hmax''': maximum value of this year
+
* '''hmin''': minimum value of all time
+
* '''hmax''': maximum value of all time
+
 
+
Apart from selectors that use absolute, predefined time slots there are also selectors that look for a certain amount of time into the past.
+
* '''max2''', '''max5''', '''max10''', '''max15''', '''max30''', '''max60''': selects the maximum value from the last 2, 5, 10, 15, 30 or 60 minutes
+
* '''min2''', '''min5''', '''min10''', '''min15''', '''min30''', '''min60''': selects the minimum value from the last 2, 5, 10, 15, 30 or 60 minutes
+
* '''avg2''', '''avg5''', '''avg10''', '''avg15''', '''avg30''', '''avg60''': selects average value from the last 2, 5, 10, 15, 30 or 60 minutes
+
* '''sum2''', '''sum5''', '''sum10''', '''sum15''', '''sum30''', '''sum60''', '''sumday''': selects summerized delta values from the last 2, 5, 10, 15, 30, 60 minutes or current day (useful to get amount of total rain in a certain time frame: "rain0total-sum60" is rainfall im mm of last 60 minutes, "rain0total-sumday" is todays rain fall)
+
 
+
====Converters====
+
Sensor data is reported in ISO units (°C, hPa, mm, m/s) by default, but can be converted into non-ISO units (imperial) by adding a conversion token. Defined tokens are:
+
* '''F''' converts temperature from Celsius to Fahrenheit.
+
* '''psi''' converts pressure from hPa (equivalent to mbar) to psi.
+
* '''mmHg''' converts pressure from hPa to millimeters of mercury.
+
* '''inHg''' converts pressure from hPa to inches of mercury.
+
* '''kmh''' converts wind speed from meters per second to kilometers per hour.
+
* '''mph''' converts wind speed from meters per second to miles per hour.
+
* '''kn''' converts wind speed from meters per second to knots.
+
* '''bft''' converts wind speed from meters per second to Beaufort scale.
+
* '''in''' converts millimeters to inches.
+
If an unknown conversion string is used, no conversion will take place, no error message will appear.
+
 
+
====Special Variables====
+
There are a couple of variables that don't come as "sensor-selector" pairs but hvae a distinct meaning by themselves.
+
 
+
Date und time variables are defined as follows:
+
* '''YYYY''': year as four digit number
+
* '''YY''': year as two digit number
+
* '''MM''': month as two digit number, if only one digit neede a zero will be used as first digit
+
* '''M''': month as one or two digit number, no leading zeros
+
* '''DD''': day of month as two digit number, if only one digit neede a zero will be used as first digit
+
* '''D''': day of month as one or two digit number, no leading zeros
+
* '''hh''': hour as two digit number, if only one digit neede a zero will be used as first digit
+
* '''h''': hour as one or two digit number, no leading zeros
+
* '''mm''': minute as two digit number, if only one digit neede a zero will be used as first digit
+
* '''m''': minute as one or two digit number, no leading zeros
+
* '''ss''': seconds as two digit number, if only one digit neede a zero will be used as first digit
+
* '''s''': seconds as one or two digit number, no leading zeros
+
When a capital "U" preceeds a date/time variable name, UTC is used instead of local time ("[Uhh]:[Umm]:[Uss] UTC" is evaluated to a string like "16:03:33 UTC")
+
 
+
====Decimals====
+
Unless otherwise defined numbers are reported with one decimal. By specifying a value for "decimals" you can determine resolution of presented values.
+
 
+
====Replacement====
+
When a variable is not defined or there is no data for a specified sensor, information specified as "replacement" string will be represented instead.
+

Latest revision as of 16:50, 5 March 2016


Web server of Meteobridge client, which presents web interface for adminstration to you, can also deliver weather data. There are three URLs defined that can be polled to get most recent sensor data in a standard XML or plain text format or in user-defined format. Although we don't recommend this for security reasons, you can make that URLs accessible from the Internet by configuring your router appropriately. However, when you want to bring sensor data to one of your own servers in the Internet we recommend to make use of Meteobridge's Push Services, which will not need you to open up your firewall. Remark: In order to reach these HTTP services you need to handle basic authentification by adding "<username>:<password>@" in front of the URL.

Live Data as XML

By sending the meteobridge a HTTP request like "http://ip-of-meteobridge/cgi-bin/livedataxml.cgi" (where "ip-of-meteobridge" must be replaced by the IP itself) meteobridge returns current weather data in XML notation. Each reply starts witch tag <logger> and ends with </logger> with the sensor data as records with sensor specific tags "THB", "TH", "SOIL", "LEAF", "WIND", "RAIN", "UV", "SOLAR". Example below illustrates the XML format:

<logger>
  <THB date="20121227224318" id="thb0" temp="26.0" hum="37" dew="10.2" 
       press="1008.8" seapress="1010.1" fc="2" lowbat="0" />
  <TH date="20130104141909" id="th0" temp="9.1" hum="95" dew="8.3" lowbat="0" />
  <RAIN date="20130104141856" id="rain0" rate="0.0" total="3.0" delta="0.0" lowbat="0" />
  <WIND date="20130104141916" id="wind0" dir="109" gust="0.9" wind="2.2" chill="9.1" lowbat="0" />
</logger>

Each sensor data record has a mandatory "date" and "id" parameter. The other parameters are sensor specific. Meaning of parameters is:

  • date: UTC timestamp of reception of sensor data in format "YYYYMMDDhhmmss"
  • id: Unique ID of sensor, consists of a sensor type description shortcut followed by a number, which is always "0" in Meteobridge, as additional sensors are not supported
  • temp: temperature in degrees Celsius (with one decimal)
  • hum: relative humidity in percent (no decimals) with humidity sensors. With leaf and soil sensors unit is wetness or centibar.
  • dew: dew point temperature in degrees Celsius (with one decimal)
  • press: station pressure (without altitude correction) in hPa (with one decimal)
  • seapress: normalized pressure with altitude correction (also called sea level pressure) in hPa (with one decimal)
  • fc: stations forecast code, if provided. As this has low evidence and also largely varies between stations, meteobridge does not recommend to make use of this data.
  • rate: measured rain rate in mm per hour (with one decimal).
  • total: current value of rain bucket counter, converted to mm (with one decimal).
  • delta: additional rain fall in mm since previous readout of this data (with one decimal).
  • wind: current average wind speed im m/s (with one decimal).
  • gust: curent not avergaed wind speed in m/s (with one decimal).
  • dir: wind direction in degrees (0-359, no decimals).
  • chill: wind chill temperature in degrees Celsius (with one decimal).
  • lowbat: indicates if battery status of sensor is low (value 1) or normal (value 0).
  • more to come...

Live Data as Plain Text

By sending the meteobridge a HTTP request like "http://ip-of-meteobridge/cgi-bin/livedata.cgi" (where "ip-of-meteobridge" must be replaced by the IP itself) meteobridge returns current weather data as plain text. Each reply consists of a series of lines, where each line represnets a sensor. Lines do start with a time stamp and a unique sensor id followed by sensor specific parameters. Example below illustrates the format:

20130104142614 thb0 26.9 38 11.4 1020.4 1021.7 2 0
20130104142610 rain0 0.0 3.0 0.0 0
20130104142636 th0 9.1 95 8.3 0
20130104142652 wind0 160 2.2 1.8 8.0 0

Live Data via Socket Connection

Methods introduced above do need HTTP authentification like all elements of Meteobridge web interface. A look at the script "livedataxml.cgi" shows that this just reads data from socket 5557, gives it a suitable HTTP header and returns that to the requesting browser:

#!/bin/sh
echo -ne "Content-type: text/xml; charset=UTF-8\n\n"
nc 127.0.0.1 5557 2>/dev/null

Therefore, reading data from socket 5557 is equivalent to calling "livedataxml.cgi" and socket 5556 reports same data as delivered by "livedata.cgi".

Template-based Individual Data

Scripts presented before return data in a standard format. As a variant you can also define a template like explained in Template section of this wiki, hand that over to "template.cgi" script and get a filled template in return.

URL to call is "http://ip-of-meteobridge/cgi-bin/template.cgi" with mandatory parameter "template=YOUR_TEMPLATE_TEXT" and optional paramater "contenttype=CONTENT_TYPE". Both parameters have to be URL-encoded with special characters represented as "%XX" (where XX is a two digit hex code) and spaces are represented by "+".

Example: In oder to get current outdoor temp and humidity this URL
http://ip-of-meteobridge/cgi-bin/template.cgi?template=[DD].[MM].[YY]+[HH]:[mm][APM]%0D[th0temp-act]%BAC%0d[th0hum-act]%25&contenttype=text/plain;charset=iso-8859-1
returns
01.06.13 04:55PM
23.2ºC
61.0%

Additional Features of Meteobridge PRO

Meteobridge PRO allows to store templates in the PC network share "/data/templates/". By calling "http://ip-of-meteobridge/cgi-bin/template.cgi?templatefile=mydata.http" the file "mydata.http" from share "/data/templates" is filled with data and returned to the requestor.

Example: There is a template file "mydata.http" defined in the templates folder:

[DD].[MM].[YY] [HH]:[mm][APM]
[th0temp-act]°C
[th0hum-act]%

Request "http://ip-of-meteobridge/cgi-bin/template.cgi?templatefile=mydata.http&contenttype=text/plain;charset=utf-8" returns this:

08.01.16 11:00AM
3.5°C
94.0%