|
| 1 | +# This code allows you to install a orion-ld broker in a linux system |
| 2 | +# The manuals are here https://github.com/FIWARE/context.Orion-LD/tree/develop/doc/manuals-ld |
| 3 | +# |
| 4 | +# INSTALL NGSI LD broker (OrionLD) |
| 5 | +# sudo docker pull mongo:3.6 |
| 6 | +# sudo docker pull fiware/orion-ld |
| 7 | +# sudo docker network create fiware_default |
| 8 | +# sudo docker run -d --name=mongo-db --network=fiware_default --expose=27017 mongo:3.6 --bind_ip_all --smallfiles |
| 9 | +# sudo docker run -d --name fiware-orionld -h orion --network=fiware_default -p 1026:1026 fiware/orion-ld -dbhost mongo-db |
| 10 | +# |
| 11 | +# TO RELAUNCH (only if you have already installed a broker in the same machine) |
| 12 | +# sudo docker stop fiware-orionld |
| 13 | +# sudo docker rm fiware-orionld |
| 14 | +# sudo docker stop mongo-db |
| 15 | +# sudo docker rm mongo-db |
| 16 | +# sudo docker network rm fiware_default |
| 17 | +# |
| 18 | +# CHECK INSTANCES |
| 19 | +# curl -X GET 'http://localhost:1026/version' |
| 20 | +# curl -X GET http://localhost:1026/ngsi-ld/v1/entities?local=true&limit=1000 |
| 21 | +# |
| 22 | +# now the python code you can use to insert some value in the context broker |
| 23 | + |
| 24 | +from pysmartdatamodels import pysmartdatamodels as sdm |
| 25 | +import subprocess |
| 26 | +serverUrl = "http://localhost:1026" # Edit to match your broker configuration |
| 27 | +dataModel = "OSMAeroway" |
| 28 | +subject = "dataModel.OpenStreetMap" |
| 29 | + |
| 30 | +osmId = 123123123 |
| 31 | +attribute = "osmId" |
| 32 | +value = osmId |
| 33 | +# Updates the attribute in the broker; creates the entity if it does not exist |
| 34 | +print(sdm.update_broker(dataModel, subject, attribute, value, serverUrl=serverUrl, updateThenCreate=True)) |
| 35 | + |
| 36 | +osmType = "way" |
| 37 | +attribute = "osmType" |
| 38 | +value = osmType |
| 39 | +# Updates the attribute in the broker; creates the entity if it does not exist |
| 40 | +print(sdm.update_broker(dataModel, subject, attribute, value, serverUrl=serverUrl, updateThenCreate=True)) |
| 41 | + |
| 42 | +osmLastModified = "2024-03-12T08:00:00Z" |
| 43 | +attribute = "osmLastModified" |
| 44 | +value = osmLastModified |
| 45 | +# Updates the attribute in the broker; creates the entity if it does not exist |
| 46 | +print(sdm.update_broker(dataModel, subject, attribute, value, serverUrl=serverUrl, updateThenCreate=True)) |
| 47 | + |
| 48 | +print("In case you have installed the orion-ld broker (see header comments)") |
| 49 | +print("Execute this to check the entity was inserted:") |
| 50 | +command = ['curl', '-X', 'GET', 'http://localhost:1026/ngsi-ld/v1/entities?local=true&limit=1000'] |
| 51 | +result = subprocess.run(command, capture_output=True, text=True) |
| 52 | +print(result.stdout) |
0 commit comments