Http binding error, Invalid query

Trying to get data from a Janitza power analyser. If I send “http://10.10.1.135/json.do?_PLN[0]” from Google Crome I get the expected reply:
{ “_PLN”: [[ 0.0789],“W”]}.

The JSON transformation do work if I hard code the reply string in a rule,
var String json=’{ “_PLN”: [[ 0.2375],“W”]}’
var test = transform(“JSONPATH”,"$._PLN[0].[0]",json)
println(test)

I then created an item:
Number Total_Power “Total Power [%d W]” {http="<[http://10.10.1.135/json.do?_PLN[0]:20000:JSONPATH($._PLN[0].[0])]"}
And if i run OH with that item I get the following error:
2015-12-29 13:14:16.779 [ERROR] [.service.AbstractActiveService] - Error while executing background thread HTTP Refresh Service
java.lang.IllegalArgumentException: Invalid uri ‘http://10.10.1.135/json.do?_PLN[0]’: Invalid query
at org.apache.commons.httpclient.HttpMethodBase.(HttpMethodBase.java:222) ~[na:na]
at org.apache.commons.httpclient.methods.GetMethod.(GetMethod.java:89) ~[na:na]
at org.openhab.io.net.http.HttpUtil.createHttpMethod(HttpUtil.java:337) ~[na:na]
at org.openhab.io.net.http.HttpUtil.executeUrl(HttpUtil.java:167) ~[na:na]
at org.openhab.io.net.http.HttpUtil.executeUrl(HttpUtil.java:133) ~[na:na]
at org.openhab.binding.http.internal.HttpBinding.execute(HttpBinding.java:164) ~[na:na]
at org.openhab.core.binding.AbstractActiveBinding$BindingActiveService.execute(AbstractActiveBinding.java:156) ~[na:na]
at org.openhab.core.service.AbstractActiveService$RefreshThread.run(AbstractActiveService.java:173) ~[na:na]

What have I done wrong?

Warning… I haven’t used the JSONPATH transformation. However, the period between the “[0]” elements looks suspicious to me. Have you tried "$._PLN[0][0]"? Just a thought.

Tried that, no change.
I think the error have something to do with the query format as the exception message says “Invalid uri ‘http://10.10.1.135:80/json.do?_PLN[0]’: Invalid query”. But I don´t have a clue

OK, second guess. :slight_smile: RFC1738 (Uniform Resource Locators) says…

Characters can be unsafe for a number of reasons. …

Other characters are unsafe because gateways and other transport agents are known to sometimes modify such characters. These characters are “{”, “}”, “|”, "", “^”, “~”, “[”, “]”, and “`”.

All unsafe characters must always be encoded within a URL.

I may have missed it but I don’t see any place in the source code where the HTTP binding encodes the URL for you. You could try

http://10.10.1.135/json.do?_PLN%5B0%5D

with encoded “[” and “]” and see if that is considered valid.

EDIT: Chrome would have encoded the URL for you.

http://10.10.1.135/json.do?_PLN[0]” it’s not working but I got a new error message:

2015-12-29 15:53:23.472 [ERROR] [.service.AbstractActiveService] - Error while executing background thread HTTP Refresh Service
java.util.MissingFormatArgumentException: Format specifier ‘%5d’
at java.util.Formatter.format(Unknown Source) ~[na:1.8.0_65]
at java.util.Formatter.format(Unknown Source) ~[na:1.8.0_65]
at java.lang.String.format(Unknown Source) ~[na:1.8.0_65]
at org.openhab.binding.http.internal.HttpBinding.execute(HttpBinding.java:139) ~[na:na]
at org.openhab.core.binding.AbstractActiveBinding$BindingActiveService.execute(AbstractActiveBinding.java:156) ~[na:na]
at org.openhab.core.service.AbstractActiveService$RefreshThread.run(AbstractActiveService.java:173) ~[na:na]

And if I use “http://10.10.1.135/json.do?_PLN[0]” i get a slightly different error message:

2015-12-29 15:48:16.332 [ERROR] [.service.AbstractActiveService] - Error while executing background thread HTTP Refresh Service
java.util.UnknownFormatConversionException: Conversion = ‘D’
at java.util.Formatter$FormatSpecifier.conversion(Unknown Source) ~[na:1.8.0_65]
at java.util.Formatter$FormatSpecifier.(Unknown Source) ~[na:1.8.0_65]
at java.util.Formatter.parse(Unknown Source) ~[na:1.8.0_65]
at java.util.Formatter.format(Unknown Source) ~[na:1.8.0_65]
at java.util.Formatter.format(Unknown Source) ~[na:1.8.0_65]
at java.lang.String.format(Unknown Source) ~[na:1.8.0_65]
at org.openhab.binding.http.internal.HttpBinding.execute(HttpBinding.java:139) ~[na:na]
at org.openhab.core.binding.AbstractActiveBinding$BindingActiveService.execute(AbstractActiveBinding.java:156) ~[na:na]
at org.openhab.core.service.AbstractActiveService$RefreshThread.run(AbstractActiveService.java:173) ~[na:na]

The HTTP binding is interpreting the % as a start of a Java format specification. See…

https://github.com/openhab/openhab/wiki/Http-Binding (Dynamic URL Enhancement)

Use…

http://10.10.1.135/json.do?_PLN%%5B0%%5D

(double %) to workaround the binding formatting feature.

Yesss, now it working :smile:

Thank you very much for your help, i had nerver fix it by my self