100% new to this so I’d appreciate any guidance. Here’s the idea. I have a device at 192.168.2.2:80 that can be controlled by “GET” requests. When I flip my switch on I want it to send /index.php?command=start
I have been reading the developers guide and have no idea what I am doing wrong. It doesn’t explicitly say it, but from their example, it looks like the ip/port needs to be presented to HubAction as HEX. It also doesn’t explicitly state where I should be executing the code to convert to HEX.
Currently, when I flip the switch on and off, I get no requests to my internal server.
[CODE]
metadata {
definition (name: “On/Off Button Tile”, namespace: “smartthings”, author: “SmartThings”) {
capability “Switch”
}
// simulator metadata
simulator {
}
// UI tile definitions
tiles {
standardTile("button", "device.switch", width: 2, height: 2, canChangeIcon: true) {
state "off", label: 'Off', action: "switch.on", icon: "st.switches.switch.off", backgroundColor: "#ffffff", nextState: "on"
state "on", label: 'On', action: "switch.off", icon: "st.switches.switch.on", backgroundColor: "#79b821", nextState: "off"
}
main "button"
details "button"
}
}
def parse(String description) {
}
// gets the address of the device
private getHostAddress() {
def ip = getDataValue(“192.168.2.2”)
def port = getDataValue(“80”)
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)
}
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(".")
}
def on() {
sendEvent(name: “switch”, value: “on”)
def result = new physicalgraph.device.HubAction(
method: “GET”,
path: “/index.php?command=run”,
headers: [
HOST: getHostAddress()
]
)
return result
}
def off() {
sendEvent(name: “switch”, value: “off”)
def result = new physicalgraph.device.HubAction(
method: “GET”,
path: “/index.php?command=halt”,
headers: [
HOST: getHostAddress()
]
)
return result
}
[/CODE]