forked from wicket1001/IoT-Box
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathServerRequest.py
157 lines (133 loc) · 4.74 KB
/
ServerRequest.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
import requests
from requests.auth import HTTPBasicAuth
from credential import *
permission = False
def requiresHigherTrustLevel():
global permission
if permission:
permission = False
else:
raise PermissionError("Has to enable trust.")
def setHigherTrustLevel():
global permission
permission = True
#The first thing upon user login
def queryLoggedInUserAndCustomerList():
suffix = '/1/me'
return requests.get(url+suffix,auth=HTTPBasicAuth(cid, passwd))
#Manage a customer
def queryTheUsersCustomerList():
suffix = '/1/customers'
return requests.get(url+suffix,auth=HTTPBasicAuth(cid, passwd))
def addNewCustomer():
requiresHigherTrustLevel()
suffix = '/1/customers'
data = {
"name": "enter name",
"street": "enter street",
"city": "enter city",
"note": "enter note"
}
return requests.post(url + suffix, json=data, auth=HTTPBasicAuth(cid, passwd))
def queryCustomersProfile():
suffix = '/1/customers/' + cid
return requests.get(url + suffix, auth=HTTPBasicAuth(cid, passwd))
def modifyCustomerProfile():
requiresHigherTrustLevel()
suffix = '/1/customer' + cid
data = {"street": "enter street",
"city": "enter city",
"note": "enter note"
}
return requests.put(url + suffix, json=data, auth=HTTPBasicAuth(cid, passwd))
def sendEmailOnBehalfThisCustomer():
requiresHigherTrustLevel()
suffix = '/1/customer/' + cid + '/cn-sending/'
data = {"receivers": [
],
"subject": "Hi all - from rapidM2M!",
"body": "<html><h1>Hi all</h1>My first message sent via rapidM2M BACKEND API</html>"
}
return requests.post(url + suffix, json=data, auth=HTTPBasicAuth(cid, passwd))
def deleteCustomerAllHisSitesAndData():
suffix = '/1/customer'
return requests.get(url + suffix, auth=HTTPBasicAuth(cid, passwd))
def sendSMSBehalfThisCostumer():
requiresHigherTrustLevel()
suffix = '/1/costumer' + cid + '/cn-sendsms/'
data = {"receivers": [
"+4311111111",
"+4312222222"
],
"subject": "Hi all - from rapidM2M!"
}
return requests.post(url + suffix, json=data, auth=HTTPBasicAuth(cid, passwd))
#Manage a site
def queryCustomersListOfSites():
suffix = '/1/customers/' + cid + '/sites'
return requests.get(url + suffix, auth=HTTPBasicAuth(cid, passwd))
def querySitesBlueprint():
suffix = '/1/customers/' +cid + '/sites/' + sid + '/blueprint'
return requests.get(url + suffix, auth=HTTPBasicAuth(cid, passwd))
#Manage a device
#Sites status&configuration data
def querySitesConfiguration():
suffix = '/1/customers/' + cid + '/sites/' + sid + '/config0'
return requests.get(url + suffix, auth=HTTPBasicAuth(cid, passwd))
def modifySitesConfiguration():
requiresHigherTrustLevel()
suffix = '/1/customers/' + cid + '/sites/' + sid + '/config0'
data = {
"transmissionmode": 1,
"stamp": "20180217124628782"
# "BinaryField": "00ff44bc78"
}
return requests.put(url + suffix, json=data, auth=HTTPBasicAuth(cid, passwd))
#SitesTimeSeriesData
def queryYoungestRawValues():
suffix = '/1/customers/'+cid+'/sites/'+sid+'/histdata0/youngest'
data = {
"select": [
"Temperature",
"VoltageBattery",
"VoltageUSB"
]
}
return requests.get(url + suffix, json=data, auth=HTTPBasicAuth(cid, passwd))
def queryTimeWindowWithRawValues(): # TODO missing or invalid parameters
suffix = '/1/customers/' + cid + '/sites/' + sid + '/histdata0'
data = { "select": [
"ch0",
"ch3",
"ch1"
],
"from": "20150101",
"until": "*"
}
return requests.get(url + suffix, json=data, auth=HTTPBasicAuth(cid, passwd))
def insertNewValuesHistoricalDataChannel():
requiresHigherTrustLevel()
suffix = '/1/customers/' + cid + '/sites/' + sid +'/histdata0'
data = {
#"stamp": "201501011030",
"Temperature": 12,
"VoltageBattery": 4.5,
"VoltageUSB": 1.2
}
return requests.post(url + suffix, json=data, auth=HTTPBasicAuth(cid, passwd))
#Sites position data
def queryYoungestPositionValues():
suffix = '/1/customers/' + cid + '/sites/' + sid + '/pos/youngest'
return requests.get(url + suffix, auth=HTTPBasicAuth(cid, passwd))
#Manage users
def queryUserList():
suffix = '/1/users'
return requests.get(url + suffix, auth=HTTPBasicAuth(cid, passwd))
def queryCustomersUserList():
suffix = '/1/customers/' + cid + '/users/'
return requests.get(url + suffix, auth=HTTPBasicAuth(cid, passwd))
def queryUsersProfile():
suffix = '/1/customers/' + cid + '/users/'
return requests.get(url + suffix, auth=HTTPBasicAuth(cid, passwd))