orion2cartodb is Python script to parse NGSI Context Brokers (such as Orion) subscriptions and feed a CartoDB Map.
You can get Orion at: https://github.com/telefonicaid/fiware-orion
CartoDB is an open source cloud-based solution for showing maps on a website.
You can create an account at: http://cartodb.com/
orion2cartodb must be deployed on a server reachable by the Context Broker.
orion2cartodb is based on webapp2, please see https://webapp-improved.appspot.com for full details, so you will need to install the following dependences on your server:
$ pip install WebOb
$ pip install Paste
$ pip install webapp2
$ pip install pyyaml
Once webapp2 is installed, you must edit the orion2cartodb configuration file (orion2cartodb.yaml):
- orion2cartodb_host: your server IP address interface attached IP reachable by the Context Broker.
- orion2cartodb_port: your server port. Please remember that must be reachable from Context Broker.
- orion2cartodb_apikey: your private CartoDB API key.
Finally orion2cartodb is ready to be started:
$ python orion2cartodb
Please, consider using FIGWAY script UpdateEntityAttribute.py to update it, you find it at:
https://github.com/telefonicaid/fiware-figway/tree/master/python/ContextBroker
Anyway, you can create it on your own as follows:
POST [[HOST]/v1/subscribeContext][]
Accept: application/json
Fiware-Service: **your_service**
Content-Type: application/json
{
entities": [
{
"type": "device",
"isPattern": "false",
"id": "**your_entity**"
}
],
"attributes": [
"**attribute1**",
"**attribute2**"
],
"reference": "[your_machine_service]"
"duration": "P1M",
"notifyConditions": [
{
"type": "ONCHANGE",
"condValues": [
"**attribute1**",
"**attribute2**"
]
}
],
"throttling": "PT1S"
}
Based on the subscription, a table will be generated introducing the attributes and their values as column name and value (for each of the assets) respectively. When a new attribute is added within the subscription, a new column will be appended to the table, and the previous values for the new attribute will be considered null in the previous assets.
Please, consider using FIGWAY script SetSubscription.py to create it, you find it at:
https://github.com/telefonicaid/fiware-figway/tree/master/python/ContextBroker
Anyway, you can update it on your own as follows:
POST [[HOST]/v1/updateContext][]
Accept: application/json
Fiware-Service: **your_service**
Content-Type: application/json
{
"contextElements": [
{
"type": "**your_type**",
"isPattern": "false",
"id": "**your_entity**",
"attributes": [
{
"name": "**your_attribute**",
"type": "**your_id**",
"value": "**your_value**"
}] }
],
"updateAction": "APPEND" }
If everything went well, you should see the attribute updates at the CartoDB data table.
- Your table will be named with your Orion FIWARE Service name. Please, do not change manually your table name, otherwise another table under the former name will be generated by default.