HTTP binding - openHAB 3 version

@mstormi

If I follow the logic of MAP and JSONPATH it should be as follows:

Binding MAP JSONPATH REGEX
http1 MAP(onoff.map) JSONPATH($.value) REGEX(. ?(. ?).*)
http2 MAP:onoff.map JSONPATH:$.value REGEX:. ?(. ?).*

.
Did you also try REGEX:. ?(. ?).*

I have updated the link above. If you set org.openhab.binding.http.internal.http to TRACE you’ll see the URL when requesting and the responses received.

Dowloaded it but did that change anything about http logging ?
That’s not really useful yet. Would need to see Headers, body and reponse code of the request

2020-07-10 20:24:04.590 [TRACE] [ttp.internal.http.RefreshingUrlCache] - Sending 'http://foscam:88/cgi-bin/CGIProxy.fcgi?cmd=getDevState' to 'HttpRequest[GET /cgi-bin/CGIProxy.fcgi HTTP/1.1]@13442bb'
2020-07-10 20:24:04.639 [TRACE] [ttp.internal.http.RefreshingUrlCache] - RefreshingUrlCache for 'http://foscam:88/cgi-bin/CGIProxy.fcgi?cmd=getDevState' received 'org.openhab.binding.http.internal.http.Content@66d12b'

I‘ll see how I can improve that.

Please check if the updated jar works for you.

It does, thanks.
It helped me find my own error now that I see the 200 response.
Turned out it was the request I didn’t copy properly. That device needs to have http://host/yaddayadda&usr=username&pwd=password rather than basic auth.

What’s left is that apparently I must be having another HTTP thing active (resulting from first tests yesterday ?) as I keep seeing both URLs below (the difference is the additional ‘/’). I don’t find that 2nd one in the list of smarthome:things though - is it something your binding does ? (although I don’t think so as it has a different request interval).

But that reminds me of this: if I’m not mistaken, you add State and Command URL Extension to Base URL but insert a fixed ‘/’, correct?
Then please remove that fixed ‘/’ insertion as the requirement could as well be to continue the URL with ? or & like in my test case.

2020-07-11 17:29:48.576 [TRACE] [ttp.internal.http.RefreshingUrlCache] - Requesting refresh from 'http://foscam:88/cgi-bin/CGIProxy.fcgi?/cmd=getDevState' with timeout 3000ms
2020-07-11 17:29:48.579 [TRACE] [ttp.internal.http.RefreshingUrlCache] - Sending 'http://foscam:88/cgi-bin/CGIProxy.fcgi?/cmd=getDevState' to 'HttpRequest[GET /cgi-bin/CGIProxy.fcgi HTTP/1.1]@5f3465'
2020-07-11 17:29:50.176 [TRACE] [ttp.internal.http.RefreshingUrlCache] - Requesting refresh from 'http://foscam:88/cgi-bin/CGIProxy.fcgi?cmd=getDevState&usr=admin&pwd=password' with timeout 1000ms
2020-07-11 17:29:50.178 [TRACE] [ttp.internal.http.RefreshingUrlCache] - Sending to 'http://foscam:88/cgi-bin/CGIProxy.fcgi?cmd=getDevState&usr=admin&pwd=password': Method = {GET}, Headers = {Accept-Encoding: gzip, User-Agent: Jetty/9.4.20.v20190813, Authorization: Basic YWRtaW46Y1ROVzBUcGU=}, Content = {null}
2020-07-11 17:29:50.418 [TRACE] [p.internal.http.HttpResponseListener] - Received from 'http://foscam:88/cgi-bin/CGIProxy.fcgi?cmd=getDevState&usr=admin&pwd=password': Code = {200}, Headers = {Content-Type: text/plain, Transfer-Encoding: chunked, Date: Sat, 11 Jul 2020 15:29:47 GMT, Server: lighttpd/1.4.35}, Content = {<CGI_Result>
    <result>0</result>
    <IOAlarm>0</IOAlarm>
    <motionDetectAlarm>1</motionDetectAlarm>
    <soundAlarm>1</soundAlarm>
    <record>0</record>
    <sdState>0</sdState>
    <sdFreeSpace>0k</sdFreeSpace>
    <sdTotalSpace>0k</sdTotalSpace>
    <ntpState>1</ntpState>
    <ddnsState>0</ddnsState>
    <upnpState>2</upnpState>
    <isWifiConnected>1</isWifiConnected>
    <infraLedState>0</infraLedState>
</CGI_Result>
}

1 Like

@J-N-K

Same here. I also need no fixed slash / at the end of baseURL or beginning of Extension. Many extensions will begin with ? or &.

I have the changed the concatenation logic. It now first checks if either the last character of the baseURL or the first character of the extension is ?, / or & and adds the / only if nothing is present. jar updated

2 Likes

What seems not to be working yet is updating the item.

I’ve filled State Transformation with a REGEX to extract a value from one of the lines in the HTTP reponse body above: REGEX:.*?<motionDetectAlarm>(.*?)</motionDetectAlarm>.*

… but I don’t see the linked item update and no hint in the internal.http trace.

I enabled debug logging on org.openhab.transform.regex and it says it is to execute the transformation, but the output isn’t shown in log and the item isn’t updated.

2020-07-11 18:39:33.930 [DEBUG] [.internal.RegExTransformationService] - about to transform '<CGI_Result>
    <result>0</result>
    <IOAlarm>0</IOAlarm>
    <motionDetectAlarm>1</motionDetectAlarm>
    <soundAlarm>1</soundAlarm>
    <record>0</record>
    <sdState>0</sdState>
    <sdFreeSpace>0k</sdFreeSpace>
    <sdTotalSpace>0k</sdTotalSpace>
    <ntpState>1</ntpState>
    <ddnsState>0</ddnsState>
    <upnpState>2</upnpState>
    <isWifiConnected>1</isWifiConnected>
    <infraLedState>0</infraLedState>
</CGI_Result>

I tried both, Number and String items but no luck.
Any idea how to debug that further ?

Works perfectly for me:

18:41:41.804 [TRACE] [http.internal.http.RefreshingUrlCache] - Requesting refresh from 'https://janessa.me/esh/test.xml' with timeout 3000ms
18:41:41.806 [TRACE] [http.internal.http.RefreshingUrlCache] - Sending to 'https://janessa.me/esh/test.xml': Method = {GET}, Headers = {Accept-Encoding: gzip, User-Agent: Jetty/9.4.20.v20190813, X-Token: mytoken}, Content = {null}
18:41:41.813 [TRACE] [tp.internal.http.HttpResponseListener] - Received from 'https://janessa.me/esh/test.xml': Code = {200}, Headers = {Server: nginx/1.10.3, Date: Sat, 11 Jul 2020 16:41:35 GMT, Content-Type: text/xml, Content-Length: 445, Last-Modified: Sat, 11 Jul 2020 16:37:03 GMT, Connection: keep-alive, ETag: "5f09eaaf-1bd", Accept-Ranges: bytes}, Content = {<CGI_Result>
    <result>0</result>
    <IOAlarm>0</IOAlarm>
    <motionDetectAlarm>1</motionDetectAlarm>
    <soundAlarm>1</soundAlarm>
    <record>0</record>
    <sdState>0</sdState>
    <sdFreeSpace>0k</sdFreeSpace>
    <sdTotalSpace>0k</sdTotalSpace>
    <ntpState>1</ntpState>
    <ddnsState>0</ddnsState>
    <upnpState>2</upnpState>
    <isWifiConnected>1</isWifiConnected>
    <infraLedState>0</infraLedState>
</CGI_Result>}
18:41:41.859 [INFO ] [smarthome.event.ItemStateChangedEvent] - HTTPURLThing_n1 changed from NULL to 1

Did you install the regex transformation?

I have been using that with the v1 binding and my log above (“about to transform”) shows it’s applied, doesn’t it.
Do I need to use a Number or a String item ?

I used a number item and pasted your transformation in the stateTransformation.

Alright, it was my own silly fault. It has been working all the time but the value didn’t change so the item didn’t.
Everything alright with your binding - thanks.

1 Like

I’ve tested it. It’s working. :slight_smile:

How do I define multiple header entries?

Like:
Accept=application/json,X-Access-Token=MYTOKEN

PaperUI? Just add a second entry. It automatically does that.

OK, got it.

Another question: I’m trying to send a JSON string as the payload:

{'frames':[{'text':'TEST1','icon': 'a36755','index': '0'}]}

but then I’m getting:


2020-07-11 21:30:44.910 [TRACE] [nding.http.internal.HttpThingHandler] - Sending to 'ttps://developer.lametric.com/api/v1/dev/widget/update/com.lametric.xxx/3': Method = {POST}, Headers = {Accept-Encoding: gzip, User-Agent: Jetty/9.4.20.v20190813, Accept: application/json, X-Access-Token: TOKEN}, Content = {笧晲慭敳✺孻❴數琧㨧呅協ㄧⰧ楣潮✺‧愳㘷㔵✬❩湤數✺‧〧絝}

2020-07-11 21:30:44.912 [WARN ] [nding.http.internal.HttpThingHandler] - Failed to convert command '{'frames':[{'text':'TEST1','icon': 'a36755','index': '0'}]}' to channel 'http:url:5080968a:lametricapp' for sending

It seems the content is messed up. What did you configure?

Is there a typo? The h at the beginning is missing?