How to send http request?


(Rich Koshak) #15

That’s the point. By using the ‘’ you are telling the openHAB software not to interpret those characters as special and pass them through unchanged. You should not see the ‘’.


(Gerardo Palacios) #16

Right, that makes sense. In that case I did edit the items fie accordingly, unfortunately, the result is the same :frowning: .


(Rich Koshak) #17

Try to make it work with curl from the command line. There might be something wrong with the URL over all, a small typo or something.


(Kerwin Lovell) #18

It looks like the trailing quote mark is missing. Is that not needed?

{ http=">[ON:POST: URL] >[OFF:POST: URL ]"}


(Rich Koshak) #19

Good eye. Indeed the closing quote is required.


(Kerwin Lovell) #20

HA! Based on other things you’ve help me with my eye is only good when it’s not my config.


(Gerardo Palacios) #21

@rlkoshak @sc1982

Okay So I’m getting closer. I got it to work using curl!

curl ‘http://192.168.86.120:8083/ZWaveAPI/Run/devices[7].instances[0].commandClasses[0x20].Set(0)’ -u admin

Or

curl -g ’ curl ‘http://192.168.86.120:8083/ZWaveAPI/Run/devices[7].instances[0].commandClasses[0x20].Set(0)’ -u admin

Now… I face the next hurdle… Looks like I can only send this command if I include the -u parameter. Is there a way I can pass two additional parameters in OH in the items file in order to send the request?


(Rich Koshak) #22

The -u option is passing the username/password for basic Auth on the Web page. You can do the same thing by embedding it as part of the URL itself

Http://user:password@url

Or in your case since it doesn’t appear to require a password you omit the :

Http://admin@192.168.86.120:8083/


(Gerardo Palacios) #23

@rlkoshak

I guess I’m still doing something wrong… I was able to make it work using the EXEC binding and Curl… but for some reason, below will not work.

The only problem I have now is that I am unable to receive status updates. I think I found something online that uses MQTT to speak to OpenHab and the use a rule to get a status update… But that’s another monster in and of itself…

I have tried escaping both [] and (), as well as escaping just [] and just (). Nothing. I keep getting the same log failure…

21:43:05.527 [WARN ] [.internal.HttpGenericBindingProvider] - bindingConfig is NULL (item=Popcorn (Type=SwitchItem, State=Uninitialized)) -> process bindingConfig aborted!
.

Switch Popcorn “Popcorn Machine” { http=">[ON:POST:http://admin:PASSWORD@192.168.86.120:8083/ZWaveAPI/Run/devices[7].instances[0].commandClasses[0x20].Set(255)] >[OFF:POST:'http://admin:PASSWORD@192.168.86.120:8083/ZWaveAPI/Run/devices[7].instances[0].commandClasses[0x20].Set(0) ]" }


(Rich Koshak) #24

At this point you need to decide is getting this working with the HTTP binding really something that you want to spend your time and effort getting it to work, or live with the working solution through the Exec binding and move on to solving more interesting problems. I would go with what works and move on.

By escaping, do you mean you added the ‘’ before each or you used the URL encoded version of the character?


(Gerardo Palacios) #25

I think you’re right, I’m just gonna use the EXEC binding to make it work. I just need to figure a way to get feedback. Otherwise, this is just a switch on my phone.

Thank you so much for taking the time to help me through this.

And I used “” before each [].


(Rich Koshak) #26

If you wanted to try one more test you can try replacing the brackets and parens with the URL encoded character.


(Gerardo Palacios) #27

@rlkoshak

I attempted the URL encoded, no luck. Either way I think I’ll consider this closed, but unsolved. I was able to get it to work using the EXEC binding (curl) and additionally ended up switching it over to a Vera and using the MiOS binding which turned out to be much better than expected!

Thank you so much for helping me. I’ve gone through a ton of these forums and your name continually pops up. Thank you for helping out newbs like me!

I actually opened up a new topic. If you find the time, I’d appreciate it if you could take a look!


(Lovro Šverko) #28

Hello,
this worked for me. It is much easier to setup NodeMCU with HTTP request than with MQTT channels.
Thanks a lot.


[SOLVED] Switch command using http binding not working
(Eduardo Alexandre) #29

Mikey, could you share the Item/thing/Sitemap config for the pan/tilt camera control? I’ve been struggling with it.

Thanks!


(Mc Noisomeworth) #30

You need to make a rule to do it.

My rule for handling positions is looking like this

rule "Garage cam position"
when
	Item GarageCamPosition received command
then
	sendHttpGetRequest("http://192.168.1.144/decoder_control.cgi?command=" + receivedCommand.toString)
end

(Mahmoud Mandour) #31

how do you do it in openhab, i cant link it


(Erik Severin) #32

I don’t succeed controlling my player by using http-command, based on TRYAK - Sonoé iEast - API Manual by AndersFluur. I have tried Item Configuration and through rules with sendHttpGetRequest and with executeCommandLine, neither works for me.

This is my Item:
Switch Roxcore_Control “Control” (Office) { http=">[ON:GET:http://192.168.0.121/httpapi.asp?command=setPlayerCmd:play:http://xxxx.m3u] >[OFF:GET:http://192.168.0.121/httpapi.asp?command=setPlayerCmd:stop:http://xxxx.m3u]" }

The http://xxxx.m3u address is a link to a streeming radio channel. The http-links works fine using a web-browser.

This is my rule:
rule “Roxcore control”
when
Item Roxcore_Control received command
then
logInfo(“roxcore control”, "Command was " + receivedCommand)
if(Roxcore_Control = ON) {
sendHttpGetRequest(“http://192.168.0.121/httpapi.asp?command=setPlayerCmd:play:http://xxxx.m3u”)
}
else if (Roxcore_Control = OFF) {
sendHttpGetRequest(“http://192.168.0.121/httpapi.asp?command=setPlayerCmd:stop:http://xxxx.m3u”)
}
end

Running the rule, I get this error message in the log:
2018-10-10 20:48:13.494 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule ‘Roxcore control’: An error occurred during the script execution: Cannot assign a value in null context.

I am running openHAB 2.2.0 on raspberry Pi 3 B.

Any suggestion on what I am doing wrong would be appreciated?


(Rich Koshak) #33

Please How to use code fences.

I strongly recommend using VSCode to edit .rules files. https://www.openhab.org/docs/configuration/editors.html#openhab-vs-code-extension

You have some very basic syntax errors and one logic problem.

  1. To access the state of an Item you must call .state, as in Roxcore_Control.state
  2. To do a comparison you must use ==. '=` is an assignment.
  3. The logic error is described here

(Erik Severin) #34

Thanks so much, the rule works fine after taking care of 1 and 2 in your answer (thought I picked up these basics after making a number of rules already). Need to remember the other recommendations for the future.