Http binding post issue

Raspberry Pi 3 / openhabian 1.5 and OH2 2.4 stable.

I am trying to realize a http POST and have read all threads here.
Unfortunately it did not help.
This is my item to activate and deactivate my alarm system (currently by execute commandline and curl).
I don’t use caching this in http.cfg (but tried this before as well)

"Alarmanlage [%s]" <siren> (G_jdbc) {http=">[ON:POST:http://root:xxx@] >[OFF:POST:http://root:xxx@]"}

I have tried also Basic authentication with a generated key.
Furthermore it work with requesting the state of the alarm system:
String Abus_Status "Abus State [%s]" (G_jdbc) {http="<[cache-Abus-Status:20000:REGEX(Mode=(.*))]" }

where http.cfg contains:


The log shows:
2019-08-22 13:08:52.102 [DEBUG] [ab.binding.http.internal.HttpBinding] - Executing url 'http://root:xxx@' via method POST

But it does not work…

Does your mystery alarm system require any content for the POST?
Is there no security or password for this?

You may get more feedback using the HTTP action in a rule, while investigating.

rule "test http"
   testSwitch received command
   var results = sendHttpPostRequest("http://root:xxx@")
   logInfo("httptest", "result " + results.toString)

I think that’ll work, defaulting the content type etc.

curl with the exact same command does the job (user:password@…)
However, I have time out issues every now and then with executeCommandLine curl + timeout period.
So I would like to move as many as possible to the http binding.

Would this help as well in this regard (timeout)?

I will try your suggestion.

No idea, it’s a diagnostic move. But you can add timeout to your parameters and handle it in a rule. I belive the return is null for a timeout.

If you were getting timeouts using curl, they’ll still happen with an Item/binding setup but be hidden from you.

Thanks, let’s see.

I am concerned about the timeouts because according to other posts, this might lead to cron rules not working anymore.
This is the original issue I face every now and then.

That’s really weird.

This does not work:
var results = sendHttpPostRequest("http://root:password@", 3000)
2019-08-22 15:30:23.008 [INFO ] [ipse.smarthome.model.script.httptest] - result ERROR

but this does switch the state correctly:
executeCommandLine("curl -s http://root:password@", 3000)

That’s moving forward, a message :smiley:

You may need to url encode the @ as %40 and then escape the % i.e. use %%40

Hmm, no, other people use @ as it is.
See also

You might need to default the POST content to get your timeout parameter “in teh right place”

sendHttpPostRequest("http://root:password@", , , 3000)

I am not sure what you mean, but this does not work (rule not loaded):

2019-08-22 16:11:24.468 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model 'abus.rules' has errors, therefore ignoring it: [36,108]: no viable alternative at input ','
[36,110]: no viable alternative at input ','
[46,106]: no viable alternative at input ','
[46,108]: no viable alternative at input ','

That curl operation sends a GET request, not POST, are you sure you need to use POST?

1 Like

Really? :thinking:
I will try the GET then instead.

Thanks - I will let you know.


Correct!! I’ve imported your curl command into my tool called “HTTP Shortcuts” (available in Google Play Store) and it told me it’s a GET.

With this tool you can test all kind of http operations (GET, PUT, POST), also import from or export to curl is possible.

Excellent - thanks for your help.

That di the trick!
sendHttpGetRequest("http://root:... works

Again, thanks a lot for this hint.

1 Like