Page tree
Skip to end of metadata
Go to start of metadata

Docker is a container tool which provides kernel level virtualization for Linux. LinkSmart® project already has IoT Data-Processing Agent container image in a registry, ready to run. This tutorial aims to help with getting started using Docker.

If you are already familiar with the project, you can just run it with docker-compose without going through the rest of the steps.

Quick start with docker-compose
# Download the compose file
curl -o docker-compose.yml

# Running
docker-compose up

1) MQTT Broker

First, an up and running MQTT Broker is required:

Run Broker
docker run -d  --name mqtt-broker -p 1883:1883 -p 9001:9001 eclipse-mosquitto

2) Data-Processing Agent

Now we can run the agent linking to the broker. Environment variables can be set to configure the agent.

docker run -d --name agent -p 8319:8319 --link mqtt-broker -e "connection_broker_mqtt_hostname=mqtt-broker" -e "api_events_mqtt_topic_incoming_Observation=/testing/#" linksmart/agent:latest

Here the agent is configured to connect to mqtt-broker container by setting connection_broker_mqtt_hostname variable. It is also subscribed to OGC SensorThings Observation messages for /testing/# topic coming to the broker. (see the default configuration file for all parameters).

Since the REST API is exposed to the host machine, REST endpoints can be called from the host machine. The API documentation with an UI is hosted on localhost:8319/swagger-ui.html. You can go ahead and try it out on your browser.

3) Using the agent

We are going to publish some dummy messages to mqtt-broker in order to demonstrate data-processing capabilities:

Publishing dummy messages
docker run -d --name mqtt-client --link mqtt-broker aksakalli/mqtt-client publish

The same container will be also used to show all messages (topic #) arriving to the MQTT broker with this command:

Using mosquitto clients
docker exec -it mqtt-client sub -t "#" -h mqtt-broker -v

After that, this terminal session will start to receive demo OGC SensorThings Observation messages like:

OGC SensonrThing:Observation Example

Let's open a new terminal to add a new statement in order to get a number of messages arriving to MQTT broker in last 60 seconds.

Using Mosquitto clients
curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{
  "statement": "select count(*) from Observation().win:time(60 sec)"
}' 'http://localhost:8319/statement/'

After inserting this query, the agent will start to publish the query result to the broker as the following format:

OGC SensonrThing:Observation Example
  "": "40c86297-2421-4e54-9a2e-5fef2f300e6e",
  "featureOfInterest": {
    "": "6c35493a2b937829c9815c39e23af964bc84e5430a7dc104c700bbc0de2b59e3",
    "description": "count(*)",
    "observations": [{}, {}],
    "@iot.selfLink": "",
    "Observations@iot.navigationLink": "FeatureOfInterest(6c35493a2b937829c9815c39e23af964bc84e5430a7dc104c700bbc0de2b59e3)/Observations"
  "datastream": {
    "": "276f2948-c252-491b-9b93-8268383fdd92",
    "observations": [{}],
    "sensor": {
      "": "276f2948-c252-491b-9b93-8268383fdd92",
      "datastreams": [{}],
      "@iot.selfLink": "",
      "Datastreams@iot.navigationLink": "Sensor(276f2948-c252-491b-9b93-8268383fdd92)/Datastreams"
    "thing": {
      "": "276f2948-c252-491b-9b93-8268383fdd92",
      "datastreams": [{}],
      "@iot.selfLink": "",
      "Datastreams@iot.navigationLink": "Thing(276f2948-c252-491b-9b93-8268383fdd92)/Datastreams",
      "HistoricalLocations@iot.navigationLink": "Thing(276f2948-c252-491b-9b93-8268383fdd92)/HistoricalLocations",
      "Locations@iot.navigationLink": "Thing(276f2948-c252-491b-9b93-8268383fdd92)/Locations"
    "@iot.selfLink": "",
    "Observations@iot.navigationLink": "Datastream(276f2948-c252-491b-9b93-8268383fdd92)/Observations",
    "Sensor@iot.navigationLink": "Datastream(276f2948-c252-491b-9b93-8268383fdd92)/Sensor",
    "ObservedProperty@iot.navigationLink": "Datastream(276f2948-c252-491b-9b93-8268383fdd92)/ObservedProperty",
    "Thing@iot.navigationLink": "Datastream(276f2948-c252-491b-9b93-8268383fdd92)/Thing"
  "phenomenonTime": "2017-08-17T16:17:35.919+0000",
  "result": 120,
  "@iot.selfLink": "",
  "FeatureOfInterest@iot.navigationLink": "Observation(40c86297-2421-4e54-9a2e-5fef2f300e6e)/FeatureOfInterest",
  "Datastream@iot.navigationLink": "Observation(40c86297-2421-4e54-9a2e-5fef2f300e6e)/Datastream"

The result which is published for the statement is 120. It is also possible to access all statement objects over the rest API:

Using mosquitto clients
curl -X GET --header 'Accept: application/json' 'http://localhost:8319/statement/'

  • No labels