Python based Wifi presence detector for Raspberry Pi

This python script is used in conjunction with the SmartApp and DTH that Stuart created in his post on ASUSWRT Wifi Presence:

This Python script is intended to run on a Raspberry Pi but likely will work on any linux box connected to your home network. This replaces the shell script that Stuart provided to run on a WRT box. With this set up, you can use your current network setup, all it requires is knowledge of the IP address of the target phone(s).

The code will first perform a ping for all the target IP addresses which populates the Arp table. It then polls the arp table every 10 seconds to see if the HW Mac Address is present, indicating the user has joined the Wifi. It will then send a message to the SmartApp to indicate the change in Presence.

Once you install the script, you will need to ‘chmod 755 scan_wifi.py’ to make it executable … then you’ll want to edit your /etc/rc.local to add a command to keep it running. I used ‘nohup python /home/pi/scan_wifi.py &’

Once you’ve gone through the ASUSWRT installation, you will see the AppID and AccessTokens. The IP_Addr is the IP of the phone you are interested in tracking. The Name is any name you want to call it (not really needed but helps keeping track of who’s who) The Present is a flag used to store the current state.

James

2 Likes