Help getting started with local IP devices with the API


(Tim Gray) #1

I have a Dlink camera that I can easily enable or disable motion detection with a simple URL. The URL is not accessible from outside the home network just like my SONOS speakers. So I am sure that I can get this working but for some reason I just cant get things to connect.

How can I from the API connect to an inside network address? are there any tutorials on how to do this?

This is how you talk to the camera…

def api(method, args = [], success = {}) {
def methods = [
“set_motion”: [uri: “http://${username}:${password}@${ip}:${port}/motion.cgi?${args}&ConfigReboot=No&user=${username}&pwd=${password}”, type: “get”],
“get_params”: [uri: “http://${username}:${password}@${ip}:${port}/motion.cgi?ConfigReboot=No&user=${username}&pwd=${password}”, type: “get”]
]


(llcanada) #2

In order to use it outside your home network is to get you public IP address.

you can get it from here.

http://www.whatsmyip.org


(Tim Gray) #3

I dont want to use it outside my home IP. I want to use it inside my home IP just like how Sonos driver works with smartthings.


(sidjohn1) #4

Docs:
http://docs.smartthings.com/en/latest/cloud-and-lan-connected-device-types-developers-guide/building-lan-connected-device-types/index.html


(Tim Gray) #5

I was hoping I did not have to use that autodiscover function. I need to see what I can find that the cameras will respond with that I can use to identify them.


(sidjohn1) #6

You don’t have to use auto discover, you can have the user input the IP address. Use the search button to search for foscam or Roomba to find examples.


(Patrick Stuart [@pstuart]) #7

How about my code here:

Already works with dlink cameras. Feel free to fork and do what you need.


(Todd Wackford) #8

Link was stale. Here it is now:
Updated link Address


(Patrick Stuart [@pstuart]) #9

I had just fixed it prior to this. Should work in post.


(Tony Gutierrez) #10

I still feel like this method is way too async to be very useful. It is very hard to match the response being parsed to the initial call.


(Tony Gutierrez) #11

For example, what if you have two buttons, each executing a chain of 2 or more local http calls. Each http call requires data from the previous call response.

The user mashes button one and it starts firing the local calls, each one being handled by parse(). In the middle the user mashes button 2, and it starts sending things to parse(). All the sudden in parse() you have no idea what response you are getting back, and what should happen next.

We need something synchronous for local calls, just like httpPostJson is for external calls!
@twack @pstuart


(sidjohn1) #12

Do you have a device that you can’t get working or that you currently have this issue with our is this pure speculation with out any experience? It sounds like you are making up issues that don’t exist.


(Tony Gutierrez) #13

Your interpretation is wrong. The issue still exists despite your disbelief. Code it if you think you know better.


(sidjohn1) #14

What’s the device?
20 charters


(Tony Gutierrez) #15

Recreate this in a device type using a local ip. Also it should not be able to be interrupted by another function using calls to the same ip. Good luck!

httpPostJson(uri: host + ':' + port, path: '/json',  body: ["cmd":"login"]) { response ->
        //log.debug response.data

        if (response.data.result == "fail")
        {
            def session = response.data.session
            def hash = username + ":" + response.data.session + ":" + password
            hash = hash.encodeAsMD5()

           httpPostJson(uri: host + ':' + port, path: '/json',  body: ["cmd":"login","session":session,"response":hash]) { response2 ->
                if (response2.data.result == "success") {
                    def BIprofileNames = response2.data.data.profiles;
                    //log.debug response2.data
                    httpPostJson(uri: host + ':' + port, path: '/json',  body: ["cmd":"status","session":session]) { response3 ->
                        //log.debug response3.data
                        if (response3.data.result == "success"){
                            if (response3.data.data.profile != profile){
                                httpPostJson(uri: host + ':' + port, path: '/json',  body: ["cmd":"status","profile":profile,"session":session]) { response4 ->
                                    //log.debug response4.data
                                    if (response4.data.result == "success") {
                                        if (response4.data.data.profile.toInteger() == profile.toInteger()) {
                                            sendNotificationEvent("I set Blue Iris to profile ${profileName(BIprofileNames,profile)}!")
                                        } else {
                                            sendNotificationEvent("Hmmm...Blue Iris ended up on profile ${profileName(BIprofileNames,response4.data.data.profile)}? I tried ${profileName(BIprofileNames,profile)}. Check your user permissions.");
                                        }
                                    } else {sendNotificationEvent(errorMsg)}
                                }
                            } else {sendNotificationEvent("Blue Iris is already at profile ${profileName(BIprofileNames,profile)}.")}
                        } else {sendNotificationEvent(errorMsg)}
                    }
                } else {sendNotificationEvent(errorMsg)}
            }
        } else {sendNotificationEvent(errorMsg)}
    }

(Patrick Stuart [@pstuart]) #16

Syncronous local hubaction calls have been asked for a long time. Don’t hold your breath.

What you want is sockets based connectivity and that is not going to happen any time soon.

If you can fake it, or cheat it, good luck. The response better be HTML or JSON/XML any variation from this and it is lost.

These are the limitations, They have been limits since the beginning, and despite promises it will be better, I don’t see it improving anytime soon.

Best option is to write an app to act as middleware and translate between ST and the device.


(sidjohn1) #17

Thx for the function… I think… it doesn’t tell me what device this is other than blue iris. If you want help and your ready to be serious about it, then let me know. Until then i have better things to do with my time.


(Tony Gutierrez) #18

It seems that you can use the normal commands (httpPost, httpGet) in a device type in a synchronous manner, but local ips are blacklisted. So close, yet so far away.

The whole hubaction/parse pattern seems a really bizzare choice…as if they are trying to fit http traffic fit into a zigbee/zwave pattern.


(Tony Gutierrez) #19

I think you should be able to recognize the issue from my comments and the code. If you think you know of a strategy, then explain it, otherwise you have just been detracting from the conversation.


(Jody) #20

@sidjohn1 I think his point is that you cannot use httpPostJson against local ip addresses and this function would be precarious to recreate using hubAction.