sendHttpGetRequest Json any way possible

  • Platform information:
    • Hardware:Raspberry pi4_
    • Java Runtime Environment: which java platform is used and what version
    • openHAB version: Openhabian 2.5

I am trying to use the “sendHttpGetRequest” but unfortunately that is not yet supported in openhab2.5.
my original rule was:

var url = “http://xx.xx.xx.xx/YamahaExtendedControl/v1/dist/startDistribution?num=0
var contenttype = “application/json”
var POSTrequest ={“group_id”:“6315c19889f14ac78ce799b77b5eca9f”,“type”:“add”,“zone”:“main”,“client_list”:[“xx.xx.xx.xx”]}’
result = sendHttpGetRequest(url, contenttype, POSTrequest)

but that doesnt seem to work. i get an {“response_code”:4} as result. ( supposed to be 0)

Then i created a script with crul command,

curl -s -d ‘{“group_id”:“6315c19889f14ac78ce799b77b5eca9f”,“type”:“add”,“zone”:“main”,“client_list”:[“xx.xx.xx.xx”]}’ -H ‘Content-Type: application/json’ -X GET ‘http://xx.xxx.xx.xx/YamahaExtendedControl/v1/dist/startDistribution?num=0

and i call the script in a rule with

executeCommandLine(" /etc/openhab2/SHscripts/MusiccastON.sh",60000)
wich results in:

2020-03-23 20:23:35.690 [WARN ] [lipse.smarthome.io.net.exec.ExecUtil] - Execution failed (Exit value: -559038737. Caused by java.io.IOException: Cannot run program “/etc/openhab2/SHscripts/MusiccastON.sh” (in directory “.”): error=2, No such file or directory)

If i run the sh script from the command line it works awesome.
Is it a user right issue? is it trying to run as user openab and it cant execute curl?
what am i missing?

Have you tried the 1.x http Action?

Looks like it. Make sure the openhab user has permissions to execute the script. This should do…

sudo chown openhab:openhab /etc/openhab2/SHscripts/MusiccastON.sh
sudo chmod u+rx /etc/openhab2/SHscripts/MusiccastON.sh

First, if you’re trying to send JSON, this isn’t going to work, as it isn’t JSON. Perhaps there’s a copy/paste error here in the forum and your actual code is fine, but you need to verify.

Second, it looks like you’re trying to execute a POST, but calling GET instead. You perhaps should be calling sendHttpPostRequest ?

2 Likes

Thanks. Yes the goal is a Get request, but i used the variable from ‘POSTrequest’

you are right I’m missing a piece here, sorry.

var url = “http://xx.xx.xx.xx/YamahaExtendedControl/v1/dist/startDistribution?num=0
var contenttype = “application/json”
var POSTrequest = ‘{“group_id”:“6315c19889f14ac78ce799b77b5eca9f”,“type”:“add”,“zone”:“main”,“client_list”:[“xx.xx.xx.xx”]}’
result = sendHttpGetRequest(url, contenttype, POSTrequest)

I think that i figured it out…
I added sh in the executeCommandLine

executeCommandLine(“sh /etc/openhab2/SHscripts/MusiccastON.sh”,60000)

and now it works…