-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsys.py
More file actions
executable file
·54 lines (43 loc) · 1.41 KB
/
Copy pathsys.py
File metadata and controls
executable file
·54 lines (43 loc) · 1.41 KB
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
#!/usr/bin/python
import io
import time
import base64
import picamera
import requests
import json
import RPi.GPIO as GPIO ## Import GPIO library
PIR=11
GPIO.setmode(GPIO.BOARD) ## Use board pin numbering
#GPIO.setup(LED, GPIO.OUT, initial=GPIO.HIGH) ## Setup GPIO Pin 7 to OUT
#GPIO.output(LED,True) ## Turn on GPIO pin 7
GPIO.setup(PIR, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
#Callback
def pir_callback(channel):
print "Rising edge detected on: " + str(PIR) + "\n"
with picamera.PiCamera() as camera:
camera.vflip = True
camera.hflip= True
camera.led = True
camera.capture('image.jpg')
#Camera.led = False
camera.close()
print 'Closed Cam'
with open('image.jpg', 'r+b') as myIm:
encoded_string = base64.b64encode(myIm.read())
print 'Finished encode'
url = 'http://securipi.roscorcoran.com/api/images'
payload = {'title': 'tada', 'data': encoded_string}
headers = {'content-type': 'application/json'}
print 'making request'
r = requests.post(url, data=json.dumps(payload), headers=headers)
print(r.text)
GPIO.add_event_detect(PIR, GPIO.RISING, callback=pir_callback, bouncetime=300)
try:
print("Wating for {}".format(PIR))
#GPIO.wait_for_edge(9, GPIO.RISING)
#input("Press Enter to continue...")
raw_input("press enter to exit ;)")
except KeyboardInterrupt:
print("KB")
#GPIO.cleanup() # clean up GPIO on CTRL+C exit
GPIO.cleanup() # clean up GPIO on normal exit