Skip to content

Node.js script that periodically queries states of parking spots on 'Kiellinie' in Kiel and imports transformed data into Orion v2 and Orion LD context broker

License

Notifications You must be signed in to change notification settings

SmartMaaS-Services/kiel-parksensors

Repository files navigation

Smart MaaS
SMART MOBILITY SERVICE PLATFORM
Smart MaaS

ContactIssuesProject Page


kiel-parksensors


MIT license Support badge NGSI v2 NGSI-LD badge

Node.js script that periodically queries states of parking spots on "Kiellinie" in Kiel and imports transformed data both into FIWARE Orion v2 and FIWARE Orion-LD context broker. Optional storage of NGSI v2 time series data in a CrateDB via QuantumLeap API is also supported.

The Node.js script and the context brokers run in separated Docker containers which in turn are composed within the included Docker Compose files.

Important note: Unfortunately, the API key provided for querying the parking sensor data has been invalid since the end of June 2020 (as of 13 August 2020). You may be lucky and get a new one from the data provider Stadtwerke Kiel.

Content

Prerequisites

Docker and Docker Compose must be installed on your system in order to run the services defined in the multi-container file. Tests have been made with Docker version 18.09.7, build 2d0083d and docker-compose version 1.23.1, build b02f1306.

Operation modes

The project offers two different compose files. The first variant starts the Node.js script, both versions of the context brokers and components for persisting parking status data. In this mode (client-server mode), the retrieved parking data is stored in the context brokers of the local Docker containers and, if configured, persisted in the local CrateDB instance.

The second variant comprises a single service for the Node.js script. It acts as a client to context brokers running elsewhere (client mode).

Configuration

There is a configuration file config.env containing environment variables used by the Node.js script. Some of the variables values have to be modified prior to initial startup, as the script uses those variables for connection management and data processing.

The following list gives a summary of currently supported variables and their description:

Name Description Default value
Park Sensors Data Source
PARKSENSORS_BASE_URL

base URL (park sensors data source)

mandatory

https://element-iot.com/api/v1/tags/stadt-kiel-parksensorik-kiellinie
PARKSENSORS_API_KEY

API key (token for authenticaton)

mandatory

645a23ee6da141b6865fa68101c34ab7
PARKSENSORS_QUERY_INTERVAL

interval for querying park sensor states [seconds]

mandatory

60
NGSI v2 Context Broker
BROKER_V2_URL

NGSI v2 context broker URL

NOTE: modify ONLY, when communicating with external context brokers, e.g. when executing './services-app-only' which does NOT start any context broker!
If this broker should not be used, just set an empty value.

optional

http://orion-v2:1026
BROKER_V2_AUTH_KEY

Auth key for 'Authorization' header

optional

BROKER_V2_API_KEY

API key (token for authenticaton)

optional

BROKER_V2_TENANT

tenant name (a tenant is a service aka domain on the context broker with its own isolated logical database)

optional

kiel
BROKER_V2_SUBTENANT

sub-tenant name (a sub-tenant is a sub-service / service path aka project for the given tenant)

optional

/parkingspots
BROKER_V2_ENTITY_ID_SUFFIX

entity ID suffix (on creation will be appended to an entitys ID for a customized identification format, e.g. the ID suffix 'XY' for a ParkingSpot entity 'parksensor-2b2f' will result in 'ParkingSpot:parksensor-2b2f-XY')

optional

XY
NGSI-LD Context Broker
BROKER_LD_URL

NGSI-LD context broker URL

NOTE: modify ONLY, when communicating with external context brokers, e.g. when executing './services-app-only' which does NOT start any context broker!
If this broker should not be used, just set an empty value.

optional

http://orion-ld:1026
BROKER_LD_AUTH_KEY

Auth key for 'Authorization' header

optional

BROKER_LD_API_KEY

API key (token for authenticaton)

optional

BROKER_LD_TENANT

tenant name (a tenant is a service aka domain on the context broker with its own isolated logical database)

optional

kiel
BROKER_LD_SUBTENANT

sub-tenant name (a sub-tenant is a sub-service / service path aka project for the given tenant)

optional

/parkingspots
BROKER_LD_ENTITY_ID_SUFFIX

entity ID suffix (on creation will be appended to an entitys ID for a customized identification format, e.g. the ID suffix 'XY' for a ParkingSpot entity 'parksensor-2b2f' will result in 'urn:ngsi-ld:ParkingSpot:parksensor-2b2f-XY')

optional

XY
Historic data persistence
ENABLE_HISTORIC_DATA_STORAGE

enables storage of historic data (into Crate-DB via QuantumLeap API for now) - support for NGSI v2 data only

optional

true
QL_V2_NOTIFICATION_URL

QuantumLeap (QL) notification URL used for sending status changes of entities in the context broker

NOTE: modify ONLY, when communicating with external QL instances, e.g. when executing './services-app-only' which does NOT start any QL instance!
If historic data persistence via QL is not wanted, just set an empty value.

optional

http://quantumleap:8668
QL_V2_AUTH_KEY

Auth key for 'Authorization' header in requests to QL

optional

QL_V2_API_KEY

API key for authentication on QL

optional

QL_V2_TENANT

tenant name on QL

optional

kiel
QL_V2_SUBTENANT

sub-tenant name on QL

optional

/parkingspots

Starting Docker containers

Depending on what operation mode is preferred, pull/create the images and start containers by running ./services create && ./services start (client-server mode) or simply ./services-app-only start (client mode) from the project root folder.
To stop the containers run ./services[-app-only] stop.
If you encounter problems executing the service scripts, add the missing permission with chmod +x services*.

Reading data from context brokers

You can GET a list of all ParkingSpot entities using the following cURL commands. Don't forget to replace the <DOCKER_HOST> placeholders with the hostname / IP of your Docker host.
<DOCKER_HOST> assumes that you are running your own context brokers on the Docker host. If you are connecting to context brokers located elsewhere, use their hostname / IP address accordingly.

Orion v2

List all ParkingSpot entities containing only the 'id' attribute:

curl -X GET '<DOCKER_HOST>:1026/v2/entities?type=ParkingSpot&attrs=id&options=keyValues' \
  -H 'Accept: application/json'

List all ParkingSpot entities containing all attributes:

curl -X GET '<DOCKER_HOST>:1026/v2/entities?type=ParkingSpot&options=keyValues' \
  -H 'Accept: application/json'

Orion LD

List all ParkingSpot entities containing only the 'id' and 'name' attributes:

curl -X GET '<DOCKER_HOST>:1027/ngsi-ld/v1/entities?type=ParkingSpot&attrs=id,name&options=keyValues' \
  -H 'Accept: application/ld+json' \
  -H 'Link: <https://schema.lab.fiware.org/ld/context>; rel="http://www.w3.org/ns/json-ld#context"; type="application/ld+json"'

List all ParkingSpot entities containing all attributes:

curl -X GET '<DOCKER_HOST>:1027/ngsi-ld/v1/entities?type=ParkingSpot&options=keyValues' \
  -H 'Accept: application/ld+json' \
  -H 'Link: <https://schema.lab.fiware.org/ld/context>; rel="http://www.w3.org/ns/json-ld#context"; type="application/ld+json"'

History data

If historic data persistence was enabled, the Node.js script sends subscriptions for status changes of all known ParkingSpot entities to the NGSI v2 context broker. QuantumLeap, a REST service for storing, querying and retrieving spatial-temporal data, will receive a notification every time a status changes and stores its current value in a CrateDB database. With this data collected over time, statistical evaluations and data visualisation will be possible, e.g. building histograms with Grafana or UI widgets using WireCloud.

As QuantumLeap has no support for NGSI-LD yet, storage of historic data is supported for NGSI v2 data only.

The Docker container of CrateDB exposes 4200 as the default port for data queries and access to the web-based admin UI.
You can reach it at <DOCKER_HOST>:4200.

Troubleshooting

CrateDB service might crash shortly after startup due to incompatible memory settings.
With docker ps -a you can check whether its container is running or has already exited. In the latter case, inspecting the container log file with

sudo vi `docker inspect --format='{{.LogPath}}' kipark-db-crate`

should give you an output saying something like
max virtual memory areas vm.max_map_count [65530] likely too low, increase to at least [262144].

In order to avoid this, increase maximum number of memory map areas before starting:

sudo sysctl -w vm.max_map_count=262144

License

This project is licensed under MIT License.

About

Node.js script that periodically queries states of parking spots on 'Kiellinie' in Kiel and imports transformed data into Orion v2 and Orion LD context broker

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published