I’ve been struggling with getting my hub to send out any telnet commands. I’ve looked through dozens of posts in the forums without any luck. I simplified my device handler down to the following code to debug, but I still am not seeing any evidence that it’s sending out the command. I’ve used a packet sniffer on my network which shows nothing is coming from the hub on port 9091 (or 9090 or 9092, other ports I’ve tried changing to). Also, I can telnet to the device (192.168.1.10) from my laptop and that communication shows up in its log while I see nothing from the hub. Any help would be greatly appreciated!
My device handler is:
/**
* TCP test
*/
preferences {
}
metadata {
definition (name: "TCP_test", namespace: "nrblock", author: "Nathan") {
capability "Switch"
}
simulator {
}
tiles {
standardTile("switch", "device.switch", width: 2, height: 2, canChangeIcon: true) {
state "on", label: '${name}', action: "switch.off", icon: "st.switches.switch.on", backgroundColor: "#79b821"
state "off", label: '${name}', action: "switch.on", icon: "st.switches.switch.off", backgroundColor: "#ffffff"
}
}
main "switch"
details(["switch"])
}
// parse events into attributes
def parse(String description) {
log.debug "Parsing '${description}'"
}
// gets the address of the device
private getHostAddress() {
def ip = getDataValue("ip")
def port = getDataValue("port")
if (!ip || !port) {
def parts = device.deviceNetworkId.split(":")
if (parts.length == 2) {
ip = parts[0]
port = parts[1]
} else {
log.warn "Can't figure out ip and port for device: ${device.id}"
}
}
log.debug "Using IP: $ip and port: $port for device: ${device.id}"
return convertHexToIP(ip) + ":" + convertHexToInt(port)
}
// command for one player only
def on() {
//device.deviceNetworkId = getHostAddress()
def hubact = new physicalgraph.device.HubAction("test command\r\n\r\n", physicalgraph.device.Protocol.LAN, "${device.deviceNetworkId}")
hubact
return
}
def off() {
//device.deviceNetworkID = getHostAddress()
def hubact = new physicalgraph.device.HubAction("test command\r\n\r\n", physicalgraph.device.Protocol.LAN, "${device.deviceNetworkId}")
hubact
return
}
private Integer convertHexToInt(hex) {
return Integer.parseInt(hex,16)
}
private String convertHexToIP(hex) {
return [convertHexToInt(hex[0..1]),convertHexToInt(hex[2..3]),convertHexToInt(hex[4..5]),convertHexToInt(hex[6..7])].join(".")
}
The device screen shot is below.