Multiple hubaction commands in one function and parsing the response

few possibilities:

  1. the event is not fired. send it explicitely
  2. the answer is sent back to a wrong instance. For this one, open the live logging and check if you don’t see 2 instances of your device. If not, maybe you can try to change the IP address to another value. There is a bug known as ghost device. I am not sure if this is solved now.
  3. make sure you don’t have the simulator on. Go to the IDE and check the device handler view. there should not be anything in the similator cell

hope it helps

the event is fired. because I get the packet on my router and it responds. I also see the packet back to the ST Hub.

I only have one instance of “Rouer” in live logging.

simulator is not on.

this might be something related to the device ID setting but I set it correctly , “C0A8FE01:0050” for “192.168.254.1:80”

so what else could it be ?

i faced that because the hub was sending the answer to a ghost instance. Try to change the IP address of the device and the networkid

the device is the router. changing its IP is not easy because I have more than 30 devices connected to it.

and if it was a ghost device then how does hubsoapaction work ?

i don’t use hubsoap so i cannot comment. you can search for my post about this hub ghost stuff on the forum. i am on my phone so i cannot be very helpful.

will try to check something once back home but yesterday i thought you said you got the parse called so i am getting confused now.

are you bursting hubactions and only receive the first one or nothing works anymore ?

In my original code I am calling several hubsoapactions and 1 hubaction sequentially.
but for testing purpose , I call only one of them.
I see the packet go to the router and it replies.
but parse is not triggered.
most probably because of some addressing issue.

when I had found this (below) , I had thought that it was the reason. But it is not…

In my case I use:
}

  private String convertIPtoHex(ipAddress) { 
        String hex = ipAddress.tokenize( '.' ).collect {  String.format( '%02x', it.toInteger() ) }.join()
        log.debug "IP address entered is $ipAddress and the converted hex code is $hex"
        return hex
  }


private String convertPortToHex(port) {
	String hexport = port.toString().format( '%04x', port.toInteger() )
    log.debug hexport
    return hexport
}

So the hexa address in my logs is:

IP address entered is 192.168.1.49 and the converted hex code is c0a80131

and what I have in my device is also lowercase hexa

I am saying this since I see a guy in the post you refer talking about upper/lower case. Maybe they just have to be consistent to work…

ok. I got your point. But there is no hex format of IP address in my code. I just have the hex format IP address in the device settings.
So there’s nothing to match right ?
I’ll try with lower case just to make sure…

edit: tried with lowercase but still the same…

I think that’s now over what I have experienced when developing my own things. I have no further idea for now

1 Like

thanks. maybe I need idea from someone who knows the internals of hubaction and hubsoapaction commands.
on which sub-forum should I post it to ?

1 Like

finally I managed to solve the problem. I used a semi-raw version of the hubaction command. Full code of the device handler is below.

I just have one issue now; I want to refresh the status of router settings when the device is updated.
But I need to run multiple hubaction commands for this.
So I put the commands in the refreshCmd() function which is called through updated()

However, the format "return [command1(), command2()] does not work there.
when I bind a similar function to a button , this format works.
what is the problem here ?

/**
 *  Netgear Router
 *
 *  Copyright 2017 ilker Aktuna
 *
 *  Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
 *  in compliance with the License. You may obtain a copy of the License at:
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
 *  on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
 *  for the specific language governing permissions and limitations under the License.
 *
 */
//import groovy.json.JsonSlurper  

metadata {
	definition (name: "Netgear Router", namespace: "ilkeraktuna", author: "ilker Aktuna") {
		capability "Switch"

		attribute "ip", "string"
		attribute "port", "string"
		attribute "username", "string"
		attribute "password", "string"
        attribute "GuestWifi2Ghz", "string"
        attribute "GuestWifi5Ghz", "string"
        attribute "5ghz", "string"
        attribute "2ghz", "string"

		command "GuestWirelessOn"
		command "GuestWirelessOff"
        command "GuestWirelessOn5"
		command "GuestWirelessOff5"
        command "GetAll"
	}

    preferences {
    	section {
        input title: "", description: "Netgear Router Control", displayDuringSetup: true, type: "paragraph", element: "paragraph"
        input("ip", "string", title:"LAN IP address", description: "LAN IP address", required: true, displayDuringSetup: true)
        input("port", "string", title:"LAN Port", description: "LAN Port", required: true, displayDuringSetup: true)
        input("username", "string", title:"Administrator username (case sensitive)", description: "Administrative rights username (case sensitive)", required: true, displayDuringSetup: true)
        input("password", "password", title:"password (case sensitive)", description: "password (case sensitive)", required: false, displayDuringSetup: true)
        }
	}
    
	simulator {
		// TODO: define status and reply messages here
	}

	// UI tile definitions
	tiles(scale: 2) {
		standardTile("GuestWifi5Ghz","device.GuestWifi5Ghz", decoration: "flat", width: 2, height: 2, canChangeIcon: true){
				state "on", label: 'GuestWifi5Ghz\n${name}', action: "GuestWirelessOff5", icon: "st.Kids.kids15", backgroundColor: "#79b821", nextState: "turningOff"
				state "off", label: 'GuestWifi5Ghz\n${name}', action: "GuestWirelessOn5", icon: "st.Kids.kids15", backgroundColor: "#ffffff", nextState: "turningOn"
				state "turningOn", label: 'GuestWifi5Ghz\n${name}', action: "GuestWirelessOff5", icon: "st.Kids.kids15", backgroundColor: "#79b821", nextState: "turningOff"
				state "turningOff", label: 'GuestWifi5Ghz\n${name}', action: "GuestWirelessOn5", icon: "st.Kids.kids15", backgroundColor: "#ffffff", nextState: "turningOn"
		}
		standardTile("GuestWifi2Ghz","device.GuestWifi2Ghz", decoration: "flat", width: 2, height: 2){
				state "on", label: 'GuestWifi2Ghz\n${name}', action: "GuestWirelessOff", icon: "st.Kids.kids15", backgroundColor: "#79b821", nextState: "turningOff"
				state "off", label: 'GuestWifi2Ghz\n${name}', action: "GuestWirelessOn", icon: "st.Kids.kids15", backgroundColor: "#ffffff", nextState: "turningOn"
				state "turningOn", label: 'GuestWifi2Ghz\n${name}', action: "GuestWirelessOff", icon: "st.Kids.kids15", backgroundColor: "#79b821", nextState: "turningOff"
				state "turningOff", label: 'GuestWifi2Ghz\n${name}', action: "GuestWirelessOn", icon: "st.Kids.kids15", backgroundColor: "#ffffff", nextState: "turningOn"
		}
		standardTile( "refresh", "device.power", inactiveLabel: false, decoration: "flat", width: 2, height: 2) {
			state "default", label:'', action:"refresh.refresh", icon:"st.secondary.refresh"
		}
        valueTile("5ghz", "device.5ghz", decoration: "flat", width: 2, height: 2) {
			state ("default", label:'${currentValue}')
		}
        valueTile("2ghz", "device.2ghz", decoration: "flat", width: 2, height: 2) {
			state ("default", label:'${currentValue}')
		}
		standardTile( "refreshall", "device.power", decoration: "flat", width: 2, height: 2) {
			state "default", label:'refresh', action: "GetAll", icon:"st.secondary.refresh", nextState: "default"
		}
		main "GuestWifi2Ghz"
		details(["GuestWifi5Ghz","GuestWifi2Ghz","refresh","5ghz","2ghz","refreshall"])
        
	}
}

def installed() {
    initialize()
}

def updated() {
//    unsubscribe()
    initialize()
}

def poll(){
    refreshCmd()
}

def initialize() {
    refreshCmd()
}

// parse events into attributes
def parse(String description) {
	def events = []
    def descMap = parseDescriptionAsMap(description)

	def body = new String(descMap["body"].decodeBase64())
    log.debug body
    def xmlt = new groovy.util.XmlParser().parseText(body)
/*
    if ( state.lastcmd == "gwget") {
	log.debug xmlt.'*'.'*'.NewGuestAccessEnabled.text()
    if (xmlt.'*'.'m:GetGuestAccessEnabledResponse'.NewGuestAccessEnabled.text() == "1") {sendEvent(name: "GuestWifi2Ghz", value: "on", isStateChange: true, displayed: false)}
    if (xmlt.'*'.'m:GetGuestAccessEnabledResponse'.NewGuestAccessEnabled.text() == "0") {sendEvent(name: "GuestWifi2Ghz", value: "off", isStateChange: true, displayed: false)}
    if (xmlt.'*'.'m:GetGuestAccessNetworkInfoResponse'.NewSSID.text() != null) {
    state.ssid2 = xmlt.'*'.'m:GetGuestAccessNetworkInfoResponse'.NewSSID.text()
    sendEvent(name: "2ghz", value: state.ssid2, isStateChange: true, displayed: false)
    log.debug "ssid 2ghz: $state.ssid"}
    }
    if ( state.lastcmd == "gwget5") {
	log.debug xmlt.'*'.'*'.NewGuestAccessEnabled.text()
    if (xmlt.'*'.'m:Get5GGuestAccessEnabledResponse'.NewGuestAccessEnabled.text() == "1") {sendEvent(name: "GuestWifi5Ghz", value: "on", isStateChange: true, displayed: false)}
    if (xmlt.'*'.'m:Get5GGuestAccessEnabledResponse'.NewGuestAccessEnabled.text() == "0") {sendEvent(name: "GuestWifi5Ghz", value: "off", isStateChange: true, displayed: false)}
    if (xmlt.'*'.'m:Get5GGuestAccessNetworkInfoResponse'.NewSSID.text() != null) {
    state.ssid5 = xmlt.'*'.'m:Get5GGuestAccessNetworkInfoResponse'.NewSSID.text()
    sendEvent(name: "5ghz", value: state.ssid5, isStateChange: true, displayed: false)
    log.debug "ssid 5ghz000: $state.ssid5"}
    }
    if ( state.lastcmd == "gwgetall") {
	log.debug xmlt.'*'.'*'.NewGuestAccessEnabled.text()
    if (xmlt.'*'.'m:GetGuestAccessEnabledResponse'.NewGuestAccessEnabled.text() == "1") {sendEvent(name: "GuestWifi2Ghz", value: "on", isStateChange: true, displayed: false)}
    if (xmlt.'*'.'m:GetGuestAccessEnabledResponse'.NewGuestAccessEnabled.text() == "0") {sendEvent(name: "GuestWifi2Ghz", value: "off", isStateChange: true, displayed: false)}
    if (xmlt.'*'.'m:Get5GGuestAccessEnabledResponse'.NewGuestAccessEnabled.text() == "1") {sendEvent(name: "GuestWifi5Ghz", value: "on", isStateChange: true, displayed: false)}
    if (xmlt.'*'.'m:Get5GGuestAccessEnabledResponse'.NewGuestAccessEnabled.text() == "0") {sendEvent(name: "GuestWifi5Ghz", value: "off", isStateChange: true, displayed: false)}
    }
    if ( state.lastcmd == "getall") {
*/
	log.debug xmlt.'*'.'*'.NewGuestAccessEnabled.text()
    if (xmlt.'*'.'m:GetGuestAccessEnabledResponse'.NewGuestAccessEnabled.text() == "1") {sendEvent(name: "GuestWifi2Ghz", value: "on", isStateChange: true, displayed: false)}
    if (xmlt.'*'.'m:GetGuestAccessEnabledResponse'.NewGuestAccessEnabled.text() == "0") {sendEvent(name: "GuestWifi2Ghz", value: "off", isStateChange: true, displayed: false)}
    if (xmlt.'*'.'m:Get5GGuestAccessEnabledResponse'.NewGuestAccessEnabled.text() == "1") {sendEvent(name: "GuestWifi5Ghz", value: "on", isStateChange: true, displayed: false)}
    if (xmlt.'*'.'m:Get5GGuestAccessEnabledResponse'.NewGuestAccessEnabled.text() == "0") {sendEvent(name: "GuestWifi5Ghz", value: "off", isStateChange: true, displayed: false)}
    if (xmlt.'*'.'m:Get5GGuestAccessNetworkInfoResponse'.NewSSID.text() != null && xmlt.'*'.'m:Get5GGuestAccessNetworkInfoResponse'.NewSSID.text() != "") {
    state.ssid5 = xmlt.'*'.'m:Get5GGuestAccessNetworkInfoResponse'.NewSSID.text() + "\n" + xmlt.'*'.'m:Get5GGuestAccessNetworkInfoResponse'.NewKey.text()
    sendEvent(name: "5ghz", value: "$state.ssid5", isStateChange: true, displayed: false)
    log.debug "ssid 5ghz: $state.ssid5"}
    if (xmlt.'*'.'m:GetGuestAccessNetworkInfoResponse'.NewSSID.text() != null && xmlt.'*'.'m:GetGuestAccessNetworkInfoResponse'.NewSSID.text() != "") {
    state.ssid2 = xmlt.'*'.'m:GetGuestAccessNetworkInfoResponse'.NewSSID.text() + "\n" + xmlt.'*'.'m:GetGuestAccessNetworkInfoResponse'.NewKey.text()
    sendEvent(name: "2ghz", value: "$state.ssid2", isStateChange: true, displayed: false)
    log.debug "ssid 2ghz: $state.ssid2"}
/*    }
*/    
}

def parseDescriptionAsMap(description) {
	description.split(",").inject([:]) { map, param ->
		def nameAndValue = param.split(":")
        
        if (nameAndValue.length == 2) map += [(nameAndValue[0].trim()):nameAndValue[1].trim()]
        else map += [(nameAndValue[0].trim()):""]
	}
}

// handle commands
def on() {
	log.debug "Executing 'on'"
	// TODO: handle 'on' command
}

def off() {
	log.debug "Executing 'off'"
	// TODO: handle 'off' command
}

def GuestWirelessOn5() {
	log.debug "Executing 'GuestWirelessOn 5Ghz'"
return [authrouter(), delayAction(9000), configStarted(), delayAction(9000), gwon5(), delayAction(9000), configFinished(), delayAction(9000), gwget5(), delayAction(9000), gwinfo5()]
}

def GuestWirelessOff5() {
	log.debug "Executing 'GuestWirelessOff 5Ghz'"
return [authrouter(), delayAction(9800), configStarted(), delayAction(9800), gwoff5(), delayAction(9800), configFinished(), delayAction(9000), gwget5()]
}

def GuestWirelessOn() {
	log.debug "Executing 'GuestWirelessOn 2Ghz'"
return [authrouter(), delayAction(9000), configStarted(), delayAction(9000), gwon(), delayAction(9000), configFinished(), delayAction(9000), gwget(), delayAction(9000), gwinfo()]
}

def GuestWirelessOff() {
	log.debug "Executing 'GuestWirelessOff 2Ghz'"
return [authrouter(), delayAction(9800), configStarted(), delayAction(9800), gwoff(), delayAction(9800), configFinished(), delayAction(9000), gwget()]
}

def refreshCmd() {
	log.debug "Executing refreshCmd"
	
    def host = ip 
    def port = port
    def hosthex = convertIPtoHex(host)
    def porthex = convertPortToHex(port)
    log.debug "The device id before update is: $device.deviceNetworkId"
    device.deviceNetworkId = "$hosthex:$porthex"
    log.debug "The device id configured is: $device.deviceNetworkId"
    
    //return gwgetall()
    //return infoall
    return GetAll()
//    return [gwget(), delayAction(1000), gwget5(), delayAction(1000), gwinfo(), delayAction(1000), gwinfo5()]
    
}

def GetAll() {
	state.lastcmd = "getall"
    return [gwget(), delayAction(1000), gwget5(), delayAction(1000), gwinfo(), delayAction(1000), gwinfo5()]
}

private gwgetall() {
	state.lastcmd = "gwgetall"
	def host = "$ip:$port"
    def method = "POST"
    def path = "/soap/server_sa/"   
    def headers = [:] 
    headers.put("HOST", "$host")
    headers.put("SOAPAction", "urn:NETGEAR-ROUTER:service:WLANConfiguration:1#GetGuestAccessEnabled")
	headers.put("content-type", "text/xml;charset=utf-8")
    try {
    def body="""<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<SOAP-ENV:Envelope xmlns:SOAPSDK1="http://www.w3.org/2001/XMLSchema" xmlns:SOAPSDK2="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAPSDK3="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header>
<SessionID>58DEE6006A88A967E89A</SessionID>
</SOAP-ENV:Header><SOAP-ENV:Body>
<M1:GetGuestAccessEnabled xmlns:M1="urn:NETGEAR-ROUTER:service:WLANConfiguration:1"></M1:GetGuestAccessEnabled>
</SOAP-ENV:Body></SOAP-ENV:Envelope>"""

    def hubAction = new physicalgraph.device.HubAction(
    	method: method,
    	path: path,
    	headers: headers,
        body: body
        )
    hubAction
    }
    catch (Exception e) {
    	log.debug "Hit Exception $e on $hubAction"
    }
    log.debug "------------1"
    new physicalgraph.device.HubAction("delay 2000")
    log.debug "------------2"
    headers.put("HOST", "$host")
    headers.put("SOAPAction", "urn:NETGEAR-ROUTER:service:WLANConfiguration:1#Get5GGuestAccessEnabled")
	headers.put("content-type", "text/xml;charset=utf-8")
    try {
    def body="""<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<SOAP-ENV:Envelope xmlns:SOAPSDK1="http://www.w3.org/2001/XMLSchema" xmlns:SOAPSDK2="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAPSDK3="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header>
<SessionID>58DEE6006A88A967E89A</SessionID>
</SOAP-ENV:Header><SOAP-ENV:Body>
<M1:Get5GGuestAccessEnabled xmlns:M1="urn:NETGEAR-ROUTER:service:WLANConfiguration:1"></M1:Get5GGuestAccessEnabled>
</SOAP-ENV:Body></SOAP-ENV:Envelope>"""

    def hubAction = new physicalgraph.device.HubAction(
    	method: method,
    	path: path,
    	headers: headers,
        body: body
        )
    hubAction
    }
    catch (Exception e) {
    	log.debug "Hit Exception $e on $hubAction"
    }
}

private gwoff() {
	def host = "$ip:$port"
    def method = "POST"
    def path = "/soap/server_sa/"   
    def headers = [:] 
    headers.put("HOST", "$host")
    headers.put("SOAPAction", "urn:NETGEAR-ROUTER:service:WLANConfiguration:1#SetGuestAccessEnabled")
	headers.put("content-type", "text/xml;charset=utf-8")
    try {
    def body="""<?xml version="1.0" encoding="UTF-8" standalone="no"?><SOAP-ENV:Envelope xmlns:SOAPSDK1="http://www.w3.org/2001/XMLSchema" xmlns:SOAPSDK2="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAPSDK3="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header>
<SessionID>58DEE6006A88A967E89A</SessionID>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<M1:SetGuestAccessEnabled xmlns:M1="urn:NETGEAR-ROUTER:service:WLANConfiguration:1">
<NewGuestAccessEnabled>0</NewGuestAccessEnabled>
</M1:SetGuestAccessEnabled>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>"""

    def hubAction = new physicalgraph.device.HubAction(
    	method: method,
    	path: path,
    	headers: headers,
        body: body
        )
    hubAction
    }
    catch (Exception e) {
    	log.debug "Hit Exception $e on $hubAction"
    }

}

private gwon() {
	def host = "$ip:$port"
    def method = "POST"
    def path = "/soap/server_sa/"   
    def headers = [:] 
    headers.put("HOST", "$host")
    headers.put("SOAPAction", "urn:NETGEAR-ROUTER:service:WLANConfiguration:1#SetGuestAccessEnabled2")
	headers.put("content-type", "text/xml;charset=utf-8")
    try {
    def body="""<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<SOAP-ENV:Envelope xmlns:SOAPSDK1="http://www.w3.org/2001/XMLSchema" xmlns:SOAPSDK2="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAPSDK3="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header>
<SessionID>58DEE6006A88A967E89A</SessionID>
</SOAP-ENV:Header><SOAP-ENV:Body>
<M1:SetGuestAccessEnabled2 xmlns:M1="urn:NETGEAR-ROUTER:service:WLANConfiguration:1">
<NewGuestAccessEnabled>1</NewGuestAccessEnabled>
</M1:SetGuestAccessEnabled2>
</SOAP-ENV:Body></SOAP-ENV:Envelope>"""

    def hubAction = new physicalgraph.device.HubAction(
    	method: method,
    	path: path,
    	headers: headers,
        body: body
        )
    hubAction
    }
    catch (Exception e) {
    	log.debug "Hit Exception $e on $hubAction"
    }
}

private gwget() {
	state.lastcmd = "gwget"
	def host = "$ip:$port"
    def method = "POST"
    def path = "/soap/server_sa/"   
    def headers = [:] 
    headers.put("HOST", "$host")
    headers.put("SOAPAction", "urn:NETGEAR-ROUTER:service:WLANConfiguration:1#GetGuestAccessEnabled")
	headers.put("content-type", "text/xml;charset=utf-8")
    try {
    def body="""<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<SOAP-ENV:Envelope xmlns:SOAPSDK1="http://www.w3.org/2001/XMLSchema" xmlns:SOAPSDK2="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAPSDK3="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header>
<SessionID>58DEE6006A88A967E89A</SessionID>
</SOAP-ENV:Header><SOAP-ENV:Body>
<M1:GetGuestAccessEnabled xmlns:M1="urn:NETGEAR-ROUTER:service:WLANConfiguration:1"></M1:GetGuestAccessEnabled>
</SOAP-ENV:Body></SOAP-ENV:Envelope>"""

    def hubAction = new physicalgraph.device.HubAction(
    	method: method,
    	path: path,
    	headers: headers,
        body: body
        )
    hubAction
    }
    catch (Exception e) {
    	log.debug "Hit Exception $e on $hubAction"
    }
}

private gwinfo() {
	state.lastcmd = "gwget"
	def host = "$ip:$port"
    def method = "POST"
    def path = "/soap/server_sa/"   
    def headers = [:] 
    headers.put("HOST", "$host")
    headers.put("SOAPAction", "urn:NETGEAR-ROUTER:service:WLANConfiguration:1#GetGuestAccessNetworkInfo")
	headers.put("content-type", "text/xml;charset=utf-8")
    try {
    def body="""<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<SOAP-ENV:Envelope xmlns:SOAPSDK1="http://www.w3.org/2001/XMLSchema" xmlns:SOAPSDK2="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAPSDK3="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header>
<SessionID>58DEE6006A88A967E89A</SessionID>
</SOAP-ENV:Header><SOAP-ENV:Body>
<M1:GetGuestAccessNetworkInfo xmlns:M1="urn:NETGEAR-ROUTER:service:WLANConfiguration:1"></M1:GetGuestAccessNetworkInfo>
</SOAP-ENV:Body></SOAP-ENV:Envelope>"""

    def hubAction = new physicalgraph.device.HubAction(
    	method: method,
    	path: path,
    	headers: headers,
        body: body
        )
    hubAction
    }
    catch (Exception e) {
    	log.debug "Hit Exception $e on $hubAction"
    }
}

private gwoff5() {
	def host = "$ip:$port"
    def method = "POST"
    def path = "/soap/server_sa/"   
    def headers = [:] 
    headers.put("HOST", "$host")
    headers.put("SOAPAction", "urn:NETGEAR-ROUTER:service:WLANConfiguration:1#Set5GGuestAccessEnabled")
	headers.put("content-type", "text/xml;charset=utf-8")
    try {
    def body="""<?xml version="1.0" encoding="UTF-8" standalone="no"?><SOAP-ENV:Envelope xmlns:SOAPSDK1="http://www.w3.org/2001/XMLSchema" xmlns:SOAPSDK2="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAPSDK3="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header>
<SessionID>58DEE6006A88A967E89A</SessionID>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<M1:Set5GGuestAccessEnabled xmlns:M1="urn:NETGEAR-ROUTER:service:WLANConfiguration:1">
<NewGuestAccessEnabled>0</NewGuestAccessEnabled>
</M1:Set5GGuestAccessEnabled>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>"""

    def hubAction = new physicalgraph.device.HubAction(
    	method: method,
    	path: path,
    	headers: headers,
        body: body
        )
    hubAction
    }
    catch (Exception e) {
    	log.debug "Hit Exception $e on $hubAction"
    }

}

private gwon5() {
	def host = "$ip:$port"
    def method = "POST"
    def path = "/soap/server_sa/"   
    def headers = [:] 
    headers.put("HOST", "$host")
    headers.put("SOAPAction", "urn:NETGEAR-ROUTER:service:WLANConfiguration:1#Set5GGuestAccessEnabled2")
	headers.put("content-type", "text/xml;charset=utf-8")
    try {
    def body="""<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<SOAP-ENV:Envelope xmlns:SOAPSDK1="http://www.w3.org/2001/XMLSchema" xmlns:SOAPSDK2="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAPSDK3="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header>
<SessionID>58DEE6006A88A967E89A</SessionID>
</SOAP-ENV:Header><SOAP-ENV:Body>
<M1:Set5GGuestAccessEnabled2 xmlns:M1="urn:NETGEAR-ROUTER:service:WLANConfiguration:1">
<NewGuestAccessEnabled>1</NewGuestAccessEnabled>
</M1:Set5GGuestAccessEnabled2>
</SOAP-ENV:Body></SOAP-ENV:Envelope>"""

    def hubAction = new physicalgraph.device.HubAction(
    	method: method,
    	path: path,
    	headers: headers,
        body: body
        )
    hubAction
    }
    catch (Exception e) {
    	log.debug "Hit Exception $e on $hubAction"
    }
}

private gwget5() {
	state.lastcmd = "gwget5"
	def host = "$ip:$port"
    def method = "POST"
    def path = "/soap/server_sa/"   
    def headers = [:] 
    headers.put("HOST", "$host")
    headers.put("SOAPAction", "urn:NETGEAR-ROUTER:service:WLANConfiguration:1#Get5GGuestAccessEnabled")
	headers.put("content-type", "text/xml;charset=utf-8")
    try {
    def body="""<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<SOAP-ENV:Envelope xmlns:SOAPSDK1="http://www.w3.org/2001/XMLSchema" xmlns:SOAPSDK2="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAPSDK3="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header>
<SessionID>58DEE6006A88A967E89A</SessionID>
</SOAP-ENV:Header><SOAP-ENV:Body>
<M1:Get5GGuestAccessEnabled xmlns:M1="urn:NETGEAR-ROUTER:service:WLANConfiguration:1"></M1:Get5GGuestAccessEnabled>
</SOAP-ENV:Body></SOAP-ENV:Envelope>"""

    def hubAction = new physicalgraph.device.HubAction(
    	method: method,
    	path: path,
    	headers: headers,
        body: body
        )
    hubAction
    }
    catch (Exception e) {
    	log.debug "Hit Exception $e on $hubAction"
    }
}

private gwinfo5() {
	state.lastcmd = "gwget5"
	def host = "$ip:$port"
    def method = "POST"
    def path = "/soap/server_sa/"   
    def headers = [:] 
    headers.put("HOST", "$host")
    headers.put("SOAPAction", "urn:NETGEAR-ROUTER:service:WLANConfiguration:1#Get5GGuestAccessNetworkInfo")
	headers.put("content-type", "text/xml;charset=utf-8")
    try {
    def body="""<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<SOAP-ENV:Envelope xmlns:SOAPSDK1="http://www.w3.org/2001/XMLSchema" xmlns:SOAPSDK2="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAPSDK3="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header>
<SessionID>58DEE6006A88A967E89A</SessionID>
</SOAP-ENV:Header><SOAP-ENV:Body>
<M1:Get5GGuestAccessNetworkInfo xmlns:M1="urn:NETGEAR-ROUTER:service:WLANConfiguration:1"></M1:Get5GGuestAccessNetworkInfo>
</SOAP-ENV:Body></SOAP-ENV:Envelope>"""

    def hubAction = new physicalgraph.device.HubAction(
    	method: method,
    	path: path,
    	headers: headers,
        body: body
        )
    hubAction
    }
    catch (Exception e) {
    	log.debug "Hit Exception $e on $hubAction"
    }
}

private authrouter() {
def hubaction
    def host = "$ip:$port"
        	try {
    hubaction = new physicalgraph.device.HubSoapAction(
	path:    "/soap/server_sa/",
	urn:     'urn:NETGEAR-ROUTER:service:ParentalControl:1',
	action:  "Authenticate",
	body:    ["NewPassword":"$password", "NewUsername":"$username" ],
	headers: [Host:"$host", CONNECTION: "close"]
    )
    }
    catch (Exception e) {
        log.debug e
    }
    return hubaction
}

private configStarted() {
state.lastcmd = "configStarted"
def hubaction
    def host = "$ip:$port"
            try {
   	hubaction = new physicalgraph.device.HubSoapAction(
	path:    "/soap/server_sa/",
	urn:     'urn:NETGEAR-ROUTER:service:DeviceConfig:1',
	action:  "ConfigurationStarted",
	body:    ["NewSessionID":"58DEE6006A88A967E89A" ],
	headers: [Host:"$host", CONNECTION: "keep-alive"]
    )
    }
    catch (Exception e) {
        log.debug e
    }
    return hubaction
}

private configFinished() {
state.lastcmd = "configFinished"
def hubaction
    def host = "$ip:$port"
            try {
   	hubaction = new physicalgraph.device.HubSoapAction(
	path:    "/soap/server_sa/",
	urn:     'urn:NETGEAR-ROUTER:service:DeviceConfig:1',
	action:  "ConfigurationFinished",
	body:    ["NewStatus":"ChangesApplied" ],
	headers: [Host:"$host", CONNECTION: "keep-alive"]
    )
    }
    catch (Exception e) {
        log.debug e
    }
    return hubaction
}

private delayAction(long time) {
	new physicalgraph.device.HubAction("delay $time")
}

private String convertIPtoHex(ipAddress) { 
    String hex = ipAddress.tokenize( '.' ).collect {  String.format( '%02x', it.toInteger() ) }.join()
    log.debug "IP address entered is $ipAddress and the converted hex code is $hex"
    return hex

}

private String convertPortToHex(port) {
	String hexport = port.toString().format( '%04x', port.toInteger() )
    log.debug hexport
    return hexport
}


//bunlar lazım mı

// gets the address of the Hub
private getCallBackAddress() {
    return device.hub.getDataValue("localIP") + ":" + device.hub.getDataValue("localSrvPortTCP")
}

// 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)
}

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(".")
}

I would try this:
add the Capability “Refresh” in your setting, just after the other one you have.

Rename the RefreshCmd into redresh

I suspect the method you defined not being a command, it is not generating events on return.

you might also add a command “refreshCmd” but that would be redundant since this the role of the refresh command.
You also have to declare the poll capability since you plan to have it used.

capability or command ?

how shall I use it ?

edit:

now added
capability “Refresh”
command “Refresh”

renamed refreshCmd to Refresh and called it from updated()

but nothing cahnged. Refresh is being called but following line does not run:

return [gwget(), delayAction(1000), gwget5(), delayAction(1000), gwinfo(), delayAction(1000), gwinfo5()]

capability "refresh"
no need for command for refresh so please remove it

you also have to add a capability “polling”

let me know

ok. added:
capability "refresh"
capability “polling”

and renamed refreshCmd to refresh()

but nothing changed.

I also added refresh() under updated()

but doesnt work…

any ideas to achieve polling and refreshing ability ?
I still could not succeed in calling 2 hubactions from the initialize or updated functions.

You have to declare the capability and then implement the respective poll
and refresh methods.
Remember that refresh suffers a problem leading most of us using pollster
smartapp instead of the regular runEveryxxxMin that you normally would have
triggered in your installed method to make sure the polling happens upon
your desired frequency.

can you give me an example ? I don’t know how to write the refresh and poll methods and I couldn’t solve it up to now…
an example groovy file would help a lot.

you can refer to any device refresh in smartthings public github or in my
own github.
Basically, a poll or refresh would call something to either trigger
information collection information from the sensor (poll) or refresh the
device state versus the sensor current state.
That’s how I make the difference between both the 2 capabilities, however,
sometimes they might end-up doing the same. I for instance call the
refresh() in my poll method

In my devs, you would find this kind of code:
capability "refresh"
capability “polling”

Then
def poll(){

log.debug “Executing ‘poll’”

refresh()

}

Then:

def refresh() {

log.debug “Executing refresh”

def hubAction = new physicalgraph.device.HubAction(

 method: "GET",

 path: path,

 headers: headers

    )

    return hubAction

}

catch (Exception e) {

 log.debug "Hit Exception $e on $hubAction"

}

}

Hope that helps

1 Like

thanks. I have a question : when is the poll occuring ? (every 5 minutes ? or what ?)

and , I have a problem :

I need to call multiple hubactions (2 or 3) in the refresh. But if I call 2 , they don’t even start.
how can I solve this ?