Skip to content

Instantly share code, notes, and snippets.

@trianglegrrl trianglegrrl/pir.py

Created Jul 22, 2015
Embed
What would you like to do?
SU GSP NCS PIR WTF
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
You can’t perform that action at this time.