Http access for Meteobridge (universal weather box bridge)

Hi, everyone

I’m trying to read in an http call. Unfortunately without success.
Other http .things work fine.
I call up the file used from a Meteobridge.
Meteobridge enables the integration of various weather stations (e.g. DAVIS) with Live Data as XML.
However, the XML file does not have the same structure as the systems used up to now. As a software beginner, I get stuck.

Any help is welcome.

Thing http:url:meteobridge "Meteobridge" [ 	baseURL="meteobridge:lommiswil@192.168.188.38/cgi-bin/livedataxml.cgi",
  	username="abcde", password="1234567890", authMode="DIGEST", stateMethod="GET",
  	refresh=15] {
	Channels:
		Type string : weather_xml "WeatherXML" [ stateTransformation="XPATH:/logger/TH/text()", mode="READONLY" ]
}

The Channels part is not true at all.
But I haven’t found a way to read any text element at all.
The XML looks like this (more or fewer lines depending on the application)

<logger>
	<TH date="20210725103044" id="th0" temp="17.0" hum="93" dew="15.9" lowbat="0"/>
	<WIND date="20210725103102" id="wind0" dir="281" gust="0.0" wind="0.4" chill="17.0" lowbat="0"/>
    <RAIN date="20210725103052" id="rain0" rate="0.0" total="17.8" delta="0.0" lowbat="0"/>
</logger>

If I could read a field as text or number, I would be happy.
Thanks for any idea.

To work with XPATH it’s important to understand the “parts” of an XML. You basically have elements and attributes. <logger> is an element. Elements have a starting tag and an ending tag (</logger>) and an element can contain attributes or other elements.

An attribute is a property on an element. temp="17.0" is an attribute on the TH element.

As shown in many XPATH tutorials and docs, one uses @ to extract an attribute.
https://www.w3schools.com/xml/xpath_syntax.asp

So your path need to be /logger/TH/@temp to select the temp attribute. You should get back “17.0”.

Always use an online expression tester when working with this sort of thing. Simple online XPath tester.

good evening rich

Thanks for your tip.
I have already tried various versions, unfortunately without success.
I also tried the following channel (probably corresponds to your suggestion):

		Type string : weather_th "Weather_TH" [ stateTransformation="XPATH:/logger/TH/@temp/text()", mode="READONLY" ]

my Openhab.log acknowledges this with:

…Creating request for ‘xxx:yyy@192.168.188.38/cgi-bin/livedataxml.cgi’ failed: unknown protocol: meteobridge

Access to the address is not criticized.
I’m looking for the bug in the structure of the channel.
The structure of the Meteobridge.XML file seems special to me.
In test files, the structure is referred to as “JSON valid in JavaScript”.
Am I making a mistake?
later I wanted to read in each line as text in order to then separate and interpret each element.
But I couldn’t read the single line either …
Do you have another tip for me?
I am grateful for any suggestion.
Greetings, Urs

I do not support Things in text files so if the problem isn’t the XPATH then I have no other suggestions.

As far as the XPATH is concerned though, I’m not certain the text() is needed at all and it might be causing problems at worse. I don’t know if it will treat the “17.0” as a text node or not. text() does not mean “give me the value as text”, it means “only match nodes that are text nodes, ignoring all other node types.”

The example you posted is definitely XML, not JSON.

Even if I redefine the channel in:

		Type number : weather_th "Weather_TH" [ stateTransformation="XPATH:/logger/TH/@temp", mode="READONLY" ]

comes the same error message.
Thanks anyway for the support.

To double check: create a String Channel without the stateTransformation parameter to make sure that you’re receiving the full XML that you expect.

I’m sure it will fail, because this:

isn’t valid, as your log has told you.

You’re trying to use the HTTP Binding, so you need to supply a valid URL - one that would work in a browser (as you’re using GET). So, one that starts with http:// or https://

Perfect! Problem solved. Several common rookie mistakes.

Thanks to Rich Koshak and Hafniumzinc.

Without outside help, I don’t recognize such simple mistakes.
Thanks to your support, the coding is easy and understandable.
Thank you.

Since maybe a beginner would like to integrate a Davis weather station via a Meteobridge, here is my solution:

Thing http:url:meteobridge "Meteobridge" [ 	baseURL="http://192.168.xxx.xx/cgi-bin/livedataxml.cgi",
  	username="meteobridge", password="1234567890", authMode="BASIC_PREEMPTIVE", 		// BASIC, BASIC_PREEMPTIVE oder DIGEST
	stateMethod="GET", refresh=100] {
		Channels:
			Type string		: weather_th_str				"Weather_TH"			[ ]
			Type string		: weather_th_str_logger 		"Weather_Logger" 		[ stateTransformation="XPATH:/logger", 				mode="READONLY" ]

			Type datetime	: weather_davis_th_timestamp 	"Weather_TH_TimeStamp" 	[ stateTransformation="XPATH:/logger/TH/@date", 	mode="READONLY" ]
			Type string 	: weather_davis_th_id 			"Weather_TH_ID" 		[ stateTransformation="XPATH:/logger/TH/@id", 		mode="READONLY" ]
			Type number 	: weather_davis_th_temp 		"Weather_TH_Temp" 		[ stateTransformation="XPATH:/logger/TH/@temp", 	mode="READONLY" ]
			Type number 	: weather_davis_th_hum 			"Weather_TH_Hum" 		[ stateTransformation="XPATH:/logger/TH/@hum", 		mode="READONLY" ]
			Type number 	: weather_davis_th_dew 			"Weather_TH_Dew" 		[ stateTransformation="XPATH:/logger/TH/@dew", 		mode="READONLY" ]
			Type number 	: weather_davis_th_lowbat 		"Weather_TH_LowBat" 	[ stateTransformation="XPATH:/logger/TH/@lowbat", 	mode="READONLY" ]
}
// Davis Vantage Pro2
    String		            Test_Http_as_String				"Test Http as String"
        { channel="http:url:meteobridge:weather_th_str" }
    String		            Test_Http_logger_as_String      "Test Http logger as String"
        { channel="http:url:meteobridge:weather_th_str_logger" }
			
	DateTime	            Weather_davis_th_TimeStamp 	    "Weather Davis - TimeStamp [%1$td.%1$tm.%1$ty %1$tH:%1$tM:%1$tS]"
        { channel="http:url:meteobridge:weather_davis_th_timestamp" }
	String                  Weather_davis_th_ID 			"Weather Davis - ID [%s]"
        { channel="http:url:meteobridge:weather_davis_th_id" }
	Number:Temperature      Weather_davis_th_Temp_ACTUAL 	"Weather Davis - Temp [%.1f %unit%]"
        <temperature>
        { channel="http:url:meteobridge:weather_davis_th_temp" }
	Number:Dimensionless    Weather_davis_th_Hum_ACTUAL 	"Weather Davis - Humidity [%d %%RH]"
        <humidity>
        { channel="http:url:meteobridge:weather_davis_th_hum" }
	Number:Temperature      Weather_davis_th_Dew_ACTUAL 	"Weather Davis - Dew Point [%.1f %unit%]"
        { channel="http:url:meteobridge:weather_davis_th_dew" }
	Number                  Weather_davis_th_LowBat 		"Weather Davis - LowBat [%s]"
        <battery>
        { channel="http:url:meteobridge:weather_davis_th_lowbat" }

Thanks for the support,
Greetings, Urs

1 Like