HTTP binding - openHAB 3 version

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?

Oops… yes. Nice catch.

Now I’m getting:

2020-07-11 22:01:12.038 [ome.event.ItemCommandEvent] - Item 'LaMetricApp2' received command {'frames':[{'text':'TEST','icon': 'a36755','index': '0'}]}

2020-07-11 22:01:12.059 [TRACE] [nding.http.internal.HttpThingHandler] - Sending to 'https://developer.lametric.com/api/v1/dev/widget/update/com.lametric.123/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 22:01:12.178 [TRACE] [p.internal.http.HttpResponseListener] - Received from 'https://developer.lametric.com/api/v1/dev/widget/update/com.lametric.123/3': Code = {400}, Headers = {Server: nginx, Date: Sat, 11 Jul 2020 20:01:12 GMT, Content-Type: application/json; charset=UTF-8, Content-Length: 90, Connection: keep-alive, X-Content-Type-Options: nosniff, X-XSS-Protection: 1; mode=block}, Content = {{"error":{"code":null,"message":"Bad Request","trace":["request body must not be empty"]}}}

Why is there the chinese characters. Is there something off with the encoding?

That’s only a logging issue. Fixed in a new jar. Maybe the problem is the missing content-type. I’ll add support for that ASAP. But not this evening.

The chinese is gone! The content looks correct.

Will be happy to test again when you find the time. Have a nice weekend!

I added a new configuration option contentType. Unfortunately I can’t test if that solves your problem.

Hi, @J-N-K would it be possible to add a configuration option to allow all ssl certificates / disable hostname verification? I’m trying to access the API of my OPNsense Firewall with your binding, but it is by default redirecting to https and accessing it via internal IP and self-signed certificate leads to errors.

(Actually, with the current error I’m not sure if https is working anyway with the latest binding. However, I’m pretty sure that I got another error when I tried a few days ago, which was more pointing to an invalid certificate …
Requesting 'https://xxx.xxx.xxx.xxx/api/' (method='GET', content='null') failed: General SSLEngine problem)

Please provide the full logs.

There actually is not much more in the logs, even with loglevel set to TRACE:

2020-07-18 19:24:02.397 [TRACE] [ttp.internal.http.RefreshingUrlCache] - Requesting refresh from 'https://192.168.1.254/api/' with timeout 3000ms
2020-07-18 19:24:02.401 [TRACE] [ttp.internal.http.RefreshingUrlCache] - Sending to 'https://192.168.1.254/api/': Method = {GET}, Headers = {Accept-Encoding: gzip, User-Agent: Jetty/9.4.20.v20190813, Authorization: Basic <...>}, Content = {null}
2020-07-18 19:24:02.572 [TRACE] [p.internal.http.HttpResponseListener] - Received from 'https://192.168.1.254/api/': Code = {0}, Headers = {}, Content = {null}
2020-07-18 19:24:02.576 [WARN ] [p.internal.http.HttpResponseListener] - Requesting 'https://192.168.1.254/api/' (method='GET', content='null') failed: General SSLEngine problem

I‘m already working on a solution.

I have updated the link above. There is a new option ignoreSSLErrors on thing-level. I checked with badssl.com that in fact invalid certificates are ignored.Please test and report if it works for you.

2 Likes

Works flawlessly :+1: , thanks for the fast implementation.

1 Like

I have a thing with user/password set but cannot delete (set empty) those ?? PaperUI bug ?

I’m failing to get another complex case to work. Maybe it could serve as an example once I get it to work.

Wanted: a “Switch” item to retrieve and send status/ON+OFF commands via HTTP
The base URL of the Thing is http://<IP>/web, channel config see below.
On retrieving URL/powerstate, the URL returns an XML that I can parse with a transformation (that worked in httpv1):

<?xml version="1.0" encoding="UTF-8"?>
<e2powerstate>
        <e2instandby>true</e2instandby>
</e2powerstate>

First problem is that state retrieval for this item does not work - item remains UNDEF. Thing is ONLINE. Although I have trace logging, I see no "GET"s logged, just “execute() called”.
TCPdump however reveals there’s requests going and being answered.

Second, on changing item I want it to POST URL/powerstate?newstate=4 if “ON” and 5 for “OFF”.
But I see the number is missing in the URL. Do I need a command transformation ?

@mstormi

One question.

Your state <e2instandby>true</e2instandby> represents true=OFF, false=ON ?
(in standby=true means power=OFF, in standby=false means power=ON ?? )

If so, then you should try MAP transformation e.g onoff.map for Command Transformation:

Content of onoff.map:

4=false
5=true

OR

false=4
true=5

.

And your channel definition then could be:
.

image