Help getting started with local IP devices with the API

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”]
]

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

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.

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

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.

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.

How about my code here:

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

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

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

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.

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

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.

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

What’s the device?
20 charters

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)}
    }

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.

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.

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.

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.

1 Like

@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.