Skip to content

Commit 5e84eac

Browse files
created example of code
1 parent 498a0ba commit 5e84eac

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
2+
# # This code allows you to install a orion-ld broker in a linux system
3+
# # The manuals are here https://github.com/FIWARE/context.Orion-LD/tree/develop/doc/manuals-ld
4+
#
5+
# # INSTALL NGSI LD broker (OrionLD)
6+
# sudo docker pull mongo:3.6
7+
# sudo docker pull fiware/orion-ld
8+
# sudo docker network create fiware_default
9+
# sudo docker run -d --name=mongo-db --network=fiware_default --expose=27017 mongo:3.6 --bind_ip_all --smallfiles
10+
# sudo docker run -d --name fiware-orionld -h orion --network=fiware_default -p 1026:1026 fiware/orion-ld -dbhost mongo-db
11+
#
12+
# # TO RELAUNCH (only if you have already installed a broker in the same machine)
13+
# sudo docker stop fiware-orionld
14+
# sudo docker rm fiware-orionld
15+
# sudo docker stop mongo-db
16+
# sudo docker rm mongo-db
17+
# sudo docker network rm fiware_default
18+
#
19+
# # CHECK INSTANCES
20+
# # Check the broker is running
21+
# curl -X GET 'http://localhost:1026/version'
22+
#
23+
# # Check what entities are in the broker
24+
# curl -X GET http://localhost:1026/ngsi-ld/v1/entities?local=true&limit=1000
25+
#
26+
# # now the python code you can use to insert some value in the context broker according to the data model
27+
#
28+
from pysmartdatamodels import pysmartdatamodels as sdm
29+
import subprocess
30+
serverUrl = "http://localhost:1026" # supposed that your broker is installed in localhost. Edit to match your configuration
31+
dataModel = "BuildingType"
32+
subject = "dataModel.Building"
33+
buildingTypeChildren = {'type': 'Relationship', 'object': ['urn:ngsi-ld:BuildingType:e4291e84-58f8-11e8-84c3-77e4f1f8c4f1', 'urn:ngsi-ld:BuildingType:a71c7a08-58f9-11e8-a41e-4bcb7249360e', 'urn:ngsi-ld:BuildingType:afac9bbc-58f9-11e8-b587-1f0d57b81bb4']}
34+
attribute = "buildingTypeChildren"
35+
value = buildingTypeChildren
36+
# The next line creates the query for inserting this attribute in a NGSI-LD context broker if the attribute does not exist it creates it
37+
print(sdm.update_broker(dataModel, subject, attribute, value, serverUrl=serverUrl, updateThenCreate=True))
38+
39+
buildingTypeParent = "{'type': 'Relationship', 'object': 'urn:ngsi-ld:BuildingType:4146335f-839f-4ff9-a575-6b4e6232b734'}"
40+
attribute = "buildingTypeParent"
41+
value = buildingTypeParent
42+
# The next line creates the query for inserting this attribute in a NGSI-LD context broker if the attribute does not exist it creates it
43+
print(sdm.update_broker(dataModel, subject, attribute, value, serverUrl=serverUrl, updateThenCreate=True))
44+
45+
root = {'type': 'Property', 'value': False}
46+
attribute = "root"
47+
value = root
48+
# The next line creates the query for inserting this attribute in a NGSI-LD context broker if the attribute does not exist it creates it
49+
print(sdm.update_broker(dataModel, subject, attribute, value, serverUrl=serverUrl, updateThenCreate=True))
50+
51+
print(" In case you have installed the orion-ld broker (see comments on the header of this program)")
52+
print(" Execute this instruction to check that the entities has been inserted")
53+
command = ['curl', '-X', 'GET', 'http://localhost:1026/ngsi-ld/v1/entities?local=true&limit=1000']
54+
result = subprocess.run(command, capture_output=True, text=True)
55+
print(result.stdout)

0 commit comments

Comments
 (0)