Basic auth format for http binding

I am trying to change settings in my camera using its web api. I know the api call is correct however I am having trouble doing the authentication. I have tried several formats and done enough googling to feel ok posting here.

Here is the api call with a phony username (admin) and password (qwerty).
http://admin:qwerty@10.9.8.252/cgi-bin/configManager.cgi?action=setConfig&MotionDetect[0].Enable=false

The documentation for the api says it supports both basic and digest auth. When using basic auth it requires the username and password to be base64 encoded.

Any suggestions?

I have wondered if this will have to be a script like the examples: https://github.com/openhab/openhab/wiki/Samples-REST

Thanks,
Kirk

Have you tried encoding the username and password in Base 64? There is an online encoder/decoder here.

I did however it didn’t like the syntax.

http://YWRtaW46cXdlcnR5@10.9.8.252/cgi-bin/configManager.cgi?action=setConfig&MotionDetect[0].Enable=false

So it worked but you didn’t like how the url looked?

If that is the case I think you will need to figure out some other way to communicate with the device. I think openHAB only supports basic authentication and per your posting above the basic authentication requires base 64 encoding.

I dont know what was different last night but I couldnt get the formated url to work in wget or a browser but now it is working in the browser using basic auth. However it is still not working in the binding.

Switch OfficeCameraMotion “Office Camera Motion” { http=">[ON:POST:http://admin:qwerty@10.9.8.252/cgi-bin/configManager.cgi?action=setConfig&MotionDetect[0].Enable=true] >[OFF:POST:http://admin:qwerty@10.9.8.252/cgi-bin/configManager.cgi?action=setConfig&MotionDetect[0].Enable=false]" }

I have enabled debugging for the http binding but it doesnt give me any additional information.

Do I need to escape any of those characters?

Even setting the binding to trace doesnt produce any logs for the http binding.

You should see something, even if it is just one log statement near the start of openHAB saying the HTTP binding is loaded and running. If you don’t see that then the binding itself may not be installed. Verify that the HTTP binding’s jar file is in your addons folder.

Well I do see the http binding starting but thats it.

I think the problem might be the URL. It doesnt work in curl. It will work in the browser though

http://10.9.8.252/cgi-bin/configManager.cgi?action=setConfig&MotionDetect[0].Enable=false

Curl doesn’t like the brackets or & symbol. I have tried replacing them with the ascii couter parts however that hasnt worked either.

Thoughts?

Thanks for the help.
Kirk

By replacing them with the ascii counter parts do you mean the escaped URL encodings:

&    %26
[     %5B
]     %5D

for

http://10.9.8.252/cgi-bin/configManager.cgi?action=setConfig%26MotionDetect[0].Enable=false

Your browser will do this for you but curl and openHAB will not.

Ok I finally found a curl command that works. As such I have switched from trying to do an http binding to an exec binding. I kept trying different options and this finally worked

curl --basic --user admin:1qaz3edc5tgb7ujm http://10.9.8.252/cgi-bin/configManager.cgi?action=setConfig&MotionDetect\[0\].Enable=true

So then I tried several variations of:

Switch OfficeCameraMotion “Office Camera Motion” { exec=
“ON:‘curl --basic --user admin:qwerty http://10.9.8.252/cgi-bin/configManager.cgi?action=setConfig&MotionDetect\[0\].Enable=true’,
OFF:‘curl --basic --user admin:qwerty http://10.9.8.252/cgi-bin/configManager.cgi?action=setConfig&MotionDetect\[0\].Enable=false’” }

Error: 23:17:23.553 ERROR o.o.m.i.i.GenericItemProvider[:354]- Binding configuration of type ‘exec’ of item âOfficeCameraMotionâ could not be parsed correctly.
java.lang.NullPointerException: null
at java.util.regex.Matcher.getTextLength(Matcher.java:1234)
at java.util.regex.Matcher.reset(Matcher.java:308)
at java.util.regex.Matcher.(Matcher.java:228)
at java.util.regex.Pattern.matcher(Pattern.java:1088)
at org.openhab.binding.exec.internal.ExecGenericBindingProvider.processBindingConfiguration(ExecGenericBindingProvider.java:100)

Am I going to have to escape every special symbol again?

curl\ --basic\ --user\ admin:1qaz3edc5tgb7ujm\ http://10.9.8.252/cgi-bin/configManager.cgi?action=setConfig\&MotionDetect\\[0\\].Enable=true

Thanks
Kirk

Probably. It is the first thing I would try.

If that doesn’t work, put your curl into a script and execute it that way.

Also, per the doc on the wiki for the exec binding, use "@@"for your spaces instead of "\ " or " ".

I feel like I had to go the round about way of doing it three times.
I ended up making a bash script with the one line to run the curl script, which was called by the exec binding. I had expected to just be able to use the http binding. I guess things are rarely as easy as we expect them to be.

Thanks for all the help guys.