Friday, July 8, 2016

Raspberry Pi 3 + Cisco Spark - My home presence check

Just got my Raspberry Pi 3 a few days ago.  I know there are loads of projects that I can do with that, before knowing what I actually want to do, I want to try something quick and simple to keep the box warm.  I've an python scripts based on the post here:

http://www.instructables.com/id/Raspberry-Pi-Bluetooth-InOut-Board-or-Whos-Hom/

I modified it slightly to send a message to a Spark room when the Raspberry Pi detects my iPhone bluetooth mac address:

#!/usr/bin/python

import bluetooth
import time
import pyCiscoSpark

print "Home Attendance"

accesstoken="Bearer "
roomid=""

while True:
        currenttime=time.strftime("%a, %d %b %Y %H:%M:%S", time.localtime())
        print "Checking " + currenttime

        result = bluetooth.lookup_name('ff:ff:ff:ff:ff:ff', timeout=5)
        if (result != None):
                print "Danny: in"
                resp_dict = pyCiscoSpark.post_message(accesstoken,roomid,"BT: Danny is at home now - " + currenttime)
                #print (resp_dict)
        else:
                print "Danny: out"
                resp_dict = pyCiscoSpark.post_message(accesstoken,roomid,"BT: Danny is NOT at home now - " + currenttime)

        time.sleep(60)

Replace ff:ff:ff:ff:ff:ff with your phone Bluetooth mac address.  I've also used the pyCiscoSpark.py in Github for posting a message to the Spark room:

https://github.com/brbester/pyCiscoSpark

So this is how it looks like when the script is running:



Spark room:

No comments: