I know this is an old thread but I found some tidbits here helpful when I was trying to get a HubAction call to call the parse()
function of my Device Handler. As many have suggested, the deviceNetworkId
needs to be set to either hexIp:hexPort
or the MAC address.
Through some experimentation, I’ve found that it works with either, but SmartThings is pretty particular about the formatting of the deviceNetworkId. The hexIp portion must be 8 characters and the port portion 4 characters, in all uppercase. If you choose to use the MAC address, it also must be in all uppercase and remove the colons. I’ve written a little groovy function to convert an IP:PORT to the correctly formatted hexIP:hexPort (and vice-versa):
// accepts a IP:PORT string and converts it to a hex identifier
// for setting the SmartThings deviceNetworkId
private String ipToHex(String ip) {
def parts = ip.tokenize(':')
def address = parts[0]
def port = parts[1]
def octets = address.tokenize('.')
def hex = ""
octets.each {
hex = hex + Integer.toHexString(it as Integer).toUpperCase()
}
hex = hex + ":" + Integer.toHexString(port as Integer).toUpperCase().padLeft(4,'0')
return hex
}
private Integer hexToInt(String hex) {
return Integer.parseInt(hex,16)
}
// accepts a hex formatted deviceNetworkId and converts it to an IP:PORT string
private String hexToIp(String hex) {
def address = [hexToInt(hex[0..1]), hexToInt(hex[2..3]), hexToInt(hex[4..5]), hexToInt(hex[6..7])].join(".")
def port = hexToInt(hex[9..12])
return address + ":" + port
}
This documentation was also helpful in figuring this out, but I wish it was more specific about the requirements for deviceNetworkId.