-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbtDevice.py
39 lines (32 loc) · 964 Bytes
/
btDevice.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/python3
#Pre run check for AutoPi
#Looks for known device before invoking AutoPi processes
#for blynk, thingpeak, autopi, wia, weather
import subprocess
import bluetooth
import time
import sys
from gpiozero import LED
from time import sleep
blue = LED(17)
green = LED(16)
def main():
while True:
print ("Checking " + time.strftime("%a, %d %b %Y %H:%M:%S", time.gmtime()))
blue.on()
time.sleep(2)
blue.off()
#Known bluetooth device
#If known device is detected in pan, invoke runAutoPi script
result = bluetooth.lookup_name('xx:xx:xx:xx:xx:xx', timeout=5)
if (result != None):
green.on()
time.sleep(2)
green.off()
subprocess.call("sudo /home/pi/autoPi/runAutoPi.sh", shell=True)
sys.exit("Hi Ian, device detected")
else:
print ("Device not detected")
time.sleep(3)
if __name__ == "__main__":
main()