HTTP Put issues

Hi - I am trying to create a driver to open/command a door attached to a HikVision Facial Recognition device.
I read a couple of the discussions. My issue is similar to Tom's in this post.

How to send a http PUT with xml data - #13 by TomS

The authentication instead of using digest, apparently still able to use the user:pwd@ip format still works. (for now).
I can send the command just fine via PostMan, and the door opens, but something in Hubitat is not sending the correct headers or body to the Hikvision device.

I sent the PUT also to webhook.site to see what I was sending in the request.
Everything looks OK (apparently), and I don't get any errors on the webhook.site either, I receive a 200 reponse.

But when trying to run from Hubitat - I keep getting this error:
Tried changing headers, parameters, but with no luck yet.

This is my code:

/////// OpenDoor ///////////
def OpenDoor(){

def xmlCode = "<RemoteControlDoor version='2.0' xmlns='http://www.isapi.org/ver20/XMLSchema'><cmd>open</cmd></RemoteControlDoor>"
def parameterMap = [  
                    uri: "http://" + state.deviceuser + ":" + state.devicepwd + "@" + state.currentip + "/ISAPI/AccessControl/RemoteControl/door/1",
                    requestContentType: "application/xml",
                    contentType:"application/xml",
                    headers: ['Content-Type': 'application/xml'],
                    body: xmlCode
                   ]

log.debug parameterMap  //View the construction in log
    
    try { httpPut(parameterMap,parseResponse) 
    parseResponse = { response ->  
        log.info response.getStatus()          
                    }
        }            
    catch (e) {
        log.debug "Response : ${e.message}" 
              }       

}

The LOG shows:

If we add the [ ] in the code to the body section, Then:

@mike.maxwell

Just a guess but I noticed in your Postman code that the xml contains double quotes around the values for version and xmlns, whereas in your code, you are using single quotes. Try replacing those with double quotes by using the escape character. For example,

version=\"2.0\" xmlns=\"http....\">.

HI @TomS - your observation did the trick! And even more, I removed the whole version='2.0' xmlns='http://www.isapi.org/ver20/XMLSchema' declaration, and worked the same too. But the definition of the body that contained the xml, worked without the [ ] .

Also - there was an error on the closure definition for the httpput which I fixed.
The complete code below for the function , and will link the code for the driver for anyone looking for HikVision door control to use it and improve anything if necessary !

/////// OpenDoor ///////////
def OpenDoor(){
def xmlCode = "open"
def parameterMap = [
uri: "http://" + state.deviceuser + ":" + state.devicepwd + "@" + state.currentip + "/ISAPI/AccessControl/RemoteControl/door/1",
requestContentType: "application/xml",
contentType:"application/xml",
headers: ['Content-Type': 'application/xml'],
body: xmlCode
]
log.debug parameterMap //View the construction in log

Closure $parseResponse = { response ->
     log.debug response.data
     if (response.status == 200) {
             sendEvent(name: "switch", value: "on", isStateChange: true)
             sendEvent(name: "Door", value: "Open", isStateChange: true)            
     }         
} 
    
    try { httpPut(parameterMap,$parseResponse) 
    
        }            
    catch (e) {
        log.debug "Error Response : ${e.message}" 
              } 

pauseExecution(5000)  //time for door autoclose (must match the settings in the Hikvision config for autoclose. Time in ms)   
off() // turn off-close door after time

}

Hi everyone, to finish the topic.
I added the Hikvision Door controller driver to HPM.

Also for manual installation available in github:

Any comments or updates, feel free!
Thanks again @TomS and @marktheknife !

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.