Building a Raspberry Pi based Smart Gateway for IoT

January 8, 2016

As described in my previous post, my intention is to create a new version of my IoT Demo.

The first element that I wanted to get up and running is the Gateway, which is supposed to run

  • a MQTT broker to receive and forward messages
  • a transformation capability to change messages, enable smart routing of messages, etc

As a feasibility approach and for demo purposes, I also decided to separate these two via Docker.

This Blog will describe in a step-by-step fashion on how to transform a Raspberry Pi 2 into a “Smart Gateway” to host the logic, which will follow in later steps.

Step 1: Install Raspian

I have decided to use Raspian as the operatingsystem for my Pi, maybe in later iterations, I will move to something closer to Red Hat Linux, like Red Sleeve.

Please follow the instructions on the Raspian page on how to install the OS for your Pi. If you should have a Apple Mac, looking at Pi Filler is an easy way and great tool to use.

Before doing anything else, please do not forget to enhance the filesystem of your Rasbian installation via

pi@raspberrypi:~ $ sudo raspi-config

Step 2: Enable Docker

For Raspbian there is a ready to use package by Hypriot to enable Docker on Raspberry Pi, so please do follow their instructions on how to install Docker on your device.

For me, the following simple steps to install and start Docker worked

pi@raspberrypi:~ $ wget http://downloads.hypriot.com/docker-hypriot_1.9.1-1_armhf.deb
pi@raspberrypi:~ $ sudo dpkg -i docker-hypriot_1.9.1-1_armhf.deb
pi@raspberrypi:~ $ sudo service docker start
pi@raspberrypi:~ $ sudo update-rc.d -f docker enable

In addition to Docker, I decided to use ‘docker-compose‘ to ease the build, start, etc of multiple Docker container.
Unfortunately ‘docker-compose‘ does not come with Hypriot, so you will have to install it separately.

pi@raspberrypi:~ $ wget https://github.com/hypriot/compose/releases/download/1.2.0-raspbian/docker-compose-Linux-armv7l
pi@raspberrypi:~ $ sudo mv docker-compose-Linux-armv7l /usr/local/bin/docker-compose
pi@raspberrypi:~ $ sudo chmod +x /usr/local/bin/docker-compose

Note: it is actually not required to use docker-compose in this simple setup, but as I  intent to add other docker-ized functionality in the Smart Gateway, I decided to already introduce docker-compose now.

If you want to be able to run Docker commands without ‘sudo’ then please also run

pi@raspberrypi:~ $ sudo gpasswd -a ${USER} docker

Step 3: Open Raspberry as WLAN Accesspoint

In my setup, I want intelligent sensors to be able to connect directly to my Raspberry via WLAN and have the Pi forward the messages to some “higher” instance in my network. You can do this communication to your liking, but I felt that for demo purposes it would make more sense to be independent on WLAN and forward the traffic via LAN.

If you want to follow that approach, the tutorial by adafruit worked well for me!

Step 4: Build the container

To be able to build the Docker images for the MQTT broker and the transformation capabilities, you will need to clone my Git repository to your Raspberry

pi@raspberrypi:~ $ git clone http://github.com/PatrickSteiner/IoT_Demo_Gateway.git

You will also need to retrieve Red Hat JBoss Fuse, which will be used to bring MQTT broker and transformation alive.

After downloading the file, you will have to copy it into the corresponding folders on your Raspberry.

pi@raspberrypi:~ $ scp jjboss-fuse-full-6.2.1.redhat-084.zip pi@<your PIs ip-address>:/home/pi/IoT_Demo_Gateway/Fuse/Docker_Files/software/

Now you can build the images, first the Base images that I tend to use for all basic stuff.

pi@raspberrypi:~ $ cd ~/IoT_Demo_Gateway/Base
pi@raspberrypi:~ $ docker build --rm -t psteiner/base .
pi@raspberrypi:~ $ cd ~/IoT_Demo_Gateway/Fuse
pi@raspberrypi:~ $ docker build --rm -t psteiner/fuse .

Followed by the “real” images

pi@raspberrypi:~ $ cd ~/IoT_Demo_Gateway
pi@raspberrypi:~ $ docker-compose build

Step 5: Run the container

To start the “Smart Gateway” services, all you need to do is:

pi@raspberrypi:~ $ cd ~/IoT_Demo_Gateway
pi@raspberrypi:~ $ docker-compose up

As I have mapped all ports of the Docker images to local ports, you can access the broker via:

  • JBoss Fuse Managament Console
    http://<your Pis ip-address>:8181/hawtio
    User-ID & password = admin / change12_me

In the next Blogs I will describe how I build an ESP8266 based sensor, who connects to this “Smart Gateway” via WLAN and delivers data via MQTT.

 

8 replies on “Building a Raspberry Pi based Smart Gateway for IoT”

I realised that you will have to enhance the swapfile on the RPi to host this much workload.

So please edit /etc/dphys-swapfile to increase to at least 1024

Hi Patrick,
thanks for using the Docker tools from Hypriot.
Here are a few enhancements for your setup.
1) you could use HypriotOS directly, then Docker Engine and Docker Compose are already pre-installed
see http://blog.hypriot.com/post/new-hypriotos-berry-with-rpi3-support/ for the latest version
2) or you can use standard Raspbian and install the Docker tools via the Hypriot package repo
“`
# set up hypriot schatzkiste repository
wget -q https://packagecloud.io/gpg.key -O – | sudo apt-key add –
sudo echo ‘deb https://packagecloud.io/Hypriot/Schatzkiste/debian/ wheezy main’ >> /etc/apt/sources.list.d/hypriot.list
sudo apt-get update
sudo apt-get install -y docker-hypriot docker-compose
“`
Later on you’ll get updates as well!

Cheers,
Dieter, Hypriot team

Leave a Reply

close

Subscribe to our newsletter.

Please select all the ways you would like to hear from Open Sourcerers:

You can unsubscribe at any time by clicking the link in the footer of our emails. For information about our privacy practices, please visit our website.

We use Mailchimp as our newsletter platform. By clicking below to subscribe, you acknowledge that your information will be transferred to Mailchimp for processing. Learn more about Mailchimp's privacy practices here.