For the creation of a smart city bus application, one of the requirements is for the application to be able to provide the location of the bus at all times. Can we create an application in python that simulates the movement of a bus ( in order to create virtual "real time" data), passes that information to an Orion-LD broker and then validate our "architecture" by creating another application that utilizes the location data?
Hmmm it looks like it is something complicated at first but it really isn't, lets get through the various steps of this process together.
NOTE! I assume that there already is a local Orion-LD broker installed at your machine, if you don't know how to have a local deployment please check the following section Orion-LD Installation Guide
Our first step should be to create an appropriate ngsi-ld data model for our bus.
(Or as I said in previous sections of this guide there is no need to reinvent the wheel, lets see if there is an existing data model that covers our needs :) )
Searching through the
<aside> 🕸️ https://smartdatamodels.org/
</aside>
website we find the following data model:
Opening the specification of the vehicle's data model, we find out that it has more than enough attributes to cover our needs. (Since we are doing an experimental virtual bus using only the location as relevant information, in reallity we care about minimal attributes for our bus).
An example of using the data model to represent our virtual bus is:
{
"id": "urn:ngsi-ld:Vehicle:Ioannina:Transportation:SmartCityBus:02",
"type": "Vehicle",
"category": {
"type": "Property",
"value": [
"public"
]
},
"vehicleType": {
"type": "Property",
"value": "bus"
},
"location": {
"type": "GeoProperty",
"value": {
"type": "Point",
"coordinates": [
20.725502013694,
39.706477052908
]
},
"observedAt": "2018-09-27T12:00:00Z"
},
"serviceProvided": {
"type": "Property",
"value": [
"urbanTransit"
]
},
"@context": [
"<https://smartdatamodels.org/context.jsonld>",
"<https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context.jsonld>"
]
}
(The urn can be generated with the urn-generator tool provided at Useful Tools section)
The location attribute's starting value is irrelevant since it is going to be replaced with a proper location at the first "GPS ping". It is more correct however if the location used to create the bus is the true starting location of the bus, as to not confuse the person who analyzes the historical data.
Now we are ready to create the vehicle entity in the broker.