[OBSOLETE] ASUSWRT Wifi Presence

@kiranmk702
Recheck you codes.

@Fuzzyligic @PerspectiveTransform
Mofied your script for clarity as well as to make it work with newer router. It is for 2 users, but can be expanded. Maybe you find it useful. This way to enter all info so if any errors there is only one area to correct. Just enter your Info in the required fields, including ServerURL (Ishow the US one). It’s been working properly for a few days now. Here it is

#!/bin/sh

ServerURL="https://graph-na02-useast1.api.smartthings.com/api/smartapps/installations/
ServerURL2Home=”/Phone/home?access_token=“
ServerURL2Away=”/Phone/away?access_token="
User2App="AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAA"
User2Secret="BBBBBBBB-BBBB-BBBB-BBBB-BBBBBBBBBBBB"
User1App="CCCCCCCC-CCCC-CCCC-CCCC-CCCCCCCCCCCC"
User1rSecret="DDDDDDDD-DDDD-DDDD-DDDD-DDDDDDDDDDDD"
User2Mac="XX:XX:XX:XX:XX:XX"
User1Mac="YY:YY:YY:YY:YY:YY"
User1Tag=/jffs/scripts/CheckUser/User1
User2Tag=/jffs/scripts/CheckUser/User2

User1=Away
User2=Away

macadresser=wl -i eth2 assoclist && wl -i eth1 assoclist && wl -i eth3 assoclist

case “$macadresser” in
$User1Mac)
User1=Home
;;
esac

case “$macadresser” in
$User2Mac)
User2=Home
;;
esac

if [ “$User1” = Home ]
then
if [ ! -f $User1Tag ] || [ “$1” = “-f” ]
then
touch $User1Tag
curl $ServerURL$User1App$ServerURL2Home$User1Secret -k
fi
else
if [ -f $User1Tag ] || [ “$1” = “-f” ]
then
rm -f $User1Tag
curl $ServerURL$User1App$ServerURL2Away$User1Secret -k
fi
fi

if [ “$User2” = Home ]
then
if [ ! -f $User2Tag ] || [ “$1” = “-f” ]
then
touch $User2Tag
curl $ServerURL$User2App$ServerURL2Home$User2Secret -k
fi
else
if [ -f $User2Tag ] || [ “$1” = “-f” ]
then
rm -f $User2Tag
curl $ServerURL$User2App$ServerURL2Away$User2Secret -k
fi
fi

@NomadTech Thanks for your response. I have used the Device handler and Smart app from Fuzzyligic code repository, Admitting being very new to this, I created Oauth and applied it to the curl. I think this is where I am going wrong. Any help on where to pick the App id and access token would help.

Thanks,
Kiran

I use Chrome with json plugin for properly formated display for AppID
Once you publish your app go to edit and enable OAUTH and click on it.

as @Fuzzyligic said, once these have been installed you need to get the Application ID and Access Token for each app, this can be gotten from the location Tab, List Smartapps page in the IDE, just click on each of the smartapps you just created and get the following details
Just follow his instruction at the beginning of the thread, except the IDE URL which is https://graph-na02-useast1.api.smartthings.com/ for US.

Login, go to MyLocations, click on SmartApps and click on yours. This is my screen

Clicking on my name yields this

Hi @NomadTech,

Again Thanks for your response, I tried the following

curl “https://graph-eu01-euwest1.api.smartthings.com/api/smartapps/installations//Phone/home?access_token=” -k

I still get {“error”:“invalid_token”,“error_description”

Not sure what is going on …

Regards,
Kiran

Please reread the instructions you’re missing the Apple and token from that URL

Hi @Fuzzyligic,

My initial attempt was with the App ID and Token as mentioned in the instruction.

Is there anyway I can let you check my configurations in smartthings ?

Regards,
Kiran

@kiranmk702 what time zone are you in? Im in the US in Seattle this week. Maybe we could do a very quick screenshare via Skype if the timing is right.

@kiranmk702 I am in London Timezone

I think I am 8 hours Ahead , UK time . Yeah Skype or Anydesk would be great !

Can you Private message me to kiran.mk@gmail.com I will share the details

Thanks,
Kiran

Hi @Fuzzyligic, @chadly and everybody else

I have run into a wee bit of a problem using your respective smart app / code…, but first a bit of history.

I have a Asus RT-AC68U
I sucessfully set up @Fuzzyligic 's code to do wifi presence detection.
Just to re-iterate again, it works fine.

I then noticed my Android Note 4 device periodically falling off & creating issues for me.
@chadly’s code to implement a delay was just the thing I needed.

What I then did was the following:

  • Kept @Fuzzyligic 's ORIGINAL asuswrt-wifi-presence.groovy; it is tied to my wife’s phone
  • Kept @Fuzzyligic 's ORIGINAL virtual-presence-sensor.groovy
  • Because @chadly’s smart app name is the same as @Fuzzyligic 's, I renamed it as such:
    definition(
    name: “AsusWRT Wifi Presence with Timeout”,
    namespace: “chadly”,
  • Add @chadly’s smart app & enabled OAUTH
  • I did NOT use @chadly’s version of check-home.sh on the router; after all, if it aint broke then don’t fix it!
  • I DID modify the CURL lines to reflect the new “AsusWRT Wifi Presence with Timeout” smart app’s Access Token and App ID.
    — the CURL line for my wife’s phone points to @Fuzzyligic’s smart app
    — the CURL line for my phone points to @chadly’s smart app

When testing the wifi presence now, the router correctly creates the presense files as it should/did.
However, the virtual presence sensor no longer updates in ST.
Logging reveals this error:

131e16b7-xxxx-xxxx-xxxx-d78f10825856 ‎1‎:‎32‎:‎49‎ ‎PM: error physicalgraph.app.exception.SmartAppException: Not Found

First question: the name of the smart app doesn’t have to be a 100% match does it…

Other than that, I’m stuck & any assistance would be greatly appreciated.

Thanks
J

The curl line to hit my smartapp is slightly different than the original one. I changed them to POSTs instead of GETs and altered the path slightly. In retrospect, I probably should have left those alone to keep things more compatible.

Just change the CURL line that hits the “app with timeout” to POST and .../api/smartapps/../<APP_ID>/<home,away>. Check here for the full line.

1 Like

Thanks Chad

I didn’t look too closely at your version of asuswrt-wifi-presence.groovy, but did immediately notice it used a different format of the CURL command.

Is your version of the Smart App DEPENDENT on the very specific formatting of the CURL line as found in your version of asuswrt-wifi-presence.groovy? Am I mistaken in thinking that using the original CURL format but just substituting for the new Access Token etc. as created by your smart app will not suffice and hence the error?

Thanks in advance
J

1 Like

yes. the formatting in this case just being the

  • extra argument -X POST
  • the moving of the access token from a querystring param to an auth header: -H "Authorization: Bearer <ACCESS_TOKEN>"
  • the path changing from <AppID>/Phone/home to <APP_ID>/home and <AppID>/Phone/away to <APP_ID>/away

Thanks Chad (@chadly), That fixed it for me… Works like a charm.

Hi Guys,

I have a Asus RT-N66u running on latest Merlin. I have followed the steps from fuzzy logic to install the ASUS wifi presence, Device handler and the smartapp as below,

I have also installed the smart app as per the steps described

,

Below is the access token and App ID

once i have this configured in the smartthings , My presence checking script works fine, except for the curl.I am trying to run the curl from my ASUS router as a test before adding it to the script,

I get the following error…

Kiran@Area51:/jffs/scripts#
Kiran@Area51:/jffs/scripts# curl “https://graph-eu01-euwest1.api.smartthings.com/api/smartapps/11a269xxxxxxxxx-bbxxxxx9d0df/Phone/home?access_token=da77dd9a-4224-4294xxxxxxxx142a986” -k
{“error”:true,“type”:“AccessDenied”,“message”:“This request is not authorized by the specified access token”}Kiran@Area51:/jffs/scripts#

Kiran@Area51:/jffs/scripts# curl -v “https://graph-eu01-euwest1.api.smartthings.com/api/smartapps/11a2xxxxx5fxxxxxxxxxxxx59d0df/Phone/home?access_token=da77dxxxxxxxxxxxxxxx2a986” -k

  • Trying 52.211.245.173…
  • TCP_NODELAY set
  • Connected to graph-eu01-euwest1.api.smartthings.com (52.211.245.173) port 443 (#0)
  • ALPN, offering http/1.1
  • Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH
  • successfully set certificate verify locations:
  • CAfile: /rom/ca-bundle.crt
    CApath: none
  • TLSv1.2 (OUT), TLS header, Certificate Status (22):
  • TLSv1.2 (OUT), TLS handshake, Client hello (1):
  • TLSv1.2 (IN), TLS handshake, Server hello (2):
  • TLSv1.2 (IN), TLS handshake, Certificate (11):
  • TLSv1.2 (IN), TLS handshake, Server key exchange (12):
  • TLSv1.2 (IN), TLS handshake, Server finished (14):
  • TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
  • TLSv1.2 (OUT), TLS change cipher, Client hello (1):
  • TLSv1.2 (OUT), TLS handshake, Finished (20):
  • TLSv1.2 (IN), TLS change cipher, Client hello (1):
  • TLSv1.2 (IN), TLS handshake, Finished (20):
  • SSL connection using TLSv1.2 / ECDHE-RSA-AES128-GCM-SHA256
  • ALPN, server did not agree to a protocol
  • Server certificate:
  • subject: C=US; ST=Virginia; L=Reston; O=Physical Graph Corporation; CN=*.api.smartthings.com
  • start date: Jan 5 00:00:00 2016 GMT
  • expire date: Jan 27 23:59:59 2018 GMT
  • issuer: C=US; O=GeoTrust Inc.; CN=GeoTrust SSL CA - G3
  • SSL certificate verify ok.

GET /api/smartapps/11a2691f-xxxxxxxxxxx59d0df/Phone/home?access_token=da77dd9xxxxxxxxx2a986 HTTP/1.1
Host: graph-eu01-euwest1.api.smartthings.com
User-Agent: curl/7.51.0
Accept: /

< HTTP/1.1 403 Forbidden
< Content-Type: application/json;charset=utf-8
< Date: Fri, 27 Jan 2017 16:57:45 GMT
< Server: SmartThings
< Set-Cookie: JSESSIONID=9184C13766F5Axxxxxxxxxx1845-n3; Path=/; Secure; HttpOnly
< transfer-encoding: chunked
< Connection: keep-alive
<

  • Curl_http_done: called premature == 0
  • Connection #0 to host graph-eu01-euwest1.api.smartthings.com left intact
    {“error”:true,“type”:“AccessDenied”,“message”:“This request is not authorized by the specified access token”}Kiran@Area51:/jffs/scripts#

I am not sure if this is something to do with the curl in the Merlin version in RT-N66u, or is it something I have overlooked when putting this together. Thought I will give one last try in this forum before I give up. Any help on this is highly appreciated.

Regards,
Kiran

Hi @Fuzzyligic

Just realised I had addressed the below message to Myself

I am in London Timezone

I think I am 8 hours Ahead , UK time . Yeah Skype or Anydesk would be great !

Can you Private message me to kiran.mk@gmail.com I will share the details

Thanks, Kiran
[/quote]

@Fuzzyligic
Still working perfect, love it!
Thanks again for the support you gave me to get it working :slight_smile:

@Fuzzyligic

Thanks for great guidance and it’s working well. I’m using my car’s WiFi to trigger garage to open or close. However it’s a time delay which is a but annoying. It takes up to 40-50 seconds to update presence. The user file in router is updated momentarily but there’s a noticeable delay in ST. How to speed up?

@Sajjad_Sarwar if the file is being created pretty much immediately, then the web request must also be created at the same time (this is provided you are using my code and not @chadly 's version as i haven’t looked into what his version is doing in regards to the timeout) if that is the case maybe the delay is occuring in your logic for the garage door if you are using CoRE…way to check is look at the live logging and see if the request is first being in a timely manner in ST. if so then troubleshoot further down the chain.

obviously wifi can sometimes takes a while to connect, but if youve already ruled that out by checking on the file creation then it must be further up the process where the delay is being introduced. but my advice is test and monitor each portion and it should become apparent where the delay is introduced as my experience is that when wifi has connected the whole recognition and web request being sent is done in a very timely manner, usually within 5 - 10 seconds

Thanks for your input @Fuzzyligic

I did some more troubleshooting and the delay is the router (Asus RT-AC68U). Sorry for the misunderstanding. If I quickly toggle wifi on/off the router updates momently. Otherwise it can take up to 40-50 seconds.

I’m running your scripts. Only change I have made is in the CheckIfHome scripts where it looks for LAN, 2 and 5 GHz wifi.

Somehow we can make the init-script run often as every second?

@Sajjad_Sarwar forget about running the script every second, you cant runt he script at a faster interval than the script takes to run otherwise you will will exhaust threads and memory and your router will crash.

so if you run the /jffs/scripts/CheckIfHome script manually does this create the file and send the web request in a timely manner?

if so you need to look at your cron jobs.

if you run cru l you should have an output of multiple lines… I run mine every 15 seconds and my output fromt he command is as follows

admin@RT-AC87U-8C38:/tmp/home/root# cru l

          • /jffs/scripts/CheckIfHome #CheckIfHome#
          • sleep 15; /jffs/scripts/CheckIfHome #CheckIfHome15#
          • sleep 30; /jffs/scripts/CheckIfHome #CheckIfHome30#
          • sleep 45; /jffs/scripts/CheckIfHome #CheckIfHome45#

what does yours output?