HTTP Binding Data-Binary

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

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…

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…

@namraccr @rlkoshak @jwveldhuis

Ding Ding :smile:

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…?

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:

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

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)

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…

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

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

Same result, the rule goes into the if statement.

val jsonString = JSON_SMA.state.toString

    if (jsonString != null) {
        number_SMA_DCVermogenA.postUpdate(transform("JSONPATH","$.result.XXXX-XXXXXXXX.XXXX_XXXXXXXX.1.0.val", jsonString))
    }
2018-03-18 08:09:37.300 [INFO ] [.eclipse.smarthome.model.script.RULE] - JSON from SMA inverter changed!
2018-03-18 08:09:37.301 [ERROR] [.script.engine.ScriptExecutionThread] - Rule 'Process JSON from SMA Inverter': The argument 'state' must not be null or empty.

The error is somewhere in the transform part:

if (jsonString != null) {
        //number_SMA_DCVermogenA.postUpdate(transform("JSONPATH","$.result.0156-76BC5229.6100_00411E00.1.0.val", jsonString))

        val tester = transform("JSONPATH","$.result.0156-76BC5229.6100_00411E00.1.0.val", jsonString)
        logInfo("RULE", tester)
        //postUpdate(number_SMA_DCVermogenA,tester)

    }

The loginfo rule for the tester is empty in the logging:

2018-03-18 08:26:54.200 [INFO ] [.eclipse.smarthome.model.script.RULE] - JSON from SMA inverter changed!
2018-03-18 08:26:54.201 [INFO ] [.eclipse.smarthome.model.script.RULE] -

But it looks like it doesn’t, your jsonString is "" and should contain the whole json.
Where is the json?

jsonString is not “”, that’s what we proved by outputting them to the log here, no?

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…

The empty rule log line is coming from the

        logInfo("RULE", tester)

And tester should contain the transformed value but something is going wrong there I think, or am I misunderstanding you?

I misread. tester should contain the transformed value.
Can you post your json? Maybe the path is incorrect and the transform returns ""

You can check your path with:

Jup, that’s what I used to check it and it returns a number last time I checked :slight_smile:

This is my jsonpath.
$.result.0156-76BC5229.6100_00411E00.1.0.val

I have pasted my JSON here (it will expire in 1 hour)
https://pastebin.com/UNTNa0v6

Sorry, I missed it. I was at work.
Could you resend it, please
Thanks

Yeah it was pretty tight timing :smiley:

I have sent you a new pastebin link which is valid for a day.

The JSONPATH is:

$.result.0156-76BC5229.6100_00411E00.1[0].val

Well I’ll be dmnd :roll_eyes:

My JSONPATH gives the exact same result in the analyzer as yours and yours is working fine and mine doesn’t. :exploding_head:

I loaded your json in jsonpath.com and your jsonpath didn’t work, so I fiddled a bit and got that one.
Did you get all your items up and running?

Very bizarre because when I use mine in the json path analyzer I get the 4000 value too(?)

No, didn’t get them all up and running, it was a little bit too late on a sunday evening :slight_smile: . Will implement today.