forked from tdamdouni/Raspberry-Pi-DIY-Projects
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmotion.py
executable file
·54 lines (48 loc) · 1.54 KB
/
motion.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import RPi.GPIO as GPIO
from time import sleep
from ISStreamer.Streamer import Streamer
# Tell the Pi we're going to use it's numbering system
GPIO.setmode(GPIO.BCM)
# Pin that D1 is connected to
PIN=23
# Specify our pin as input
GPIO.setup(PIN,GPIO.IN)
# Initial State bucket name (displayed)
BUCKET_NAME = ":wave: Motion Sensor"
# Initial State bucket key (hidden)
BUCKET_KEY = "pizerowmotion"
# Initial State access key
ACCESS_KEY = "Your_Access_Key_Here"
# Variables that ensure we don't stream "Motion Detected" or "No Motion" twice in a row
# This saves on sent events and processing power
alreadyRecordedMotion = False
alreadyRecordedNoMotion = False
# Initialize the Initial State Streamer
streamer = Streamer(bucket_name=BUCKET_NAME, bucket_key=BUCKET_KEY, access_key=ACCESS_KEY)
# Loop indefinitely
while True:
# If the motion sensor pulls high (detects motion):
if GPIO.input(PIN) == 1:
print "Motion detected"
# If we haven't streamed yet:
if not alreadyRecordedMotion:
# Stream to Initial State
streamer.log(":spy: Anybody Around?",":runner: Motion Detected")
streamer.flush()
alreadyRecordedMotion = True
alreadyRecordedNoMotion = False
else:
# Pause the script for 1 second
sleep(1)
else:
print "No motion detected"
# If we haven't streamed yet:
if not alreadyRecordedNoMotion:
# Stream to Initial State
streamer.log(":spy: Anybody Around?",":no_pedestrians: No Motion")
streamer.flush()
alreadyRecordedNoMotion = True
alreadyRecordedMotion = False
else:
# Pause the script for 1 second
sleep(1)