-
Notifications
You must be signed in to change notification settings - Fork 1
/
ping-photo-test.py
executable file
·39 lines (29 loc) · 1.03 KB
/
ping-photo-test.py
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
#!/usr/bin/python
import picamera
import requests
from datetime import datetime
import calendar
import time
import os
# epochtime = calendar.timegm(time.gmtime())
# print epochtime
count = 0
camera = picamera.PiCamera()
camera.capture("image.jpeg")
while (count < 20):
timestamp = datetime.now()
print timestamp
# Send ping request to a host, this example uses google
hostname = "google.com"
response = os.popen("ping -c 1 " + hostname).read()
# Parse data to retrieve response time in ms
ping_time = response.split("time=")[1].split(" ms")[0]
print ping_time + " ms"
headers = {'Accept': 'application/json'}
r = requests.post("http://192.168.1.14:3000/events/create", data={"api_key":"NR71J65VHMH5WZ26A1K4", "sensor_id": 19, "value":ping_time, "notified":"false", "capture_time":timestamp}, files={'photo': ('image,jpeg', open('image.jpeg','rb'), 'image/jpeg')}, headers=headers)
print(r.status_code, r.reason)
print(r.encoding)
print(r.text[:10000] + '...')
count = count + 1
time.sleep(40)
print "Finished"