I am trying to write a device handler for Netgear Routers. It will enable various actions (such as turning on/off guest wifi) to be handled through ST.
I have the access to device’s SOAP interface through LAN and I know what to send to the device as in SOAP XML format.
I prefer to use HubSoapAction command because it handles the Soap headers. But I could not find any method to add a soap-envelope header section to the soap xml data with HubSoapAction command.
Since some of the commands require this header section, I used HubAction command with raw data instead (idea by @Philippe_Portes )
The problem is , return from the HubAction command does not reach the parse function. It doesn’t trigger parse. Maybe it is not associated with the device I created for my router.
On the other hand , all of the HubSoapAction command responsed trigger the parse function.
My router is using IP 192.168.254.1 and the Soap interface is on tcp port 80
So I entered network device ID c0a8fe01:0050 in my device settings when I created it.
This is correct , right ?
This is the HubAction command I try
private gwget() {
state.lastcmd = "gwget"
def host = "192.168.254.1"
def port = "80"
def hubaction
try {
hubaction = new physicalgraph.device.HubAction("""POST /soap/server_sa/ HTTP/1.1
SOAPAction: "urn:NETGEAR-ROUTER:service:WLANConfiguration:1#GetGuestAccessEnabled"
Content-Type: text/xml; charset="utf-8"
Host: ${host}:${port}
Accept: */*
User-Agent: Linux UPnP/1.0 SmartThings
CONNECTION: close
Content-Length: 598
<?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:Header>
<SessionID>58DEE6006A88A967E89A</SessionID>
</s:Header>
<s:Body>
<u:GetGuestAccessEnabled xmlns:u="urn:NETGEAR-ROUTER:service:WLANConfiguration:1"></u:GetGuestAccessEnabled>
</s:Body>
</s:Envelope>""", physicalgraph.device.Protocol.LAN,"${deviceNetworkId}")
}
catch (Exception e) {
log.debug e
}
return hubaction
}
I can see that the soap packet is reaching my router and it replies (I got network trace on my router)
This is the request and response I see on the trace:
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>
On the other hand, this is a sample from HubSoapAction request and response which successfully triggers 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>
I really can’t find what is wrong. Please someone who knows the internals of ST hubaction and hubsoapaction commands, help me…
I had different problems before I came to this point. And most of them were solved on the following thread (thanks to @Philippe_Portes ):