thank you sooo much
it really works now.
Now I have to figure out how to parse the response and change the button state accordingly. Because the button stays āonā always.
thank you sooo much
it really works now.
Now I have to figure out how to parse the response and change the button state accordingly. Because the button stays āonā always.
That one is easy:
In your parse, once you decode your answer, you just have to create an event and send it to your tile.
Check my DTH: https://github.com/philippeportesppo/Honeywell_HPA250B_SmartThings/blob/master/honeywell-hpa250b.groovy
in the parse function, youāll see how to do that.
Good luck
thanks. then difficult part is parsing
actually, thereās one more question, since you know a lot about it.
I call several hubactions from the action:
def GuestWirelessOff() {
log.debug "Executing 'GuestWirelessOff'"
return [authrouter1(), delayAction(9800), configStarted1(), delayAction1(9800), gwoff1(), delayAction2(9800), configFinished1(), delayAction3(9800)]
}
I just need to parse the result of gwoff1 to understand if it worked. How can I do that ?
I have no idea regarding the answer format you get but simply, parse method argument is a deacription string that can be either interpreted as json (my dth is an example) or html (you can refer to my airmentor dth on my same github) or other types as long as you have something to decode it.
Check the smartthings documentation for parse method, that will give you many examplea too
ok. I got it. I am able to parse the messages now. But response to āhubactionā does not trigger parse function.
Return to hubsoapaction triggers parse.
I donāt get it why.
I found this thread :
It says āput the port in hex with 4 digitsā and I do that. my device id is C0A8FE01:0050
but doesnt work.
a comment on your implementation: all the events you returned will be fired at once in my understanding.
if you need to sequence -> action, youāll have certainly to setup a state variable so that query to answer sequence update the state variable and plan the next sequence -> action
ok. I can do that. (state machine)
but I still could not get hubaction result to trigger parse
what can I check ?
whatever I do , I could not make the result of hubaction command to trigger parse()
hubsoap action command results always trigger parse()
I compared both results and canāt find a significant difference to prevent response reaching the hub.
this is an example reaching the parse function:
POST /soap/server_sa/ HTTP/1.1
Accept: */*
User-Agent: Linux UPnP/1.0 SmartThings
Host: 192.168.254.1:80
CONNECTION: keep-alive
SOAPAction: "urn:NETGEAR-ROUTER:service:DeviceConfig:1#ConfigurationStarted"
Content-Type: text/xml; charset="utf-8"
Content-Length: 343
<?xml version="1.0" encoding="utf-8"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><s:Body><u:ConfigurationStarted xmlns:u="urn:NETGEAR-ROUTER:service:DeviceConfig:1"><NewSessionID>58DEE6006A88A967E89A</NewSessionID></u:ConfigurationStarted></s:Body></s:Envelope>HTTP/1.0 200 OK
CONTENT-LENGTH: 359
CONTENT-TYPE: text/xml; charset="utf-8"
SERVER: Linux UPnP/1.0
<?xml version="1.0" encoding="UTF-8"?><s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<s:Body>
<m:ConfigurationStartedResponse xmlns:m="urn:NETGEAR-ROUTER:service:DeviceConfig:1"></m:ConfigurationStartedResponse>
<ResponseCode>000</ResponseCode>
</s:Body>
</s:Envelope>
and this is the one from hubaction , which does not trigger parse:
POST /soap/server_sa/ HTTP/1.0
SOAPAction: "urn:NETGEAR-ROUTER:service:WLANConfiguration:1#GetGuestAccessEnabled"
content-type: text/xml;charset=utf-8
Host: 192.168.254.1:80
User-Agent: SOAP Toolkit 3.0
connection: keep-Alive
Cache-Control: no-cache
Pragma: no-cache
content-length: 599
<?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>HTTP/1.0 200 OK
CONTENT-LENGTH: 569
CONTENT-TYPE: text/xml; charset="utf-8"
SERVER: Linux UPnP/1.0
<?xml version="1.0" encoding="UTF-8"?><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:Body>
<m:GetGuestAccessEnabledResponse xmlns:m="urn:NETGEAR-ROUTER:service:WLANConfiguration:1">
<NewGuestAccessEnabled>0</NewGuestAccessEnabled>
</m:GetGuestAccessEnabledResponse>
<ResponseCode>000</ResponseCode>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
I also tried making the soap headers similar to the hubsoapaction headers:
POST /soap/server_sa/ HTTP/1.0
SOAPAction: "urn:NETGEAR-ROUTER:service:WLANConfiguration:1#GetGuestAccessEnabled"
content-type: text/xml;charset=utf-8
Host: 192.168.254.1:80
User-Agent: SOAP Toolkit 3.0
connection: keep-Alive
Cache-Control: no-cache
Pragma: no-cache
content-length: 599
<?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>HTTP/1.0 200 OK
CONTENT-LENGTH: 569
CONTENT-TYPE: text/xml; charset="utf-8"
SERVER: Linux UPnP/1.0
<?xml version="1.0" encoding="UTF-8"?><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:Body>
<m:GetGuestAccessEnabledResponse xmlns:m="urn:NETGEAR-ROUTER:service:WLANConfiguration:1">
<NewGuestAccessEnabled>0</NewGuestAccessEnabled>
</m:GetGuestAccessEnabledResponse>
<ResponseCode>000</ResponseCode>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
I really canāt understand why this does not trigger parse()
desparately looking for helpā¦
few possibilities:
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
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 ?
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(".")
}