Skip to content

Commit

Permalink
Add function startSensor() to pir. Call in wifi-checker when RPi conn…
Browse files Browse the repository at this point in the history
…ected to WiFi + update cron jobs to call wifi-checker instead
  • Loading branch information
nenoch committed Sep 16, 2017
1 parent 0818935 commit 4746d36
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
27 changes: 14 additions & 13 deletions pir.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@
import json
import requests

pir = MotionSensor(4)
webhook_url = 'https://hooks.slack.com/services/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'
json_text = {'text':'Door :door: is open :open_hands:!'}

while True:
print('Running')
if pir.motion_detected:
print('motion detected...')
response = requests.post(
webhook_url, data=json.dumps(json_text),
headers={'Content-Type':'application/json'})
if response.status_code != 200:
print('Request to slack returned an error %s' % (response.status_code))
exit()
def startSensor():
pir = MotionSensor(4)
webhook_url = 'https://hooks.slack.com/services/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'
json_text = {'text':'Door :door: is open :open_hands:!'}

while True:
if pir.motion_detected:
print('motion detected...')
response = requests.post(
webhook_url, data=json.dumps(json_text),
headers={'Content-Type':'application/json'})
if response.status_code != 200:
print('Request to slack returned an error %s' % (response.status_code))
exit()
Binary file added pir.pyc
Binary file not shown.
4 changes: 2 additions & 2 deletions wifi-checker.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pir
import urllib2
import pir

while True:
try:
Expand All @@ -8,5 +8,5 @@
print('Not Connected yet')
else:
print('Connected to WiFi')
pir
pir.startSensor()
exit()

0 comments on commit 4746d36

Please sign in to comment.