HTTP Get not working in RM because camera added security

I have an http command that works in my browser to change a camera position.

I created a rule in RM so a door contact is open them action is to send this HTTP command to position the camera. Logs show RM is triggered, but no cam movement.
Any ideas?

You can send from terminal and it works?

Click on the rule, click on the gear icon and click on events. Just double check that the event is being sent correctly to the rule. You want to see something like this:

|RM||Tool Closet is now True|2019-03-25 04:03:11.677 PM EDT|

|RM||Zone 024 - Tool Closet Door contact open|2019-03-25 04:03:11.534 PM EDT|

You can also try Dan's HTTP switch to troubleshoot.

 *  HTTP Momentary Switch
 *  Copyright 2018 Daniel Ogorchock
 *  Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
 *  in compliance with the License. You may obtain a copy of the License at:
 *  Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
 *  on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
 *  for the specific language governing permissions and limitations under the License.
 *  Change History:
 *    Date        Who            What
 *    ----        ---            ----
 *    2018-02-18  Dan Ogorchock  Original Creation
metadata {
	definition (name: "HTTP Momentary Switch", namespace: "ogiewon", author: "Dan Ogorchock") {
        capability "Switch"
        capability "Momentary"

	preferences {
		input(name: "deviceIP", type: "string", title:"Device IP Address", description: "Enter IP Address of your HTTP server", required: true, displayDuringSetup: true)
		input(name: "devicePort", type: "string", title:"Device Port", description: "Enter Port of your HTTP server (defaults to 80)", defaultValue: "80", required: false, displayDuringSetup: true)
		input(name: "devicePath", type: "string", title:"URL Path", description: "Rest of the URL, include forward slash.", displayDuringSetup: true)
		input(name: "deviceMethod", type: "enum", title: "POST, GET, or PUT", options: ["POST","GET","PUT"], defaultValue: "POST", required: true, displayDuringSetup: true)

def parse(String description) {

def push() {
    //toggle the switch to generate events for anything that is subscribed
    sendEvent(name: "switch", value: "on", isStateChange: true)
    runIn(1, toggleOff)
    //sendEvent(name: "switch", value: "off", isStateChange: true)
    runCmd(devicePath, deviceMethod)

def toggleOff() {
    sendEvent(name: "switch", value: "off", isStateChange: true)

def on() {

def off() {

def runCmd(String varCommand, String method) {
	def localDevicePort = (devicePort==null) ? "80" : devicePort
	def path = varCommand 
	def body = "" 
	def headers = [:] 
    headers.put("HOST", "${deviceIP}:${localDevicePort}")
	headers.put("Content-Type", "application/x-www-form-urlencoded")

	try {
		def hubAction = new hubitat.device.HubAction(
			method: method,
			path: path,
			body: body,
			headers: headers
		log.debug hubAction
		return hubAction
	catch (Exception e) {
        log.debug "runCmd hit exception ${e} on ${hubAction}"

As I said, The rule is fine.

RM ENI cam to Stair Door is now True 2019-03-26 03:42:56.853 PM HKT
RM Outside Door contact open 2019-03-26 03:42:56.716 PM HKT

But the http command is not moving the camera, whereas in the browser the command works fine.

Permission needed

This command works in browser- no cam login required.
Do you mean some other permission?

What headers are you sending in your get?

On one of my custom devices I had to properly define "contentType" and "requestContentType" for an "asynchttpPost" in order to get it to work... maybe there is some more info you need to send along?

Yeah it was Camera login, I meant

Like I said, the http call works fine using a browser. My cam moves to a preset just fine.
If you are talking about something else HE needs, I have no clue what that would be. I assumed HE simply pushes the http call onto the network. This stuff used to work fine with my Vera controller. What would HE be doing differently?

Yes and that's because the browser sends certain additional information with it's http get request. Stuff like "USER-AGENT" etc.. what I'm suggesting is there is a difference between what the browser is sending and what your call is - maybe it's missing some of this information that the cam's webserver expects.

Have you tried using the postman utility? You could independently confirm the http call and isolate the issue to HE.

Did you try it from a virtual switch device page? I had issues with my HTTP Get so I removed the try response part of code since I don't think my HTTP was providing a response. I will try and go back and figure out the right way later but for now it is working for me.

def on() {
    if (logEnable) log.debug "Sending on GET request to [${settings.onURI}]"
sendEvent(name: "switch", value: "on", isStateChange: true)
//    try {
        httpGet(settings.onURI){ resp ->
//            if (resp.success) {
//                sendEvent(name: "switch", value: "on", isStateChange: true)
//            }
            if (logEnable)
                if ( log.debug "${}"
//    } catch (Exception e) {
//        log.warn "Call to on failed: ${e.message}"
//    }

I tried Dans test switch and it logged

2019-03-27 07:35:21.720 am [debug](http://My HE/device/edit/4500)GET /cgi-bin/ptz.cgi?action=start&channel=0&code=GotoPreset&arg1=0&arg2=1&arg3=0
Accept: /
User-Agent: Linux UPnP/1.0 Hubitat
HOST: Mycam IP and Port
Content-Type: application/x-www-form-urlencoded
Content-Length: 0

[dev:4500](http://My HE/logs#dev4500)2019-03-27 07:33:58.891 am [debug](http://My HE/device/edit/4500)GET /cgi-bin/ptz.cgi?action=start&channel=0&code=GotoPreset&arg1=0&arg2=1&arg3=0
HTTP/1.1 Accept: /
User-Agent: Linux UPnP/1.0 Hubitat
HOST: Mycam IP and Port
Content-Type: application/x-www-form-urlencoded
Content-Length: 0

RM rule set to send....
http://Mycam IP and Port/cgi-bin/ptz.cgi?action=start&channel=0&code=GotoPreset&arg1=0&arg2=1&arg3=0

RM rule logs............
app:13702019-03-27 07:35:38.541 am infoENI cam to Stair Dr: Outside Door contact closed

app:13702019-03-27 07:35:21.757 am infoENI cam to Stair Dr is now True

app:13702019-03-27 07:35:21.676 am info --> Outside Door open [true]

app:13702019-03-27 07:35:21.642 am infoENI cam to Stair Dr: Outside Door contact open

It looks to me like RM is sending correctly. Correct me if I'm wrong.

Sorry, I don't know how to use this app.

So try setting the content type to: "text/html" in your parameters in the http get call maybe?

"application/x-www-form-urlencoded" is usually associated with form data..

It's not all that hard to figure out postman, you don't need to sign up or anything and it will let you do a get/post/put with whatever parameters you need. Very handy and worth learning if you are going to be doing http/REST call development etc.

I appreciate all your help and suggestions. I did figure out what is wrong. Auth fails. and the reason is that FW change in the cam.
Some bonehead dev with Amcrest has decided that it will lock out any ability to auto login "for security". The

Before my http code worked fine. Today it shows me a login screen first. So my cam must have been already logged in before and my code worked.

So heads up! Amcrest cams are amazing. BUT no more http control! Amcrest said they will not change this decision.

1 Like

That sucks to hear!! You might be able to automate with something like Headless Chrome and puppeteer or selenium but it would take some messing around with..

Thanks for the suggest but I'm done screwing with this. I put in a ticket to Amcrest and see what they say but I am not expecting anything.

1 Like

There isn't a network ACL in place is there? Both my LaView cameras and iSpy server allow me to setup ACLs for what devices can access them . . . (trying to think of anything)

I double-checked mine just to make sure it wasn't something in one of the recent releases that broke the http get from Rule Machine . . . mine are still working fine.