-
Notifications
You must be signed in to change notification settings - Fork 0
/
register.py
54 lines (42 loc) · 1.56 KB
/
register.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
#!/usr/bin/python
import sys
import json
import urllib3
import base64
import pprint
import http.client
deviceId = '' # set uuid like d5494cc8-9c52-11ea-bb37-0242ac130002
url = '' # https://CLOUD.MYCLOUD.XYZ/index.php/apps/sensorlogger/api/v1/registerdevice/ -> NOTE: SLASH AT THE END is necessary
def registerDevice():
# Example extended registration config:
payload = {
'deviceId': deviceId,
'deviceName': 'Sensor#1',
'deviceType': 'IndoorTempHumid',
'deviceGroup': 'living room',
'deviceDataTypes': [
{
'type': 'temperature',
'description': 'Temperatur',
'unit': '°C'
},
{
'type': 'humidity_rel',
'description': 'rel. Luftfeuchtigkeit',
'unit': '% r.F.'
},
{
'type': 'dew_point',
'description': 'Taupunkt',
'unit': '°C'
}
]
}
encoded_body = json.dumps(payload)
http = urllib3.PoolManager()
credentials = '%s:%s' % ('USERNAME', 'DEVICE PASSWORD')
encoded_credentials = base64.b64encode(credentials.encode('ascii'))
r = http.request('POST', url, headers={'Content-Type': 'application/json', "Content-Security-Policy" : "default-src 'none';script-src 'self' 'unsafe-eval';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self';connect-src 'self';media-src 'self'", "Authorization" : "Basic %s" % encoded_credentials.decode('ascii')},
body=encoded_body)
print(r.data)
registerDevice()