Http binding help

Hi

I would like to use my dynalite gateway in openhab is uses HTTP GET and HTTP POST, but I can’t really see how to set it up

I have made an item that GET status and one that POST a preset by on and off

String dynalite "dynet kode [%s]" (test)  { http="<[http://192.168.0.222/GetDyNet.cgi?a=21:30000" }
Switch dynet  "ON/OFF Area 3 [%s]" (test) { http=">[ON:POST:[http://192.168.0.222/SetDyNet.cgi?a=21&p=1] >[OFF:POST:[http://192.168.0.222/SetDyNet.cgi?a=21&p=6]" }

if i put this http://192.168.0.222/SetDyNet.cgi?a=21&p=1 in to a webbrowser it works perfect, but not on in openhab.

SetDynNet.cgi
This file to send messages to the controller
?a=21&p=1

a= is the area to control
p= is the preset to send

GetDyNet.cgi
This file is used to get status from the controller
?a=21
a= is the area to get status from

The answer from the controller will then be
p=4

p= is the preset the area is in, so I like to display the number in the string like Preset 4 with some mapping maby

OH2 LOG:
on the item I get this error

20:31:12.087 [ERROR] [el.item.internal.GenericItemProvider] - Binding configuration of type 'http' of item 'dynalite' could not be parsed correctly.
org.eclipse.smarthome.model.item.BindingConfigParseException: bindingConfig '<[http://192.168.0.222/GetDyNet.cgi?a=21:30000' doesn't contain a valid binding configuration
        at org.openhab.core.binding.internal.BindingConfigReaderDelegate.processBindingConfiguration(BindingConfigReaderDelegate.java:50)[204:org.openhab.core.compat1x:2.1.0.201706022154]
        at org.eclipse.smarthome.model.item.internal.GenericItemProvider.internalDispatchBindings(GenericItemProvider.java:323)[125:org.eclipse.smarthome.model.item:0.9.0.201706071228]
        at org.eclipse.smarthome.model.item.internal.GenericItemProvider.internalDispatchBindings(GenericItemProvider.java:295)[125:org.eclipse.smarthome.model.item:0.9.0.201706071228]
        at org.eclipse.smarthome.model.item.internal.GenericItemProvider.processBindingConfigsFromModel(GenericItemProvider.java:181)[125:org.eclipse.smarthome.model.item:0.9.0.201706071228]
        at org.eclipse.smarthome.model.item.internal.GenericItemProvider.modelChanged(GenericItemProvider.java:352)[125:org.eclipse.smarthome.model.item:0.9.0.201706071228]
        at org.eclipse.smarthome.model.core.internal.ModelRepositoryImpl.notifyListeners(ModelRepositoryImpl.java:286)[124:org.eclipse.smarthome.model.core:0.9.0.201706071228]
        at org.eclipse.smarthome.model.core.internal.ModelRepositoryImpl.addOrRefreshModel(ModelRepositoryImpl.java:136)[124:org.eclipse.smarthome.model.core:0.9.0.201706071228]
        at org.eclipse.smarthome.model.core.internal.folder.FolderObserver.checkFile(FolderObserver.java:262)[124:org.eclipse.smarthome.model.core:0.9.0.201706071228]
        at org.eclipse.smarthome.model.core.internal.folder.FolderObserver.processWatchEvent(FolderObserver.java:325)[124:org.eclipse.smarthome.model.core:0.9.0.201706071228]
        at org.eclipse.smarthome.core.service.WatchQueueReader.run(WatchQueueReader.java:206)[100:org.eclipse.smarthome.core:0.9.0.201706071228]
        at java.lang.Thread.run(Thread.java:745)[:1.8.0_121]

on the dynet item I get following error then pressing

20:31:55.548 [WARN ] [org.apache.karaf.services.eventadmin] - EventAdmin: Exception during event dispatch [org.osgi.service.event.Event [topic=openhab/command/dynet] {bridgemarker=true, item=dynet, command=ON} | {org.osgi.service.cm.ManagedService, org.osgi.service.event.EventHandler}={event.topics=openhab/*, service.pid=org.openhab.http, component.name=org.openhab.binding.http, component.id=207, service.id=817, service.bundleid=231, service.scope=bundle} | Bundle(org.openhab.binding.http_1.10.0.201706261321 [231])]
java.lang.IllegalArgumentException: Invalid uri '[http://192.168.0.222/SetDyNet.cgi?a=21&p=1': incorrect scheme
        at org.apache.commons.httpclient.HttpMethodBase.<init>(HttpMethodBase.java:222)[60:org.apache.servicemix.bundles.commons-httpclient:3.1.0.7]
        at org.apache.commons.httpclient.methods.GetMethod.<init>(GetMethod.java:89)[60:org.apache.servicemix.bundles.commons-httpclient:3.1.0.7]
        at org.openhab.io.net.http.HttpUtil.createHttpMethod(HttpUtil.java:314)[204:org.openhab.core.compat1x:2.1.0.201706022154]
        at org.openhab.io.net.http.HttpUtil.executeUrl(HttpUtil.java:167)[204:org.openhab.core.compat1x:2.1.0.201706022154]
        at org.openhab.io.net.http.HttpUtil.executeUrl(HttpUtil.java:130)[204:org.openhab.core.compat1x:2.1.0.201706022154]
        at org.openhab.binding.http.internal.HttpBinding.formatAndExecute(HttpBinding.java:285)[231:org.openhab.binding.http:1.10.0.201706261321]
        at org.openhab.binding.http.internal.HttpBinding.internalReceiveCommand(HttpBinding.java:130)[231:org.openhab.binding.http:1.10.0.201706261321]
        at org.openhab.core.binding.AbstractBinding.receiveCommand(AbstractBinding.java:97)[204:org.openhab.core.compat1x:2.1.0.201706022154]
        at org.openhab.core.events.AbstractEventSubscriber.handleEvent(AbstractEventSubscriber.java:45)[204:org.openhab.core.compat1x:2.1.0.201706022154]
        at org.apache.felix.eventadmin.impl.handler.EventHandlerProxy.sendEvent(EventHandlerProxy.java:415)[6:org.apache.karaf.services.eventadmin:4.0.8]
        at org.apache.felix.eventadmin.impl.tasks.HandlerTask.run(HandlerTask.java:90)[6:org.apache.karaf.services.eventadmin:4.0.8]
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)[:1.8.0_121]
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)[:1.8.0_121]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)[:1.8.0_121]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)[:1.8.0_121]
        at java.lang.Thread.run(Thread.java:745)[:1.8.0_121]

Hope someone can help

When you use a web browser it does an HTTP GET, not a POST. Are you sure it is supposed to be a POST?

The errors are informative. It says your http configuration cannot be parsed correctly. When you see errors like this go to the docs and compare yours to what the docs say. In this case, the docs say the transformation is not option. You must provide a transform, even if it is just default which means don’t apply a transform.

The second error is complaining about the URI being invalid. It looks OK to me but there is one thing different between it and the previous one, the &. You may need to escape it using URL encoding (replace the & with %26).

I tryed to change the item to get and change the & to %26

String dynalite "dynet kode [%s]" (test)  { http="<[http://192.168.0.222/GetDyNet.cgi?a=21:30000" }
Switch dynet  "ON/OFF Area 3 [%s]" (test) { http=">[ON:GET:[http://192.168.0.222/SetDyNet.cgi?a=21%26p=1] >[OFF:GET:[http://192.168.0.222/SetDyNet.cgi?a=21%26p=6]" }

I get this error

22:13:22.990 [WARN ] [org.apache.karaf.services.eventadmin] - EventAdmin: Exception during event dispatch [org.osgi.service.event.Event [topic=openhab/command/dynet] {bridgemarker=true, item=dynet, command=ON} | {org.osgi.service.cm.ManagedService, org.osgi.service.event.EventHandler}={event.topics=openhab/*, service.pid=org.openhab.http, component.name=org.openhab.binding.http, component.id=207, service.id=817, service.bundleid=231, service.scope=bundle} | Bundle(org.openhab.binding.http_1.10.0.201706261321 [231])]
java.util.UnknownFormatConversionException: Conversion = 'p'
        at java.util.Formatter$FormatSpecifier.conversion(Formatter.java:2691)[:1.8.0_121]
        at java.util.Formatter$FormatSpecifier.<init>(Formatter.java:2720)[:1.8.0_121]
        at java.util.Formatter.parse(Formatter.java:2560)[:1.8.0_121]
        at java.util.Formatter.format(Formatter.java:2501)[:1.8.0_121]
        at java.util.Formatter.format(Formatter.java:2455)[:1.8.0_121]
        at java.lang.String.format(String.java:2940)[:1.8.0_121]
        at org.openhab.binding.http.internal.HttpBinding.formatAndExecute(HttpBinding.java:266)[231:org.openhab.binding.http:1.10.0.201706261321]
        at org.openhab.binding.http.internal.HttpBinding.internalReceiveCommand(HttpBinding.java:130)[231:org.openhab.binding.http:1.10.0.201706261321]
        at org.openhab.core.binding.AbstractBinding.receiveCommand(AbstractBinding.java:97)[204:org.openhab.core.compat1x:2.1.0.201706022154]
        at org.openhab.core.events.AbstractEventSubscriber.handleEvent(AbstractEventSubscriber.java:45)[204:org.openhab.core.compat1x:2.1.0.201706022154]
        at org.apache.felix.eventadmin.impl.handler.EventHandlerProxy.sendEvent(EventHandlerProxy.java:415)[6:org.apache.karaf.services.eventadmin:4.0.8]
        at org.apache.felix.eventadmin.impl.tasks.HandlerTask.run(HandlerTask.java:90)[6:org.apache.karaf.services.eventadmin:4.0.8]
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)[:1.8.0_121]
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)[:1.8.0_121]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)[:1.8.0_121]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)[:1.8.0_121]
        at java.lang.Thread.run(Thread.java:745)[:1.8.0_121]

I have allso tryed with the & and the GET, then I get this error.

22:13:39.005 [WARN ] [org.apache.karaf.services.eventadmin] - EventAdmin: Exception during event dispatch [org.osgi.service.event.Event [topic=openhab/command/dynet] {bridgemarker=true, item=dynet, command=OFF} | {org.osgi.service.cm.ManagedService, org.osgi.service.event.EventHandler}={event.topics=openhab/*, service.pid=org.openhab.http, component.name=org.openhab.binding.http, component.id=207, service.id=817, service.bundleid=231, service.scope=bundle} | Bundle(org.openhab.binding.http_1.10.0.201706261321 [231])]
java.lang.IllegalArgumentException: Invalid uri '[http://192.168.0.222/SetDyNet.cgi?a=21&p=6': incorrect scheme
        at org.apache.commons.httpclient.HttpMethodBase.<init>(HttpMethodBase.java:222)[60:org.apache.servicemix.bundles.commons-httpclient:3.1.0.7]
        at org.apache.commons.httpclient.methods.GetMethod.<init>(GetMethod.java:89)[60:org.apache.servicemix.bundles.commons-httpclient:3.1.0.7]
        at org.openhab.io.net.http.HttpUtil.createHttpMethod(HttpUtil.java:314)[204:org.openhab.core.compat1x:2.1.0.201706022154]
        at org.openhab.io.net.http.HttpUtil.executeUrl(HttpUtil.java:167)[204:org.openhab.core.compat1x:2.1.0.201706022154]
        at org.openhab.io.net.http.HttpUtil.executeUrl(HttpUtil.java:130)[204:org.openhab.core.compat1x:2.1.0.201706022154]
        at org.openhab.binding.http.internal.HttpBinding.formatAndExecute(HttpBinding.java:285)[231:org.openhab.binding.http:1.10.0.201706261321]
        at org.openhab.binding.http.internal.HttpBinding.internalReceiveCommand(HttpBinding.java:130)[231:org.openhab.binding.http:1.10.0.201706261321]
        at org.openhab.core.binding.AbstractBinding.receiveCommand(AbstractBinding.java:97)[204:org.openhab.core.compat1x:2.1.0.201706022154]
        at org.openhab.core.events.AbstractEventSubscriber.handleEvent(AbstractEventSubscriber.java:45)[204:org.openhab.core.compat1x:2.1.0.201706022154]
        at org.apache.felix.eventadmin.impl.handler.EventHandlerProxy.sendEvent(EventHandlerProxy.java:415)[6:org.apache.karaf.services.eventadmin:4.0.8]
        at org.apache.felix.eventadmin.impl.tasks.HandlerTask.run(HandlerTask.java:90)[6:org.apache.karaf.services.eventadmin:4.0.8]
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)[:1.8.0_121]
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)[:1.8.0_121]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)[:1.8.0_121]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)[:1.8.0_121]
        at java.lang.Thread.run(Thread.java:745)[:1.8.0_121]

I cant see what to do in the docs

I don’t do much with HTTP so am out of ideas. It may not handle passing multiple arguments.

I told you above:

the docs say the transformation is not option. You must provide a transform, even if it is just default which means don’t apply a transform.

http://docs.openhab.org/addons/bindings/http1/readme.html#item-configuration

The syntax for the HTTP binding configuration string is given below.

Receive repeated updates from a URL (“in” binding):

http="<[<url>:<refreshintervalinmilliseconds>:<transformationrule>]"

I says nothing about <transformationrule> being optional. All the examples show a transformation rule. You must add a transformation rule to your first Item.

and the closing bracket “]” is missing…

Now my items looks like this

String dynalite "dynet kode [%s]" (test)  { http="<[http://192.168.0.222/GetDyNet.cgi?a=21:30000:default]" }
Switch dynet  "ON/OFF Area 3 [%s]" (test) { http=">[ON:[http://192.168.0.222/SetDyNet.cgi?a=21&p=1:default] >[OFF:[http://192.168.0.222/SetDyNet.cgi?a=21&p=6:default]" }

19:41:19.887 [ERROR] [org.openhab.io.net.http.HttpUtil    ] - Fatal transport error: org.apache.commons.httpclient.NoHttpResponseException: The server 192.168.0.222 failed to respond
19:41:19.888 [ERROR] [ab.binding.http.internal.HttpBinding] - No response received from 'http://192.168.0.222/GetDyNet.cgi?a=21'

Is there a way to test if I can receive a HTTP Get message with some other program, to see if it is a OH2 problem.

My switch does not work either, there is no errors in the log

19:47:45.588 [INFO ] [smarthome.event.ItemCommandEvent    ] - Item 'dynet' received command ON
19:47:45.594 [INFO ] [marthome.event.ItemStateChangedEvent] - dynet changed from OFF to ON

As I said above:

When you use a web browser it does an HTTP GET