# HTTP Binding Data-Binary

**URL:** <https://community.openhab.org/t/http-binding-data-binary/41722>\
**Category:** Items & Sitemaps\
**Created:** [March 14, 2018, 12:22pm UTC](https://community.openhab.org/t/http-binding-data-binary/41722 "2018-03-14T12:22:05Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![hyperbart](https://community.openhab.org/user_avatar/community.openhab.org/hyperbart/32/72154_2.png) [@hyperbart](https://community.openhab.org/u/hyperbart)\
**Post date:** [March 14, 2018, 12:22pm UTC](https://community.openhab.org/t/http-binding-data-binary/41722/1 "2018-03-14T12:22:05Z")

</div>

- Platform information:
  - Hardware: X86/8GB/SSD
  - OS: Ubuntu
  - Java Runtime Environment:
  - openHAB version: 2

- Issue of the topic: I have a device in my network which I can launch a CURL command against and it will return a JSON file which I want to pull apart and show in OpenHAB. I prefer to do this with the HTTP binding.

The curl command is:

curl ‘[http://10.0.0.2/dyn/getAllOnlValues.json?sid=7Y-18GWyxTBylEWF](http://10.0.0.2/dyn/getAllOnlValues.json?sid=7Y-18GWyxTBylEWF)’ --data-binary ‘{“destDev”:}’

The --data-binary option is mandatory, if I delete it, the server returns a 404 error.

The JSON is quite big and via JSON-path statements I succeeded in getting the right values (tested this with [http://jsonpath.com/](http://jsonpath.com/), it returns the value I want between square brackets

 ![image](https://community-openhab-org.s3.dualstack.eu-central-1.amazonaws.com/original/3X/4/a/4a3ca7c632f6f477489db9e04f7d73c64ce3181a.jpeg)

This is my items file:

Number http\_number\_PowerA “Vermogen A [%.1f]” { http=“\<[[http://10.0.0.2/dyn/getAllOnlValues.json?sid=7Y-18GWyxTBylEWF](http://10.0.0.2/dyn/getAllOnlValues.json?sid=7Y-18GWyxTBylEWF)’:JSONPATH($.result.0123-76AD1234.5432\_40251E00.1.0.val)]” }

And I have created an entry in sitemap:

Text item=http\_number\_PowerA

However, the item stays empty… How do I pass the --data-binary option in the HTTP binding?

---

<div class="post-metadata">

**Author:** ![rlkoshak](https://community.openhab.org/user_avatar/community.openhab.org/rlkoshak/32/75251_2.png) [@rlkoshak](https://community.openhab.org/u/rlkoshak)\
**Post date:** [March 14, 2018, 4:11pm UTC](https://community.openhab.org/t/http-binding-data-binary/41722/2 "2018-03-14T16:11:32Z")

</div>

I do not believe you can. I think you will have to continue to use curl and use the Exec binding or executeCommandLine to access this data.

---

<div class="post-metadata">

**Author:** ![hyperbart](https://community.openhab.org/user_avatar/community.openhab.org/hyperbart/32/72154_2.png) [@hyperbart](https://community.openhab.org/u/hyperbart)\
**Post date:** [March 15, 2018, 12:40pm UTC](https://community.openhab.org/t/http-binding-data-binary/41722/3 "2018-03-15T12:40:54Z")

</div>

Okay, trying to get that working now:

exec.items file:

```csv
String SMAJSON "[%s]" (All) {channel="exec:command:smajson"}

```

exec.things file:

```csv
Thing exec:command:smajson [command="curl 'http://192.168.4.129/dyn/getAllOnlValues.json?sid=yBak0jS7r0F7TjSX' --data '{"destDev":[]}'", interval=15, timeout=5]

```

But logging is saying some strange things:

```javascript
2018-03-15 13:39:36.017 [ERROR] [el.item.internal.GenericItemProvider] - Binding configuration of type 'channel' of item 'SMAJSON' could not be parsed correctly.
org.eclipse.smarthome.model.item.BindingConfigParseException: UID must have at least 4 segments.
        at org.eclipse.smarthome.model.thing.internal.GenericItemChannelLinkProvider.createItemChannelLink(GenericItemChannelLinkProvider.java:82)[133:org.eclipse.smarthome.model.thing:0.9.0.b4]
        at org.eclipse.smarthome.model.thing.internal.GenericItemChannelLinkProvider.processBindingConfiguration(GenericItemChannelLinkProvider.java:72)[133:org.eclipse.smarthome.model.thing:0.9.0.b4]
        at org.eclipse.smarthome.model.item.internal.GenericItemProvider.internalDispatchBindings(GenericItemProvider.java:312)[123:org.eclipse.smarthome.model.item:0.9.0.b4]
        at org.eclipse.smarthome.model.item.internal.GenericItemProvider.internalDispatchBindings(GenericItemProvider.java:284)[123:org.eclipse.smarthome.model.item:0.9.0.b4]
        at org.eclipse.smarthome.model.item.internal.GenericItemProvider.processBindingConfigsFromModel(GenericItemProvider.java:167)[123:org.eclipse.smarthome.model.item:0.9.0.b4]
        at org.eclipse.smarthome.model.item.internal.GenericItemProvider.modelChanged(GenericItemProvider.java:347)[123:org.eclipse.smarthome.model.item:0.9.0.b4]
        at org.eclipse.smarthome.model.core.internal.ModelRepositoryImpl.notifyListeners(ModelRepositoryImpl.java:207)[122:org.eclipse.smarthome.model.core:0.9.0.b4]
        at org.eclipse.smarthome.model.core.internal.ModelRepositoryImpl.addOrRefreshModel(ModelRepositoryImpl.java:120)[122:org.eclipse.smarthome.model.core:0.9.0.b4]
        at org.eclipse.smarthome.model.core.internal.folder.FolderObserver.checkFile(FolderObserver.java:272)[122:org.eclipse.smarthome.model.core:0.9.0.b4]
        at org.eclipse.smarthome.model.core.internal.folder.FolderObserver.access$1(FolderObserver.java:265)[122:org.eclipse.smarthome.model.core:0.9.0.b4]
        at org.eclipse.smarthome.model.core.internal.folder.FolderObserver$WatchQueueReader.processWatchEvent(FolderObserver.java:146)[122:org.eclipse.smarthome.model.core:0.9.0.b4]
        at org.eclipse.smarthome.core.service.AbstractWatchQueueReader.run(AbstractWatchQueueReader.java:122)[98:org.eclipse.smarthome.core:0.9.0.b4]
        at java.lang.Thread.run(Thread.java:745)[:1.8.0_121]

```

---

<div class="post-metadata">

**Author:** ![jwveldhuis](https://community.openhab.org/user_avatar/community.openhab.org/jwveldhuis/32/21522_2.png) [@jwveldhuis](https://community.openhab.org/u/jwveldhuis)\
**Post date:** [March 15, 2018, 2:22pm UTC](https://community.openhab.org/t/http-binding-data-binary/41722/4 "2018-03-15T14:22:01Z")

</div>

You pass `--data` instead of `--data-binary`?

---

<div class="post-metadata">

**Author:** ![hyperbart](https://community.openhab.org/user_avatar/community.openhab.org/hyperbart/32/72154_2.png) [@hyperbart](https://community.openhab.org/u/hyperbart)\
**Post date:** [March 15, 2018, 2:25pm UTC](https://community.openhab.org/t/http-binding-data-binary/41722/5 "2018-03-15T14:25:09Z")

</div>

Yes, that works too. But doesn’t matter because afaics (?) the regular --data option isn’t supported either in the HTTP binding, so that’s why I diverted to exec binding.

Open for any suggestion though!

---

<div class="post-metadata">

**Author:** ![jwveldhuis](https://community.openhab.org/user_avatar/community.openhab.org/jwveldhuis/32/21522_2.png) [@jwveldhuis](https://community.openhab.org/u/jwveldhuis)\
**Post date:** [March 15, 2018, 2:27pm UTC](https://community.openhab.org/t/http-binding-data-binary/41722/6 "2018-03-15T14:27:28Z")

</div>

Maybe need to escape the `"` in `..{"destDev":[]}'"`.  
I hate this too, it’s to hard to find out the correct syntax.. while you know it should be possible..

You could create a shell script that includes the curl call, to avoid the need for the special chars in the exec command text.

---

<div class="post-metadata">

**Author:** ![jwveldhuis](https://community.openhab.org/user_avatar/community.openhab.org/jwveldhuis/32/21522_2.png) [@jwveldhuis](https://community.openhab.org/u/jwveldhuis)\
**Post date:** [March 15, 2018, 2:36pm UTC](https://community.openhab.org/t/http-binding-data-binary/41722/7 "2018-03-15T14:36:49Z")

</div>

ah, just learned about this 2.0 way of using the Exec binding. You miss the Channel name in the Item.  
`{channel="exec:command:smajson:output"}` (append **:output** )

---

<div class="post-metadata">

**Author:** ![rlkoshak](https://community.openhab.org/user_avatar/community.openhab.org/rlkoshak/32/75251_2.png) [@rlkoshak](https://community.openhab.org/u/rlkoshak)\
**Post date:** [March 15, 2018, 2:37pm UTC](https://community.openhab.org/t/http-binding-data-binary/41722/8 "2018-03-15T14:37:42Z")

</div>

> [@jwveldhuis](#):
>
> I hate this too, it’s to hard to find out the correct syntax… while you know it should be possible…

VSCode does wonders for stuff like this.

In this case, you can see just by looking at the way the forum did syntax highlighting that this is the problem. The command needs to be a single String.

![image](https://community-openhab-org.s3.dualstack.eu-central-1.amazonaws.com/original/3X/e/1/e17fd1e843cd3834d143c9ad9ee12068e4eabc92.png)

The fact that destDev is highlighted in black instead of red like the rest of the String shows you that it isn’t being seen as a single string. Escape the double quotes and it will not treat the " as the end of the string but as part of the string.

```
'{\"destDev\":[]}'"

```

This would have been a problem in exec 1.x, HTTP, in Rules or anywhere else.

---

<div class="post-metadata">

**Author:** ![hyperbart](https://community.openhab.org/user_avatar/community.openhab.org/hyperbart/32/72154_2.png) [@hyperbart](https://community.openhab.org/u/hyperbart)\
**Post date:** [March 15, 2018, 2:45pm UTC](https://community.openhab.org/t/http-binding-data-binary/41722/9 "2018-03-15T14:45:54Z")

</div>

> [@rlkoshak](#):
>
> This would have been a problem in exec 1.x, HTTP, in Rules or anywhere else.

I think we’re getting somewhere:

```javascript
2018-03-15 15:45:04.524 [INFO] [el.core.internal.ModelRepositoryImpl] - Loading model 'exec.things'
2018-03-15 15:45:04.543 [INFO] [el.core.internal.ModelRepositoryImpl] - Refreshing model 'exec.things'
2018-03-15 15:45:04.557 [ERROR] [hab.binding.exec.handler.ExecHandler] - An exception occurred while waiting for the process ('curl 'http://192.168.4.129/dyn/getAllOnlValues.json?sid=yBak0jS7r0F7TjSX' --data '{"destDev":[]}'') to finish : 'null'
2018-03-15 15:45:04.558 [WARN] [hab.binding.exec.handler.ExecHandler] - Forcibly termininating the process ('curl 'http://192.168.4.129/dyn/getAllOnlValues.json?sid=yBak0jS7r0F7TjSX' --data '{"destDev":[]}'') after a timeout of 15000 ms

```

This is my file now:  
exec.things

```csv
Thing exec:command:smajson:output [command="curl 'http://192.168.4.129/dyn/getAllOnlValues.json?sid=yBak0jS7r0F7TjSX' --data '{\"destDev\":[]}'"", interval=15, timeout=5]

```

exec.items

```csv
String SMAJSON "[%s]" (All) {channel="exec:command:smajson:output"}

```

---

<div class="post-metadata">

**Author:** ![jwveldhuis](https://community.openhab.org/user_avatar/community.openhab.org/jwveldhuis/32/21522_2.png) [@jwveldhuis](https://community.openhab.org/u/jwveldhuis)\
**Post date:** [March 15, 2018, 2:51pm UTC](https://community.openhab.org/t/http-binding-data-binary/41722/10 "2018-03-15T14:51:00Z")

</div>

I don’t think the **Thing** should have the `:output` in it’s definition. The Item should.

---

<div class="post-metadata">

**Author:** ![hyperbart](https://community.openhab.org/user_avatar/community.openhab.org/hyperbart/32/72154_2.png) [@hyperbart](https://community.openhab.org/u/hyperbart)\
**Post date:** [March 15, 2018, 2:57pm UTC](https://community.openhab.org/t/http-binding-data-binary/41722/11 "2018-03-15T14:57:31Z")

</div>

Okay, we’re getting something now.

Item is updated to:

> curl: (1) Protocol “'http” not supported or disabled in libcurl curl: (1) Protocol “'http” not supported or disabled in libcurl

This is my exec.things file now:

```csv
Thing exec:command:smajson [command="curl 'http://192.168.4.129/dyn/getAllOnlValues.json?sid=yBak0jS7r0F7TjSX' --data '{\"destDev\":[]}'", interval=15, timeout=5]

```

---

<div class="post-metadata">

**Author:** ![namraccr](https://community.openhab.org/user_avatar/community.openhab.org/namraccr/32/36484_2.png) [@namraccr](https://community.openhab.org/u/namraccr)\
**Post date:** [March 16, 2018, 4:03am UTC](https://community.openhab.org/t/http-binding-data-binary/41722/12 "2018-03-16T04:03:09Z")

</div>

```auto
curl: (1) Protocol “'http” not supported or disabled in libcurl curl

```

Your URL needs to:  
a) Come after the options  
b) be either not quoted or wrapped in double quotes, not single quotes

---

<div class="post-metadata">

**Author:** ![hyperbart](https://community.openhab.org/user_avatar/community.openhab.org/hyperbart/32/72154_2.png) [@hyperbart](https://community.openhab.org/u/hyperbart)\
**Post date:** [March 16, 2018, 6:54am UTC](https://community.openhab.org/t/http-binding-data-binary/41722/13 "2018-03-16T06:54:04Z")

</div>

After which options? Like this then?

Thing exec:command:smajson [command=“curl --data ‘{"destDev":}’ [http://192.168.4.129/dyn/getAllOnlValues.json?sid=yBak0jS7r0F7TjSX](http://192.168.4.129/dyn/getAllOnlValues.json?sid=yBak0jS7r0F7TjSX)”, interval=15, timeout=5]

After deleting the single quotes around the URL I’m getting a 404 now, which means the data option is not getting passed through or something is going wrong there.

---

<div class="post-metadata">

**Author:** ![rlkoshak](https://community.openhab.org/user_avatar/community.openhab.org/rlkoshak/32/75251_2.png) [@rlkoshak](https://community.openhab.org/u/rlkoshak)\
**Post date:** [March 16, 2018, 1:43pm UTC](https://community.openhab.org/t/http-binding-data-binary/41722/14 "2018-03-16T13:43:36Z")

</div>

> [@hyperbart](#):
>
> –data-binary

In your OP you used --data-binary but in these later posts you are using --data

---

<div class="post-metadata">

**Author:** ![hyperbart](https://community.openhab.org/user_avatar/community.openhab.org/hyperbart/32/72154_2.png) [@hyperbart](https://community.openhab.org/u/hyperbart)\
**Post date:** [March 16, 2018, 7:27pm UTC](https://community.openhab.org/t/http-binding-data-binary/41722/15 "2018-03-16T19:27:36Z")

</div>

Good thinking Rich, but unfortunately that’s not the issue, I tested that before I changed the option and --data was okay too.

Tested it in the exec.things file with --data-binary to no avail…

---

<div class="post-metadata">

**Author:** ![namraccr](https://community.openhab.org/user_avatar/community.openhab.org/namraccr/32/36484_2.png) [@namraccr](https://community.openhab.org/u/namraccr)\
**Post date:** [March 17, 2018, 3:04am UTC](https://community.openhab.org/t/http-binding-data-binary/41722/16 "2018-03-17T03:04:14Z")

</div>

> [@hyperbart](#):
>
> After deleting the single quotes around the URL I’m getting a 404 now, which means the data option is not getting passed through or something is going wrong there.

Probably still a quoting issue there somewhere, then. You could grab a debug log to try to figure out what the binding thinks it’s executing…

---

<div class="post-metadata">

**Author:** ![hyperbart](https://community.openhab.org/user_avatar/community.openhab.org/hyperbart/32/72154_2.png) [@hyperbart](https://community.openhab.org/u/hyperbart)\
**Post date:** [March 17, 2018, 8:58pm UTC](https://community.openhab.org/t/http-binding-data-binary/41722/17 "2018-03-17T20:58:39Z")

</div>

@namraccr @rlkoshak @jwveldhuis

Ding Ding 😄

After doing some TCP dumps I saw the difference and the solution was deleting the single qutoes around the curly brackets.

The item gets populated with the JSON now but that brings up a new question:

Can you process an item and split it in different new items without using rules? I was thinking of creating a JSONSMA-item and make “sub-items” which point to the “main” item and process that main item with JSONPATH so the sub-items get populated…?

---

<div class="post-metadata">

**Author:** ![vzorglub](https://community.openhab.org/user_avatar/community.openhab.org/vzorglub/32/17166_2.png) [@vzorglub](https://community.openhab.org/u/vzorglub)\
**Post date:** [March 17, 2018, 10:03pm UTC](https://community.openhab.org/t/http-binding-data-binary/41722/18 "2018-03-17T22:03:11Z")

</div>

You could use the JSONPATH transform in the thing but that gives you only one item  
unfortunately you can’t do that without a rule

see:

> [@Exec JSONPATH](https://community.openhab.org/t/exec-jsonpath/34397):
>
> Hi, Is it possible to apply jsonpath to the item? i have a thing that gets a json result. Thing exec:command:testitem [command="python /etc/openhab2/scripts/test.py", interval=900, timeout=10] { "store": { "book": [ { "category": "reference", "author": "Nigel Rees", "title": "Sayings of the Century", "price": 8.95 }, { "category": "fiction", "author": "Evelyn Waugh", "title": "Sword of Honour", "price": 12.99 }, …

```php
rule "jsonpath"
when
    Item SMAJSON changed
then
    val jsonString = SMAJSON.state.toString
    Item1.postUpdate(transform("JSONPATH",".$.path.path1", jsonString))
    Item2.postUpdate(transform("JSONPATH",".$.path.path2", jsonString))
    Item3.postUpdate(transform("JSONPATH",".$.path.path3", jsonString))
end

```

---

<div class="post-metadata">

**Author:** ![hyperbart](https://community.openhab.org/user_avatar/community.openhab.org/hyperbart/32/72154_2.png) [@hyperbart](https://community.openhab.org/u/hyperbart)\
**Post date:** [March 17, 2018, 11:55pm UTC](https://community.openhab.org/t/http-binding-data-binary/41722/19 "2018-03-17T23:55:36Z")

</div>

Thanks for the quick reply, it confirmed my fears I should start writing a rule again.

Continuing with this story, I implemented your rule (changed the variables names to match my naming convention)

```php
rule "Process JSON from SMA Inverter"
when
    Item JSON_SMA changed
then
    logInfo("RULE", "JSON from SMA inverter changed!")

    logInfo("RULE", "---------------------------------------------------------------------------------")
    logInfo("RULE", "-----------------------------WRITING THE ITEM TO LOG-----------------------------")
    logInfo("RULE", "---------------------------------------------------------------------------------")
    logInfo("RULE", JSON_SMA.state.toString)

    val jsonString = JSON_SMA.state.toString

    logInfo("RULE", "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-")
    logInfo("RULE", "++++++++++++++++++++++++++++WRITING THE STRING TO LOG++++++++++++++++++++++++++++")
    logInfo("RULE", "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-")
    logInfo("RULE", jsonString)

    

    number_SMA_DCVermogenA.postUpdate(transform("JSONPATH","$.result.XXXX-XXXXXXXX.XXXX_XXXXXXXX.1.0.val", jsonString))
    
    

```

However, the logging shows:

2018-03-18 00:37:24.078 [ERROR] [.script.engine.ScriptExecutionThread] - Rule ‘Process JSON from SMA Inverter’: The argument ‘state’ must not be null or empty

So I checked if it really was empty or null, which it isn’t. I’m outputting both the item defined in the items file to the log and the jsonString val object and they both return the JSON in the log file…

If I comment out the number\_SMA… transform rule, the error disappears in the logging. Additional strange thing is that I have multiple of these code-lines (vermogen means power in Dutch, so I have power,amperage,voltage etc) but I’m seeing the error only once though I would expect to see it the amount of times I have defined a statement to process a value…

---

<div class="post-metadata">

**Author:** ![vzorglub](https://community.openhab.org/user_avatar/community.openhab.org/vzorglub/32/17166_2.png) [@vzorglub](https://community.openhab.org/u/vzorglub)\
**Post date:** [March 18, 2018, 12:35am UTC](https://community.openhab.org/t/http-binding-data-binary/41722/20 "2018-03-18T00:35:12Z")

</div>

add an if condition to test is the string is null  
It will be on the first execution of the rule after saving the file and should be fine thereafter

```php
if (jsonString != null) {
    number_SMA_DCVermogenA.postUpdate(transform("JSONPATH","$.result.XXXX-XXXXXXXX.XXXX_XXXXXXXX.1.0.val", jsonString))
}

```

[Next page](https://community.openhab.org/t/http-binding-data-binary/41722.md?page=2)
