Skip to content

Instantly share code, notes, and snippets.

@tanelpuhu
Last active August 29, 2015 13:56
Show Gist options
  • Save tanelpuhu/9197495 to your computer and use it in GitHub Desktop.
Save tanelpuhu/9197495 to your computer and use it in GitHub Desktop.
phone-is-home
#!/bin/bash
# http://www.reddit.com/r/raspberry_pi/comments/1yrudi/a_simple_bash_script_for_detecting_the_presence/
MACS=`arp -an | awk '{print $4}'`
IFS='\n'
read -a MAC_ARRAY <<< "${MACS}"
for MAC in $MAC_ARRAY
do
if [ $MAC == {insert your phone mac adress here} ]
then
echo "phone is home!"
else
echo "phone is not home :("
fi
done
#!/bin/bash
# http://www.reddit.com/r/raspberry_pi/comments/1yrudi/a_simple_bash_script_for_detecting_the_presence/
# Checks for presence of device and speaks a notification
NOW=$(date +"%s")
dayBegin=$(date --date="Today 07:00" +"%s")
dayEnd=$(date --date="Today 22:00" +"%s")
if [ ${NOW} -gt ${dayBegin} ] && [ ${NOW} -lt ${dayEnd} ]; then
ping 192.168.1.40 -c 1 -W 5 > /home/pi/devicelist
status=$(grep -i -c '1 received' /home/pi/devicelist)
prevStatus=$(cat /home/pi/ishome)
if [ $status = $prevStatus ]; then
echo "No change"
else
if [ $status = "1" ]; then
echo "Phone detected"
else
echo "Phone lost"
fi
fi
echo $status > /home/pi/ishome
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment