-
Notifications
You must be signed in to change notification settings - Fork 0
/
webservice.py
37 lines (30 loc) · 1.37 KB
/
webservice.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
# Fall detector webservice
#
# Kim Salmi, kim.salmi(at)iki(dot)fi
# http://tunn.us/arduino/falldetector.php
# License: GPLv3
import requests
import json
class Webservice():
def __init__(self):
# set api url and request token
self.url = 'https://us-central1-urgence-7232b.cloudfunctions.net/api/v1/'
self.headers = {'Authorization': 'Bearer 2c19b8e18579401fb1d4032b8d1b3ad6',
'Content-Type': 'application/json'}
self.data = ''
def alarm(self, device_id, image_binary):
payload = {'device_id': device_id, 'image_binary': image_binary}
response = requests.post(
self.url + 'camera', data=json.dumps(payload), headers=self.headers) # use json.dumps to send data in json format
print(response)
print ''
def checkVersion(self, device_id):
payload = {'device_id': device_id}
response = requests.post(
self.url + 'version', data=json.dumps(payload), headers=self.headers) # use json.dumps to send data in json format
return response.json()
def updateVersion(self, device_id, version_id):
payload = {'device_id': device_id, 'version_id': version_id}
response = requests.post(
self.url + 'updated', data=json.dumps(payload), headers=self.headers) # use json.dumps to send data in json format
return response.json()