Saturday, October 15, 2016

Internet of Things (IoT): Raspberry Pi + DS18B20 + Eclipse KURA + Mosquitto + Eclipse Paho MQTT—PART 3

Next to complete our environment, we set up an MQTT message broker: Eclipse Mosquitto, on a our development machine or even on a separate machine. There are some publicly available message brokers as well, for example, there is one instance of Mosquitto by Eclipse. IBM Bluemix also includes an instance of MQTT broker.

So Eclipse Kura running on Raspberry Pi, will read the temperature from DS18B20 and sends the data as MQTT message to the broker , MQTT clients, which have subscribed for the topic of the message, will receive the data. Following link describes MQTT and provides a good basic understanding.


MQTT primarily belongs Machine to Machine communication and was specifically developed for the purpose, its reliable and resource efficient. I found following resource about the preference of MQTT for Internet of Things (IoT) projects:


Since I am working on Ubuntu I just had to do sudo apt-get install mosquitto to install Mosquitto, that’s it!! There are installers for other OSes here: https://mosquitto.org/download/

In my case on Ubuntu, I created a password file under /etc/mosquitto/ using following command:

sudo mosquito_passwd -c mosquito.pwd user_name

This user is used to configure Eclipse Kura

I also set ‘Protocol’ in /etc/mosquitto/mosquitto.conf as following:

protocol mqtt

Try to run Mosquitto using the following comment:

mosquito -c /etc/mosquitto/mosquitto.conf

If it runs fine, you should a similar output as following:

1476551631: mosquitto version 1.4.8 (build date Fri, 19 Feb 2016 12:03:16 +0100) starting
1476551631: Config loaded from mosquitto.conf.
1476551631: Opening ipv4 listen socket on port 9001.
1476551631: Opening ipv6 listen socket on port 9001.
1476551631: Opening ipv4 listen socket on port 1883.
1476551631: Opening ipv6 listen socket on port 1883.

Next we need to configure Eclipse Kura with Mosquitto, instructions for doing so can be found on the following link:

Wednesday, October 12, 2016

Internet of Things (IoT): Raspberry Pi + DS18B20 + Eclipse KURA + Mosquitto + Eclipse Paho MQTT-P2

Next we do Eclipse Kura. For an introduction of Eclipse, check following link:


Eclipse Kura is an OSGi based IoT gateway framework, in our case since Raspberry Pi will be acting as Gateway, therefore, we will install Eclipse Kura on Raspberry Pi. Different versions of Kura have been classified based on Raspberry Pi model. In my case, I chose Raspbian (Model B+).

Notice that another classification is Non-Net and Net(Not having Non-Net as part of those name). Net version provides the facilities to configure the network setting of the gateway device where Kura is running. I first tried Net version and I lost all my network configuration on Raspberry Pi which I didn’t want, so I tried Non-Net version that worked for me and is still running successfully.
In my case I chose Raspbian Model B+ No Net Stable.
Use following link to choose and download a suitable version.

The steps for installing Eclipse Kura on Raspberry Pi are listed on the following link, follow all the steps as it is, however, use the debian package downloaded from the above link:


If everything goes fine , you should be able to access Kura through browser at http://127.0.0.1:8080 if Raspberry Pi has display. Externally it may be accessed in browser using RasPi’s ip address (on default porti.e. no port required), for example, in my case it was 192.168.1.103.

To develop applications to run on Kura Framework, we need to set up the development environment. Eclipse Kura provides an workspace which contain all the necessary components required. Please see the following link for details:


There are some tutorials with example applications e.g. HelloWorld Example, Configurable Application. One called Deploying Bundles describes how to install the application (in OSGi terminology called Bundle) on target device in our case its Raspberry Pi.

There is one more tutorial on the same page called Publishing Application, it describes the a demo Application: Heater, its actually this application’s code we will use for our working setup. Pay special attention to this: http://eclipse.github.io/kura/doc/heater_demo.html

Sunday, October 9, 2016

Internet of Things (IoT): Raspberry Pi + DS18B20 + Eclipse KURA + Mosquitto + Eclipse Paho MQTT-P1

These posts describe a working set-up of following component:
  • Raspberry Pi 3
  • DS18B20 (1-Wire Digital Temperature Sensor)
  • Eclipse Kura (Eclipse Project: Framework for IoT Gateway)
  • Eclipse Mosquitto (Message Broker for MQTT)
  • Eclipse Paho MQTT (Eclipse Project: MQTT Client)

The post primarily discusses how to make above components work, however, we will try to provide the relevant resources throughout the posts.


We start off with connecting DS18B20 and Raspberry Pi, there are a number of online resources which helps to understand 1-wire sensor and how to connect them to Raspberry Pi, following are the two which I used:



Above links explains it in a detailed way, we instead look at another issue: in some cases, we come across an error when following command is executed: (discussed on the above links)

cat w1_slave

Error: w1_slave: No such file or directory

Generally when sensor is connected successfully and is working properly, upon executing following commands:

cd /sys/bus/w1/devices/
ls

The list should show your sensor(s) as a directory with its name starting with ‘28-’, the name itself is a combination of characters and numbers. I experienced that in situations where sensor is not correctly working in fact not connected properly, the sensor directory name is although, a combination of characters and numbers but doesn’t start with ‘28-’. In these situation command: cat w1_slave returns the above error.

The source of the error, as mentioned earlier, could be incorrect connections, connecting wires not working properly, incorrect GPIO connections (Caution: As always be careful with GPIO connections).

I have attached some images from my working set-up below. I used 10K ohm resistor in my setup and Dallas Digital 1-Wire Temperature sensor.