Skip to content

Commit 7fc3534

Browse files
created example of code
1 parent 0325128 commit 7fc3534

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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 = "EOProduct"
32+
subject = "dataModel.SatelliteImagery"
33+
cloudCoverage = {'type': 'Property', 'value': 19.125499, 'unitCode': 'P1'}
34+
attribute = "cloudCoverage"
35+
value = cloudCoverage
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+
ingestionDate = "{'type': 'Property', 'value': {'@type': 'DateTime', '@value': '2021-01-18T18:29:16.884Z'}}"
40+
attribute = "ingestionDate"
41+
value = ingestionDate
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+
orbitDirection = "{'type': 'Property', 'value': 'Descending'}"
46+
attribute = "orbitDirection"
47+
value = orbitDirection
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+
orbitNumber = {'type': 'Property', 'value': 93}
52+
attribute = "orbitNumber"
53+
value = orbitNumber
54+
# 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
55+
print(sdm.update_broker(dataModel, subject, attribute, value, serverUrl=serverUrl, updateThenCreate=True))
56+
57+
print(" In case you have installed the orion-ld broker (see comments on the header of this program)")
58+
print(" Execute this instruction to check that the entities has been inserted")
59+
command = ['curl', '-X', 'GET', 'http://localhost:1026/ngsi-ld/v1/entities?local=true&limit=1000']
60+
result = subprocess.run(command, capture_output=True, text=True)
61+
print(result.stdout)

0 commit comments

Comments
 (0)