Best Presence detection

Im using whis code instaled on Tomato router to track users via WIFI.
It works on any phone, android Nexus 5 in my case.

#!/bin/sh
OHIPPORT="192.168.0.212:8081"
function fcomp() {
    awk -v n1=$1 -v n2=$2 'BEGIN{ if (n1<n2) exit 0; exit 1}'
}

RET=`brctl showmacs br0|grep $1`
if [ "$RET" = "" ]
then
echo 'FAIL'
curl --header "Content-Type: text/plain" --request PUT --data "OFF" http://$OHIPPORT/rest/items/$2/state
else
ATIME=`echo $RET | awk '{print $4}'`
echo $ATIME
if fcomp $ATIME 200; then
echo "OK"
curl --header "Content-Type: text/plain" --request PUT --data "ON" http://$OHIPPORT/rest/items/$2/state
else
echo "EXP"
curl --header "Content-Type: text/plain" --request PUT --data "OFF" http://$OHIPPORT/rest/items/$2/state
fi
fi


Phone must periodicaly contact to the internet (eg. mail/whatsup check), this is normal in out times.

Execution:

maccheck.sh mirek 00:00:00:00:00

where:
mirek - is the name of switch that represents person in openhab (need to be declared in items)
00:00:00:00:00 - is the mac address of phone

Add this script to cron to be run in every minute:

cru a " * * * * * maccheck.sh mirek 00:00:00:00:00"

1 Like