-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmsg.py
More file actions
executable file
·55 lines (49 loc) · 1.29 KB
/
Copy pathmsg.py
File metadata and controls
executable file
·55 lines (49 loc) · 1.29 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
54
#!/usr/bin/python
import io
import time
import base64
import picamera
import requests
import json
import RPi.GPIO as GPIO
#Callback
def takeapic():
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'
files = {'file': open('image.jpg', 'r+b')}
#files = {'file': ('image', open('image.jpg', 'r+b'), 'image/JPEG', {'Expires': '0'})}
print 'Finished read'
#url = 'http://192.168.0.12:8080/api/images'
url = 'http://securipi.roscorcoran.com/api/images'
#payload = {'title': 'tada', 'data': encoded_string}
#Headers = {'content-type': 'image/JPEG'}
print 'making request'
r = requests.post(url, files=files)#, headers=headers)
print(r.text)
def msg():
print("Wating for msg")
msgurl = 'http://securipi.roscorcoran.com/api/control/pi'
#msgurl = 'http://192.168.0.12:8080/api/control/pi'
try:
r = requests.get(msgurl, timeout=600)
if r.text == 'takeapic':
takeapic()
msg()
except requests.exceptions.Timeout as e:
print e
msg()
except requests.exceptions.RequestException as e: # This is the correct syntax
print e
time.sleep(10)
msg()
try:
msg()
#input("Press Enter to continue...")
except KeyboardInterrupt:
print("KB")