Netgear Nigthhawk Routers - Alexa reachaable commands

project_router

(ilker Aktuna) #1

Hi,

Some of the Netgear routers have Amazon Alexa integration. Their guest network can be enabled/disabled and they can be rebooted through Alexa.
That means they have an API for this kind of remote control.
Can we create a device handler doing the actions through ST ?

where should we start ?


#2

Quite a few companies have built Alexa integrations which unfortunately are not available for anything else. :disappointed_relieved:

So the first thing to do is to contact the router company and see if they have an open API for those commands.

If not, there are some people who put an inexpensive android device literally next to the echo and use LANnouncer or something similar to have the tablet speak the appropriate commands to the echo. Obviously, it’s a hack, but it can work. :sunglasses:


(ilker Aktuna) #3

actually, I got traces from my router’s wan interface to understand what packet is coming and then maybe I could point out the API command they use.
But there’s a lot of traffic and I could not figure out.


(ilker Aktuna) #4

hi,

I found the router’s api by tracing communication between router and its client app.

A sample communication is using basic http authentication and then a soap post to port 80.
POST /soap/server_sa/ HTTP/1.0
SOAPAction: urn:NETGEAR-ROUTER:service:WLANConfiguration:1#GetGuestAccessEnabled
content-type: text/xml;charset=utf-8
HOST: www.routerlogin.com
User-Agent: SOAP Toolkit 3.0
connection: keep-Alive
Cache-Control: no-cache
Pragma: no-cache
content-length: 540

<?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>

Now , can I do this type of http auth and soap post with Groovy ?
can anyone provide me a sample code to do it ?

btw, I found a Python code doing this but I don’t know how to convert it tp Groovy:

thanks.


(ilker Aktuna) #5

I am now able to create a soap request to the router with following code:

def hubaction = new physicalgraph.device.HubSoapAction(
path:    "/soap/server_sa/",
urn:     'urn:NETGEAR-ROUTER:service:WLANConfiguration:1',
action:  "GetGuestAccessEnabled",
body:    ["ObjectID":"FV:2","BrowseFlag":"BrowseDirectChildren","StartingIndex":"0","RequestedCount":"100"],
headers: [Host:"192.168.254.1:80", CONNECTION: "close"])
hubaction

but I get 401 unauthorized. because I don’t know how to authorize.
any idea on that ?


(ilker Aktuna) #6

I think I’ve figured out how to do it.
But I can’t use 2 consecutive hubaction commands in a function.
only the last one is run if I put them in the same function.
What is the proper way of doing it ?


(ilker Aktuna) #7

I am still trying to do it.
I need to send 3 soap commands to the router to make one change.
So I put all of these in separate functions and I call them from one action bound to a device handler’s button tile.

But I need to get the response of each commands sent to the hub.

how can I do that ?

my sample code for 3 actions are below. GuestWirelessOff is the main function called when button is pressed.

def GuestWirelessOff() {
	log.debug "Executing 'GuestWirelessOff'"
	// TODO: handle 'GuestWirelessOff' command
return [authrouter1(), configStarted1(), gwoff1() ]
}

private authrouter1() {
new physicalgraph.device.HubAction("delay 1000")
log.debug "authrouter"
    def userpassascii = "${username}:${password}"
	def userpass = "Basic " + userpassascii.encodeAsBase64().toString()
    def host = ip         
        try {
    def hubaction = new physicalgraph.device.HubSoapAction(
	path:    "/soap/server_sa/",
	urn:     'urn:NETGEAR-ROUTER:service:ParentalControl:1',
	action:  "Authenticate",
	body:    ["NewPassword":"password", "NewUsername":"admin" ],
	headers: [Host:"192.168.254.1:80", Authorization: userpass, CONNECTION: "close"],)
        log.debug hubaction
        hubaction
    }
    catch (Exception e) {
        log.debug "Hit Exception on $hubAction"
        log.debug e
    }

	
}

private gwoff1() {
new physicalgraph.device.HubAction("delay 1000")
    def userpassascii = "${username}:${password}"
	def userpass = "Basic " + userpassascii.encodeAsBase64().toString()
    def host = ip 
            try {
   	def hubaction = new physicalgraph.device.HubSoapAction(
	path:    "/soap/server_sa/",
	urn:     'urn:NETGEAR-ROUTER:service:WLANConfiguration:1',
	action:  "SetGuestAccessEnabled",
	body:    ["NewGuestAccessEnabled":"0" ],
	headers: [Host:"192.168.254.1:80", Authorization: userpass, CONNECTION: "close"],)
        log.debug hubaction
        hubaction
    }
    catch (Exception e) {
        log.debug "Hit Exception on $hubAction"
        log.debug e
    }
}

private configStarted1() {
new physicalgraph.device.HubAction("delay 1000")
    def userpassascii = "${username}:${password}"
	def userpass = "Basic " + userpassascii.encodeAsBase64().toString()
    def host = ip 
            try {
   	def hubaction = new physicalgraph.device.HubSoapAction(
	path:    "/soap/server_sa/",
	urn:     'urn:NETGEAR-ROUTER:service:DeviceConfig:1',
	action:  "ConfigurationStarted",
	body:    ["NewSessionID":"58DEE6006A88A967E89A" ],
	headers: [Host:"192.168.254.1:80", Authorization: userpass, CONNECTION: "close"],)
        log.debug hubaction
        hubaction
    }
    catch (Exception e) {
        log.debug "Hit Exception on $hubAction"
        log.debug e
    }
}

(Clinton Bro) #8

Nighthawk routers are the best router on the market. On another hand, Alexa is also an interesting thing to connect smart devices. I love both. If getting any Alexa or router related problem follow troubleshooting steps here.

Download Latest Version of Alexa app