Telling the difference between different response from the same remote device

I am writing a SmartApp to expose the camera in my Swann NVR. It supports 5 cameras and you can take snapshots with an HTTP request which returns an image as a response. I implemented a SmartApp which will create a device for each camera.

Each camera has a take() action which will make the HTTP request to get the snapshot from the camera. My understanding (and proven by experiments) is I can’t get a response from a LAN action (to request the snapshot) unless I set the deviceNetworkId for the device to the address and port (in hex of course) of the remote device. The problem arises in that I want to have separate devices, one for each camera, so snapshots can be separated. This means I need to create 5 different devices, all with the same address – which of course doesn’t work.

I thought I could just implement the snapshot functionality in the SmartApp and have the devices call the SmartApp to make the call and get the response in the location handler. The problem is I don’t know which device a snapshot is for from the incoming request. The response doesn’t appear to have the request path that was made and the request Id that is present is opaque.

So three questions:

  1. When you get an incoming message in your locationHandler is there any way to determine the path or other data about the request that was made in order to get this response?

  2. Is there any way to allow multiple device instances to share the same network Id?

  3. Any other suggestions on approach? All the examples I have found have cameras which each have their own IP Address.

I do not want to track a state value for which camera is currently taking a picture if I can help it – which is the only way I can think of working around this problem.

For those who come across this trying to solve the same problem…

I ended up enabling the smartapp to be the one to make the REST calls to initiate the picture and then passed the result to the devicetype to write it out. I tracked which device was currently taking a picture in the SmartApp. This does mean that I can only be snagging one picture at a time but it was the only option.

Are you planning on making this app public?

Happy to do so. I need to clean it up a bit first – I’ll add that to my todo list.

In the meantime, if you are interested, or anyone else checking out this thread is interested and up to experimenting in the meantime here are direct links:

The SmartApp:

The Device Type: