Tutorial: Configurable Kura Application

Wiring of LED to a Raspberry Pi

Summary. This tutorial explains how to build a Kura application into a bundle using Reactive Blocks. Then, the bundle is deployed on a Raspberry Pi and also configured.

Kura is an Eclipse project which provides an OSGi-based container for IoT applications running in service gateways. It provides API for configuration, communication, etc.

Learn more about Kura on the project’s website: http://www.eclipse.org/kura.

Required Hardware:

  • Raspberry Pi Model B or B+
  • ethernet cable
  • 1 LED
  • 1 resistor
  • jumpers and breadboard to connect the LED and resistor to the Pi via GPIO pin #16 as shown in the figure below

Wiring of LED to a Raspberry Pi

See for example here to find out how to connect a LED to a Raspberry Pi via a breadboard.

Recommeded:

  • Some familiarity with Reactive Blocks to get the most out of this tutorial.
  • Read Configuration with Kura article which gives a general introduction about configuration with Kura.

Raspberry Pi Setup

The first time you boot your Raspberry Pi, you need to set it up. If a monitor is connected to the Pi, the Raspberry Pi configuration menu is opened automatically. If you login to the Pi via ssh (default username and password are pi/raspberry), run the command sudo raspi-config.

Raspberry Pi Configuration

  • To utilize all your SD card, choose 1 Expand Filesystem.
  • Choose Finish and reboot the Pi by, e.g., use the command sudo reboot.
  • Install Kura on the Raspberry Pi as described here.
  • Open a web browser and type in the IP address of your Raspberry Pi. The Kura’s web console will be opened after you login. The default username and password are admin/admin.

Let us connect the Raspberry Pi to an MQTT broker.

  • Choose MqttDataTransport section on the left menu, change the broker-url to mqtt://blocks2.bitreactive.com:1883/

Set MQTT Broker URL

  • Choose DataService section and set connect.auto-on-startup to true

After a while, you should see that the Pi is connected to the on the Status section.

Connected to an MQTT Broker

Development Setup

The Application

You can create a (configurable) Kura application as described here. However, in this tutorial we will use an existing example application.

  • Import the example project (Level 3) Kura Configuration Example
  • Open the application block Kura Demo

Kura Configuration Example

This is a simple example that toggles a LED and publish the LED state using MQTT.

  • The block Lamp represents the LED. It can receive toggle commands and emits the state of the LED after each toggle command.
  • The block Periodic Toggler emits the commad to toggle LED every some milliseconds.
  • The block Publisher sends the state of the LED to an MQTT broker.
  • The block Termination listens for termination signal from the OSGi framework so that used resources can be released before the application terminates.

Configurable Properties

When looking inside block Periodic Toggler or block Publisher you will see that both contain block Config Listener 2.

  • Config Listener 2 is listening to changes of properties and emits these as Map. This makes it easy to react to changes within the application.
  • Periodic Toggler will react to changes of toggle.duration.
  • Publisher will react to changes of publish.topic

These properties are defined as metatypes in an XML file. The file is created for each system block of type Kura Application with Configuration and can be found in the OSGI-INF/metatype directory of the project. When running on Kura, this configuration will be picked up by the OSGi Metatype service. As developers, you specify the configuration properties of your application by modifying the XML file.

Build and Deploy

  • Building a Kura application is described here

You should get generated files in the project. Some files are also updated.

Building Kura Configurable Application

  • Right-click the deployment package definition file KuraDemo.dpp and select Quick Build to generate the deploymet package KuraDemo.dp.

  • Open the Kura’s web console of your Raspberry Pi.
  • Choose Packages section on the left menu.
  • Install the deployment pacakage KuraDemo.dp (not the dpp file!)
  • You might need to use the refresh button in order to see packages you installed.
  • The LED should start blinking every about five seconds.

Package Deployment on Kura

Debug

An easy way of finding out what is going on is looking at the log file. Log into the Raspberry Pi (for example using ssh) and type:

	tail -f /var/log/kura.log

You should see that the application is publishing messages.

Configure the Application

As described in the section Configurable Properties above, there are two properties in the example, namely toggle.duration and publish.topic

  • Open the Kura’s web console of your Raspberry Pi
  • Choose Kura Demo section on the left menu
  • You should see the two properties

Kura Demo Configure

  • Change toggle.duration to 10000 and click the button + Apply.
  • You should see that the LED is blinking slower.