LAN light switch GET request problem

(Anthony Hell) #1

Hi everyone,

i’m trying to create new device type for my LAN light switch. The problem is that SmartHub doesn’t actually send any request to switch REST server.

I’ve created a device based on this device type with device id: 0A000107:0D54 //
and tried with it - no luck. I’ve tried to use virtual device in IDE - no luck.

when I open the uri in browser: it turns on the light
when I open telnet to 3412 and write all lines from logs (in method doRequest) it turns on the light

but with this device type no luck

Could anyone help me with it? I don’t want to forward port and make this REST server available to everyone.

Here’s the code:

metadata {
	definition (name: "Internal Switch", namespace: "narsul", author: "Anthony Peklo") {
		capability "Switch"
		capability "Refresh"

	// simulator metadata
	simulator {

	// UI tile definitions
	tiles {
		standardTile("button", "device.switch", width: 2, height: 2, canChangeIcon: false) {
			state "off", label: 'Off', action: "switch.on", icon: "st.Kids.kid10", backgroundColor: "#ffffff", nextState: "on"
			state "on", label: 'On', action: "", icon: "st.Kids.kid10", backgroundColor: "#79b821", nextState: "off"
		standardTile("refresh", "device.switch", inactiveLabel: false, decoration: "flat") {
			state "default", label:'', action:"refresh.refresh", icon:"st.secondary.refresh"
		main "button"
		details(["button", "refresh"])

def parse(String description) {
	log.debug "Parsing '${description}'"

def on() {
	sendEvent(name: "switch", value: "on")

def off() {
	sendEvent(name: "switch", value: "off")

def doRequest(action) {
	// device.deviceNetworkId = "0A000107:0D54"
	try {
        def hubAction = new physicalgraph.device.HubAction(
            method: 'GET',
            path: "/switch?name=corridorLight&state=${action}",
            headers: [HOST:getHostAddress()]

        log.debug hubAction
    catch (Exception e) {
    	log.debug "Hit Exception $e on $hubAction"

private Integer convertHexToInt(hex) {

private String convertHexToIP(hex) {

private getHostAddress() {
	def parts = device.deviceNetworkId.split(":")
	def ip = convertHexToIP(parts[0])
	def port = convertHexToInt(parts[1])
	return ip + ":" + port

P.S. By the way method ‘parse’ is not bing called too

(trac starr) #2

If i’m not mistaken there is a known bug/issue when using LAN with IPs in the range 10.0.x.x or maybe even any 10.x.x.x. I’m not sure of the link to the post off hand. I think it’s in the hex conversion or something - sorry I can’t remember more.