I’m trying to get a curl script working, but I can’t get OH2 to return anything at all.
In 2.0.0b3, and the the latest snapshot, it fails so I feel like I’m missing something crucial. I have installed the exec and http bindings through paperUI. As well as a few transformations fwiw.
rule TestRule
when
Item test_Payload received update
then
logInfo(“Sensor”, “Test Sensor Payload arrived…”) //To tell me the script fired OK
logInfo(“Sensor”, test_Payload.state.toString) //To show the curl string in the log
I’ve tried using executeCommandLine and the result is the same.
If I simplify my test curl to something different like curl http://www.centos.org The result is also the same.
The curl script is part of a larger rule which has some JSON transformations,. This throws an error about how the JSON string cannot be null or empty, hence my stripped back test to get it figured out. I’m trying this on a Win10x64 machine right now, but have similar results from my Pi3 running raspbian.
I should also add, that running the curl script in Windows (using Cygwin) works fine, as does doing the same on OSX (terminal) and my Pi3 (via ssh).
Does the script work as expected, if you call it from command line? I think, there is a missing quotation mark (") at the end of the curl line (could be copy-paste issue, though)
Ok, so if I use the timeout and the simple curl http://www.centos.org string then I get the expected log result. Thanks.
However, if I use the longer string
val String results = executeCommandLine("curl curl@@--silent@@-X@@POST@@-H@@"host:@@mytaglist.com"@@-H@@"Content-Type:@@application/json;@@charset=utf-8"@@-H@@"Authorization:@@bearer@@9cb01305-b6d7-47c2-ada9-614f04749838"@@-H@@"d:@@"""@@-H@@"Cache-Control:@@no-cache"@@-H@@"Postman-Token:@@7f208f85-2c1f-96ce-2ca7-033fab5b83fe"@@-d@@''@@"http://mytaglist.com/ethClient.asmx/GetTagList"", 5000)
logInfo("curl", results)
I get the info/error:
[INFO ] [lipse.smarthome.io.net.exec.ExecUtil] - executed commandLine '[curl, --silent, -X, POST, -H]'
[ERROR] [.script.engine.ScriptExecutionThread] - Rule 'TestRule': An error occured during the script execution: The name 'host' cannot be resolved to an item or type.
This happens whether I use spaces, or replace them with @@ as mentioned in other similar topics.
You need to escape quotes(") that appear inside of quotes using a backslash. Otherwise it thinks the String has ended and tries to treat the “host” part as a variable.
It appears to finish the curl early, and OH doesn’t log anything at all. I’ll keep trying to figure out how to escape the -H d: portion of the script as it’s different to the rest but I’m really only guessing.
It was always failing with the single quotes at the end of the curl ...-d '' \"http://myt...
This has to read ...-d {} \"http://myt...
My theory is that the single quotes were just to say to post nothing to the following address. However looking around all the references I could find to a similar technique used curly brackets.