HTTP binding - openHAB 3 version

So far I use the snapshot version for both, OH 3 and the HTTP Binding.
Things and 4 channels have been created in UI, three of them are working well:

  • 1 x number and 2 x string channel

Each channel has its own JS script attached to it, I am pasring a local ics.file for the upcoming garbage dates.

The datetime channel is making some trouble, the log says:

2020-10-25 17:03:33.632 [WARN ] [iles.JavascriptTransformationProfile] - Could not transform state 'UNDEF' with function 'abfall_naechste_abholung_datum.js' and format '%s'
2020-10-25 17:04:03.802 [WARN ] [iles.JavascriptTransformationProfile] - Could not transform state 'UNDEF' with function 'abfall_naechste_abholung_datum.js' and format '%s'
2020-10-25 17:04:33.880 [WARN ] [iles.JavascriptTransformationProfile] - Could not transform state 'UNDEF' with function 'abfall_naechste_abholung_datum.js' and format '%s'
2020-10-25 17:05:03.448 [WARN ] [iles.JavascriptTransformationProfile] - Could not transform state 'UNDEF' with function 'abfall_naechste_abholung_datum.js' and format '%s'
2020-10-25 17:05:33.732 [WARN ] [iles.JavascriptTransformationProfile] - Could not transform state 'UNDEF' with function 'abfall_naechste_abholung_datum.js' and format '%s'

I understand, that the default setting is %s, so I tried allready some other settings like [%1$td.%1$tm.%1$tY], but the result is still the same.

Somebody else have seen this?

Can you please show the script, the input and the expected output? Thanks.

Hi Jan, thanks for helping.
Script (rename to abfall_naechste_abholung_datum.js)
abfall_naechste_abholung_datum.txt (6.3 KB)

Input file: (rename to abfall2020.ics)
abfall2020.txt (26.4 KB)

Thing config:
grafik

Channel config:

The output should be just the date, at least it is running like this within the OH 1.x Version.

channel profiles are unrelated to binding transformations.
At OH2, transform profiles were restricted to use with String type Items, I do not think that has been addressed yet.

Thanks for the hint, changed it to string… date is now visible. Since the output ist just being displayed in the sitemap and no further action will be done with it, this is fine for me as well.

It won’t be fixed in OH2, but is already implemented in OH3!

That’s good. :slight_smile:
I suppose it did not work in this case then, because the user’s transform does not output an ISO date string that can be parsed into a DateTime Item state,

Thanks Solved now.
Finally the problem was that I always need to clean the cache after any .things update …

That‘s Why I never use textual configuration.

I will probably move to the visual configuration on OH3 sooner or later (I need to move toons of code rows !) but for the time being I have OH2 on stage and OH3 in testing and it is easy to work on textual configuratrion in OH2 and move it on OH3 for testing.

1 Like

Hi… i am using the OH 3 version of the binding. Want to make a http POST request to a URL with a json payload. the equivalent curl command is:

curl -X POST -d '{"state": "off"}' http://192.168.1.199:5000/device/0/power

is this the right way to configure the binding and channel?

I cant seem to get it done. Logs seem to indicate the command is going but is this is the right way to send a json payload? i suspect its just going as a plain string.

2020-11-14 02:36:28.453 [TRACE] [.HttpDynamicStateDescriptionProvider] - returning new stateDescription for http:url:bf98036307:TV_ON
2020-11-14 02:36:28.453 [TRACE] [nding.http.internal.HttpThingHandler] - Sending to 'http://192.168.1.199:5000/device/0/power': Method = {POST}, Headers = {Accept-Encoding: gzip, User-Agent: Jetty/9.4.20.v20190813, Content-Type: text/plain}, Content = {"state: "on"}
2020-11-14 02:36:28.460 [TRACE] [p.internal.http.HttpResponseListener] - Received from 'http://192.168.1.199:5000/device/0/power': Code = {500}, Headers = {Date: Fri, 13 Nov 2020 21:06:28 GMT, Content-Length: 89, Content-Type: text/plain; charset=UTF-8}, Content = {{"state":"Error: json: cannot unmarshal string into Go value of type webservice.Request"}}
2020-11-14 02:36:28.461 [WARN ] [p.internal.http.HttpResponseListener] - Requesting 'http://192.168.1.199:5000/device/0/power' (method='POST', content='org.eclipse.jetty.client.util.StringContentProvider@3534c0d2') failed: 500 Internal Server Error

the other side a custom golang microserver expecting a json payload via POST.
any suggestions pls?

Judging from the log your command is missing the double-quote after state

Thanks. Sorry That was a typo. But still getting the same error. Anything else I can do to troubleshoot?

2020-11-14 08:37:20.793 [TRACE] [.HttpDynamicStateDescriptionProvider] - returning new stateDescription for http:url:bf98036307:TV_ON
2020-11-14 08:37:20.794 [TRACE] [nding.http.internal.HttpThingHandler] - Sending to 'http://192.168.1.199:5000/device/0/power': Method = {POST}, Headers = {Accept-Encoding: gzip, User-Agent: Jetty/9.4.20.v20190813, Content-Type: text/plain}, Content = {"state": "on"}
2020-11-14 08:37:20.802 [TRACE] [p.internal.http.HttpResponseListener] - Received from 'http://192.168.1.199:5000/device/0/power': Code = {500}, Headers = {Date: Sat, 14 Nov 2020 03:07:20 GMT, Content-Length: 89, Content-Type: text/plain; charset=UTF-8}, Content = {{"state":"Error: json: cannot unmarshal string into Go value of type webservice.Request"}}
2020-11-14 08:37:20.803 [WARN ] [p.internal.http.HttpResponseListener] - Requesting 'http://192.168.1.199:5000/device/0/power' (method='POST', content='org.eclipse.jetty.client.util.StringContentProvider@1adeda5c') failed: 500 Internal Server Error

Infact the sendHttpPostRequest from a script works just fine

sendHttpPostRequest("http://192.168.1.199:5000/device/0/power", "text/plain", "{\"state\":\"on\"}", 30000)

Can you confirm that it works on the command line?

curl -X POST -d '{"state": "on"}' http://192.168.1.199:5000/device/0/power

Also check to make sure the device is there

Can you post the response of
curl http://192.168.1.199:5000/device/0

It looks like you are missing the curly braces in the on/off value fields, have you tried including them? (try {“state”: “on”} instead of “state”: “on”)

2 Likes

LOL. Thanks for pointing that out. yes this is the correct solution :slight_smile:
also did content-type as “application/json”

1 Like

Links in 1st post do not work.

If you are using OH3, the binding is now included in the snapshots

Hi,
I’m currently testing the HTTP binding on OH 3 (Build 2017). But the site i’m running the test against doesn’t seem to be using any authentication except for a “API” Key they call “AppKey”.

Please note that i have changed the AppKey, and address in this post. This is just for showing an example.
I’m getting this current error:

[WARN ] [p.internal.http.HttpResponseListener] - Requesting ‘https://komteksky.norkart.no/komtek.renovasjonwebapi/api/tommekalender/?gatenavn=Address&gatekode=1006&husnr=150’ (method=‘GET’, content=‘null’) failed: HTTP protocol violation: Authentication challenge without WWW-Authenticate header

I have setup the thiing with this Header: Kommunenr=0000&RenovasjonAppKey=11-22-33-44&OS=Android&Connection=Keep-Alive&Accept-Encoding=gzip

I can get it to work with a curl like this:
curl -H “Kommunenr: 0000” -H “RenovasjonAppKey: 11-22-33-44” -H “OS: Android” -H “Connection: Keep-Alive” -H “Accept-Encoding: gzip” -X GET “https:/komteksky.norkart.no/komtek.renovasjonwebapi/api/tommekalender/?gatenavn=Address&gatekode=1006&husnr=150”

Does anyone have any suggestion on what could be wrong?

1 Like

Please enable TRACE or DEBUG logging and show what exactly is sent. Did you configure authentication? Did you really set the headers as above? That’ll probably not work. Add a new entry for each header key-value-pair.