-
Notifications
You must be signed in to change notification settings - Fork 1
/
locations.py
73 lines (68 loc) · 1.81 KB
/
locations.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
import requests
import json
def data_populator(name,status,lng,lat,serial):
#example hostname:https://developer.cumulocity.com
urlmo="<<hostname>>"
da1={
"name":name,
"type":"c8y_Linux",
"c8y_IsDevice":{
},
"com_cumulocity_model_Agent":{
},
"com_softwareag_parkingpi_ParkingPiStatus": {
"status": status
},
"c8y_SupportedOperations":[
"c8y_RemoteAccessConnect",
"c8y_Restart",
"c8y_Firmware",
"c8y_Configuration",
"c8y_SoftwareList"
],
"c8y_Position":{
"lng":lng,
"lat":lat
},
"c8y_Hardware":{
"serialNumber":serial,
"model":"BCM2835",
"revision":"ma2018"
}
}
head={
"Content-Type": "application/json",
"Accept": "application/json",
}
s1=requests.post(urlmo,json=da1,auth=('<<username>>','<<password>>'),headers=head)
print(s1)
t=s1.json()
ids=t["id"]
return ids
def data_register(ids,exname):
#example hostname:https://developer.cumulocity.com
urlre="<<hostname>>/identity/globalIds/"+ids+"/externalIds"
da1={
"type" : "c8y_Serial",
"externalId" : exname
}
head={
"Content-Type": "application/json",
"Accept": "application/json",
}
s1=requests.post(urlre,json=da1,auth=('<<username>>','<<username>>'),headers=head)
print(s1)
with open("data.json") as c:
dumdata=json.load(c)
n=len(dumdata["devices"])
i=0
while i<n:
name=dumdata["devices"][i]["Name"]
status=dumdata["devices"][i]["status"]
exname=dumdata["devices"][i]["exname"]
lng=dumdata["devices"][i]["lng"]
lat=dumdata["devices"][i]["lat"]
serial=dumdata["devices"][i]["serial"]
ids=data_populator(name,status,lng,lat,serial)
data_register(ids,exname)
i+=1