Please fix setting device.deviceNetworkId from code

So I spent the entire day trying to figure out why my camera DTH would not fetch a picture. Just now discovered that the network ID indeed needs to be hex uppercase ip + port, but I was setting it from code which does not work, not even when I move it out of my updated() method. Only when I set it manually through the web interface I’m able to retrieve a picture…

First, the DNI does not have to be the hex ip/port. As a matter of fact, that is far less common than using the MAC less colons as the DNI in new code. DNI is set by the Service Manager (SM) (or SmartApp SA)) on installation. The SM then tracks for IP address changes and sends changes to the device (through the DTH).

Questions: Are you writing this DTH? If so, are you writing at this time a SM or SA?

Reason, I have done several DTHs that did not have SM or SA. I uses preferences to define the IP address, do not use hex format address/port, and use any unique string as the DNI. I also use static (reserved) addresses on my router so I do not have to change the IP.

I’m writing a Smartapp for netatmo presence and welcome camera’s that spawns device childs. From the API I get the mac adresses that I use as ID for the camera’s. At the time of creating the devices their network ID is set as the mac address but I can’t get the hubaction for images to work on anything other than hex ip. So I created a preference to set the ip address and upon saving that I used the update method to set the device network id. Which does not seem to work no matter what I try…

Try something like the below in your code. It may work for what you are attempting.

preferences {
   input("deviceIP", "text", title: "Device IP", required: true, displayDuringSetup: true)
   input("devicePort", "text", title: "Device Port", required: true, displayDuringSetup: true)
}
private sendCmd(command, action){
	def cmdStr = new physicalgraph.device.HubAction([
		method: "GET",
		path: command,
		headers: [
			HOST: getHostAddress()
		]],
		null,
		[callback: action]
	)
	sendHubCommand(cmdStr)
}

private getHostAddress() {
	def ip = convertHexToIP(deviceIP)
	def port = convertHexToInt(devicePort)
	return ip + ":" + port
}
private Integer convertHexToInt(hex) {
	Integer.parseInt(hex,16)
}
private String convertHexToIP(hex) {
[convertHexToInt(hex[0..1]),convertHexToInt(hex[2..3]),convertHexToInt(hex[4..5]),convertHexToInt(hex[6..7])].join(".")
}

Thanks… I finally got it to work using mac address, which I can set during the child device camera creation to the network id. Progress :smile:

1 Like