diff --git a/UnmannedAerialVehicle/code/code_for_using_dataModel.UnmannedAerialVehicle_UnmannedAerialVehicle.py b/UnmannedAerialVehicle/code/code_for_using_dataModel.UnmannedAerialVehicle_UnmannedAerialVehicle.py index 7f880f7..673c36c 100644 --- a/UnmannedAerialVehicle/code/code_for_using_dataModel.UnmannedAerialVehicle_UnmannedAerialVehicle.py +++ b/UnmannedAerialVehicle/code/code_for_using_dataModel.UnmannedAerialVehicle_UnmannedAerialVehicle.py @@ -24,31 +24,36 @@ # curl -X GET http://localhost:1026/ngsi-ld/v1/entities?local=true&limit=1000 # # # now the python code you can use to insert some value in the context broker according to the data model +# # Version Warning! +# # This code is designed to work with the version 0.8 of pysmartdatamodels or later +# # to work with earlier version you need to replace the import instruction for +# # from pysmartdatamodels import pysmartdatamodels as sdm # -from pysmartdatamodels import pysmartdatamodels as sdm +# +import pysmartdatamodels as sdm import subprocess serverUrl = "http://localhost:1026" # supposed that your broker is installed in localhost. Edit to match your configuration dataModel = "UnmannedAerialVehicle" subject = "dataModel.UnmannedAerialVehicle" -uavModel = "{'type': 'Relationship', 'object': 'urn:ngsi-ld:UAVModel:23821045-33d4-46ec-b777-98f461bf4856'}" +uavModel = "urn:ngsi-ld:UAVModel:23821045-33d4-46ec-b777-98f461bf4856" attribute = "uavModel" value = uavModel # 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 print(sdm.update_broker(dataModel, subject, attribute, value, serverUrl=serverUrl, updateThenCreate=True)) -operator = {'type': 'Relationship', 'object': ['urn:ngsi-ld:Person:cdfd9cb8-ae2b-47cb-a43a-b9767ffd5c84', 'urn:ngsi-ld:Person:3d5f533e-5920-11e8-871b-534f1ae5f35d']} +operator = ['urn:ngsi-ld:Person:cdfd9cb8-ae2b-47cb-a43a-b9767ffd5c84', 'urn:ngsi-ld:Person:3d5f533e-5920-11e8-871b-534f1ae5f35d'] attribute = "operator" value = operator # 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 print(sdm.update_broker(dataModel, subject, attribute, value, serverUrl=serverUrl, updateThenCreate=True)) -operationMode = "{'type': 'Property', 'value': 'vlos'}" +operationMode = "vlos" attribute = "operationMode" value = operationMode # 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 print(sdm.update_broker(dataModel, subject, attribute, value, serverUrl=serverUrl, updateThenCreate=True)) -elevation = {'type': 'Property', 'value': 1000, 'unitCode': 'MTR'} +elevation = 1000 attribute = "elevation" value = elevation # 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