Skip to content

Commit 78a3a5c

Browse files
created example of code
1 parent 960c308 commit 78a3a5c

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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 = "VibrationsObserved"
32+
subject = "dataModel.Building"
33+
accelerationMeasured = {'type': 'Property', 'value': 1.3}
34+
attribute = "accelerationMeasured"
35+
value = accelerationMeasured
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+
dateObserved = "{'type': 'Property', 'value': {'@type': 'DateTime', '@value': '2021-03-08T09:45:00Z'}}"
40+
attribute = "dateObserved"
41+
value = dateObserved
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+
print(" In case you have installed the orion-ld broker (see comments on the header of this program)")
46+
print(" Execute this instruction to check that the entities has been inserted")
47+
command = ['curl', '-X', 'GET', 'http://localhost:1026/ngsi-ld/v1/entities?local=true&limit=1000']
48+
result = subprocess.run(command, capture_output=True, text=True)
49+
print(result.stdout)

0 commit comments

Comments
 (0)