[Solved] OH3 http binding creating request failed

Hi everyone,

I’ve been using OH 2 very successfully for several year. Now I want to move on to OH3.
I want to extract a sensor value with the new HTTP binding but I don’t really get it.

I created a Thing via GUI with a channel:

UID: http:url:glucose
label: HTTP URL Glucose
thingTypeUID: http:url
configuration:
  authMode: BASIC
  ignoreSSLErrors: false
  baseURL: http://10.0.0.5:8086/query?pretty=true&db=openhab&q=select%20value_mgdl%20from%20glucose%20ORDER%20BY%20time%20DESC%20limit%201
  password: XXX
  refresh: 30
  commandMethod: GET
  timeout: 3000
  bufferSize: 2048
  username: XXX
channels:
  - id: _StringGlucose
    channelTypeUID: http:string
    label: _Zuckerwert
    description: ""
    configuration:
      mode: READONLY

The Item looks like this:

In the log I get the message:

[ttp.internal.http.RefreshingUrlCache] - Creating request for 'http://10.0.0.5:8086/query?pretty=true&db=openhab&q=select%20value_mgdl%20from%20glucose%20ORDER%20BY%20time%20DESC%20limit%201' failed: Conversion = 'v'

Any tipps to get the new binding running?

Thanks in advance!!

Martin

Can you share the actual content that you expect to get back from this request?

When I open the URL in a browser, I get a JSON response:

{
    "results": [
        {
            "statement_id": 0,
            "series": [
                {
                    "name": "glucose",
                    "columns": [
                        "time",
                        "value_mgdl"
                    ],
                    "values": [
                        [
                            "2020-12-30T06:26:23.176Z",
                            173
                        ]
                    ]
                }
            ]
        }
    ]
}

Which is what I expect

Good. And which bit of that JSON are you interested in? At the moment you don’t have any transformations defined in your Channel, but we can help.

Yes, I know about the transformation. But I am stuck one or two steps before that (I guess).

The transformation on the old binding was

JSONPATH($.results[*].series[*].values[0].[1])

I haven’t tried yet, but I guess I could work out the right syntax on the new binding.

To answer your question: I’m looking for the value 173. I know my Item is a String-Type but I wanted to develop my Thing and Item step by step

Check the following YAML - all I’ve done is add the transformation into your Channel.

UID: http:url:glucose
label: HTTP URL Glucose
thingTypeUID: http:url
configuration:
  authMode: BASIC
  ignoreSSLErrors: false
  baseURL: http://10.0.0.5:8086/query?pretty=true&db=openhab&q=select%20value_mgdl%20from%20glucose%20ORDER%20BY%20time%20DESC%20limit%201
  password: XXX
  refresh: 30
  commandMethod: GET
  timeout: 3000
  bufferSize: 2048
  username: XXX
channels:
  - id: _StringGlucose
    channelTypeUID: http:string
    label: _Zuckerwert
    description: ""
    configuration:
      mode: READONLY
      stateTransformation: $.results[*].series[*].values[0].[1]

In the UI, it would look something like this:

I tried that but no success. I don’t think that there is a transformation error.

The log message tells me that the creation of the request failed. We are at least one step before the transformation.
Maybe something is wrong with the URL. Do I have to mask certain characters?

The log also says Conversion = 'v'

What does that mean?

The reference to Conversion = 'v' shows that the problem comes from the %20v in the URL. I’m betting all the occurrences of %20 will cause similar issues. Take note of the README section on formatting.

I don’t see any mention of a way to disable this “feature”. You could try replacing the %20 values in your URL with spaces and see if it improves.

Ok, we are on the right track. I replaced the %20 with blanks and the message shows:

2020-12-31 07:39:33.331 [WARN ] [ttp.internal.http.RefreshingUrlCache] - Creating request for 'http://10.0.0.5:8086/query?pretty=true&db=openhab&q=select value_mgdl from glucose ORDER BY time DESC limit 1' failed: Illegal character in query at index 58: http://10.0.0.5:8086/query?pretty=true&db=openhab&q=select value_mgdl from glucose ORDER BY time DESC limit 1

Character 58 is the first blank in the URL.

I also tried to use ’ ’ around the URL. No success.

I played around with the URL a bit.

When I use + instead of %20 it works right away:

http://10.0.0.5:8086/query?pretty=true&db=openhab&q=select+value_mgdl+from+glucose+ORDER+BY+time+DESC+limit+1
1 Like

Good work! Looks like it was a bug in the binding, which will be fixed at the next release:

Will this bugfix also fix problems with other url encoded special “chars” such as %3E or %3D?