Created
July 22, 2015 01:13
-
-
Save trianglegrrl/eec5f2a897a1fafa848c to your computer and use it in GitHub Desktop.
SU GSP NCS PIR WTF
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import RPi.GPIO | |
import os | |
import time | |
from pyslack import SlackClient | |
import requests | |
import json | |
import string | |
url = "https://hooks.slack.com/services/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" | |
RPi.GPIO.setmode(RPi.GPIO.BCM) | |
RPi.GPIO.setup(4, RPi.GPIO.IN, pull_up_down=RPi.GPIO.PUD_DOWN) | |
current_movement = RPi.GPIO.LOW | |
headers = {'content-type': 'application/json'} | |
while True: | |
movement_sensed = RPi.GPIO.input(4) == RPi.GPIO.HIGH | |
if movement_sensed != current_movement: | |
if movement_sensed: | |
message = "Movement sensed" | |
else: | |
message = "Movement has stopped" | |
payload = { "text": message } | |
response = requests.post(url, data=json.dumps(payload), headers=headers) | |
current_movement = movement_sensed |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment