[NEEDS UPDATING] Presence Detection using DD-WRT Router Script

Thank you @blancofran. I am still having some issues and it appears my router is not really supported by Tomato. There are some workarounds but it looks like a lot of people have bricked them. I started doing some peeking around and my jffs said that there was no memory available so I installed a mini build which at least allowed me to use the ipkg update command. However when it connected to the repositories they couldn’t download any of the update files. I spoke with my father and he said I still had an old linksys router in a closet from when I was younger so I think I am going to try and flash that with tomato and start there. I may also try to install optware like recommended in the tutorial.

By the way, your english is great and your help thus far has been greatly appreciated.

I am going to hold off for now and try the second router later this week.

You will have to telnet into your router and install curl or wget (with ssl support) using ipkg.

I just picked up a different router which supports the Tomato firmware. I also tried both the curl and wget commands and it recognizes both. I am just having a little bit of difficulty on where I am supposed to put the router scripts. The Tomato router has an Init (instead of startup), Shutdown, Firewall, and WAN up. I am fairly certain I want the startup script in the INIT section and that I am not using Shutdown or firewall. Do I put the rest of the script in WAN up or do I make a script file and load it onto the jffs mountable storage on the router. If so I am not sure how to copy a file using telnet onto the router. I have done a lot of searching.

Thanks

  • Joe

Ok. I am making progress. I installed optware. I also have run some tests trying to access URLs using both the curl and wget command with success. However when I use the https links i receive an error telling me that https is not supported or disabled in libcurl. I tried using the /opt/bin/curl -k reference. I also tried installed a package called wget–ssl and I can’t seem to get that to work. Any help would be appreciated.

  • Joe

Hi,

I am trying to implement the example in the first post.
But I couldn’t understand how to form the URL at:
PHONE1ON=“https://graph.api.smartthings.com/api/…”

First of all , is this a device handler or a smart app ? (the code in the first post)

I created it as a device handler and got the client ID from settings.

But now I can’t get the access code via:

https://graph.api.smartthings.com/oauth/authorize?response_type=code&client_id=ID_FROM_IDE

I finally got fed up with ST’s mobile presence and did this today on my Asus AC68 router. I also wanted to do this to get VPN capabilities since I’m sitting behind a FIOS router and Asus stock firmware doesn’t allow Access Point mode to use VPN without all sorts of weird hacks. It took me awhile, and I did have to make some modifications to the above instructions:

  1. Since my router is dual band and I only cared about the 5ghz, I had to use wl -i eth2 assoclist
  2. I had to enable jjjfs on my router and then created custom.sh and whatever.startup (so it starts up properly on reboot) and store it in /jjffs/etc/config.

What is everyone doing for logic? I am using Home Mode Director with both my and my wife’s real phones and these virtual switches. So pretty much if all of them are away, house will go into away mode, if one of them is home, the house will go into home mode. I need to use double presences as I have a wifi extender in the house and if I move towards the rear of the house, our mobile phones disconnect from the Asus router and connect to an Actiontec network extender.

Probably a stupid question, but…

My primary router is NOT DD-WRT compatible, but a few others that I use for WiFi extenders, etc are (and I already have it running on one of them).

So, does the DD-WRT router that this script runs on have to be the one that the Android/device actually connects to directly for its WiFi connection, or will this still work if the DD-WRT router is simply connected to and part of the same TCP/IP network?

All of the routers/network extenders work independently of each other. You can install it on your extenders and when you connect to them, it will work. The problem is when you roam throughout your house, you will drop off the extender and your presence sensor will say your there. I have this problem in reverse.

1 Like

Stupid question #2: Does this method require SSHd to be running on the DD-WRT router?

The reason I ask is that, although there IS a firmware for my router, it doesn’t include ssh. I’ve looked around and found one that seems appropriate to add ssh, but since I’m a total DD-WRT noob, I’m not exactly sure of the process to figure out whether or not a specific firmware will work with my router, and/or whether or not anything else is needed to get it to work properly, etc (I saw mention of compressing the CFE, but…lost).

Thanks for all the hard work on this. I got both methods working at different times: impliciter’s and cjunghans’.

My problem is though the logic for multiple mac addresses isn’t correct for either method and I don’t know how to tweak the custom.sh appropriately.

I’d like for it to be when ALL MAC addresses leave the network than the presence gets switched to PHONEOFF. When I run it now and ANY of the MAC addresses leave than it toggles to PHONEOFF.

Like the logic offered in the smartthings app with ‘Everyone leaves’.

Thanks for any help!

Not really - technically you can set up the scripts needed through the DD-WRT gui. But I found it a lot easier to troubleshoot the issues with your specific router if you can SSH into it. The DD-WRT gui I’m using doesn’t provide any errors on the scripts or anything - so if it doesn’t work on the first try it’d be tough to figure out why with out SSH I think.

I’m a total DD-WRT noob too but got it figured out for the most part.

1 Like

OK, good. I will give it a try blind first and see how that goes.
Thanks! :slight_smile:

Never mind - I figured out the logic, below is my flavor of the startup and custom scripts if anyone’s interested in how to accomplish this.


startup script (I leave GU:ES:TM:AC:AD:DY as a garbage MAC and just replace that with whatever the guest MAC is when they are there):

while [ ! -e "/tmp/custom.sh" ]; do
    sleep 1 # wait till /tmp/custom.sh gets generated
    done
    /tmp/custom.sh xx:xx:xx:xx:xx:xx yy:yy:yy:yy:yy:yy GU:ES:TM:AC:AD:DY &

custom.sh:

#!/bin/sh
WATCHDOG_SLEEP_SEC=10
MAC_ADDRESS_1="$1" # Phone 1 MAC
c1_last_state="0"
MAC_ADDRESS_2="$2" # Phone 2 MAC
c2_last_state="0"
MAC_ADDRESS_3="$3" # Guest Phone MAC
c3_last_state="0"
PHONEON="https://graph.api.smartthings.com/api/smartapps/installations/***************/iPhone/here?access_token=##############"
PHONEOFF="https://graph.api.smartthings.com/api/smartapps/installations/***************/iPhone/away?access_token=##############"
offcount=0
while sleep $WATCHDOG_SLEEP_SEC
do
	c1_new_state=`wl_atheros assoclist | grep $MAC_ADDRESS_1`
	if [ "$c1_new_state" == "$c1_last_state" ] ; then
		sleep 0
	else
		if [ "$c1_new_state" == "assoclist $MAC_ADDRESS_1" ]; then
			c1_last_state="$c1_new_state"
			wget "${PHONEON}" -qs
			offcount=0
		fi
	fi

	c2_new_state=`wl_atheros assoclist | grep $MAC_ADDRESS_2`
	if [ "$c2_new_state" == "$c2_last_state" ] ; then
		sleep 0
	else
		if [ "$c2_new_state" == "assoclist $MAC_ADDRESS_2" ]; then
			c2_last_state="$c2_new_state"
			wget "${PHONEON}" -qs
			offcount=0
		fi
	fi

	c3_new_state=`wl_atheros assoclist | grep $MAC_ADDRESS_3`
	if [ "$c3_new_state" == "$c3_last_state" ] ; then
		sleep 0
	else
		if [ "$c3_new_state" == "assoclist $MAC_ADDRESS_3" ]; then
			c3_last_state="$c3_new_state"
			wget "${PHONEON}" -qs
			offcount=0
		fi
	fi

	if [ "$c1_new_state" != "assoclist $MAC_ADDRESS_1" ] && [ "$c2_new_state" != "assoclist $MAC_ADDRESS_2" ] && [ "$c3_new_state" != "assoclist $MAC_ADDRESS_3" ] ; then
		offcount=$(( $offcount + 1 ))
	fi	

	if [ $offcount -lt 6 ]; then
		# give not responding devices 1 minute to respond
		sleep 0
	else
		c1_last_state="$c1_new_state"
		c2_last_state="$c2_new_state"
		c3_last_state="$c3_new_state"
		wget "${PHONEOFF}" -qs
		offcount=0
	fi

done

@impliciter
When you say this…

…are you referring to this?..

EDIT: Actually, I reread the thread again, and noticed the answer…

Does anyone know how long before a MAC address drops off from the arp -a list? I’ve been playing with pinging a phone’s IP and checking if the MAC address is present on the the arp table and I’m finding out that iPhones suck when it comes to being connected to the wifi :slight_smile:, can’t ping it when it goes to sleep.

Guys, I have another solution for presence Detection using DD-WRT, I will submit the code after some clean up.
:wink:

3 Likes

can’t…stand…the suspense lol :slight_smile:

Looking forward to seeing what you’ve come up with.

What does this do that the previous scripts didn’t do?

1 Like

This is really a non-trivial security risk. WTF?

Opens your home network to hackers?

Not being facetious… This setup is really bad advice.

1 Like