A couple of weeks ago I told you about teaching the first Cypress Academy WICED WiFi class.  In that class, one of the things that I taught people is how to connect a WICED WiFi devkit to the Amazon AWS IOT Cloud using MQTT (which I am going to will publish here).  At the time I was writing the material I wanted to create a “cloud” server that ran on the LAN for the classroom, but there were too many moving parts for me to attack that.  However, the last couple of days I have had some free time so I have gone through all of the steps to create the first part of the Cypress Academy Cloud.  The cloud will have:

  • An RabbitMQ MQTT server
  • An RabbitMQ AMQP server
  • A COAP server (future)
  • An HTTP server

Each of these four protocols are in common use by IoT devices to transfer data to the cloud as they are all lightweight.

In order to simply things, I wanted to run MQTT and AMQP in Docker containers.  And to make matters a bit more fun, on my laptop I only run test stuff inside of a virtual machine (VirtualBox in this case), never on the bare metal.  In order to facilitate the provisioning of the virtual machine I use a tool called Vagrant which can create and configure a virtual machine from a single configuration file called “Vagrantfile”.

Nicholas, my son, always comes in my office and asks “what are you doing”.  I decided years ago to always do my best to answer this question.  On Tuesday, when he asked the question I started talking and quickly realized that this whole thing was a little bit complicated…. well, actually a lot complicated.  So, I did what I always do, drew a picture:

mqtt-network-pic

The get all of this going I:

  1. Install VirtualBox 5.1 on the Mac (Use the simple Mac installer)
  2. Install Vagrant 1.8.7 on the Mac (Use the simple Mac installer)
  3. Create a “Vagrantfile” (by running “vagrant init”) that:
    1. (line 3) Creates a Ubuntu trusty installation in VirtualBox
    2. (lines 5-7) Forwards ports TCP ports 15672, 1883 and 5672
    3. (line 11) Install emacs (which is the best editor)
    4. (lines 12-20) Installs Docker into the Ubuntu 14.04 (Trusty) virtual machine using instructions from the docker website.  There is a vagrant Ubuntu box based on Precise Pangolin 12.04 but the built in kernel does not seem to work with Docker and it wasn’t worth figuring out why/how to fix it.
      1. (line 21-22) Configures Docker to get the RabbitMQ and Management docker images using instructions from the docker rabbitmq website
        1. (line 23) Creates a Docker container called “rabbitmq” and forwards ports 15672, 1883, and 5672
        2. (line 24) Enables the MQTT Plugin
      2. (line 25)Configures Docker to get the NGINX HTTP container
        1. (line 26) Create and run a docker container with NGINX and forward Port 80

screen-shot-2016-11-25-at-9-51-57-am

The networking aspect of this was a bit tricky to understand when I first went through the process.  Docker and VirtualBox both create private networks for the virtual machines/containers to run in.   In order to get from the native Mac –> Ubuntu VirtualBox –> Docker RabbitMQ container you need to setup port forwarding tables.

To test all of this first prove that the NGIX server is working go to http://127.0.0.1:8000

screen-shot-2016-11-25-at-10-16-19-am

And the RabbitMQ Management Console at http://127.0.0.1:15672

screen-shot-2016-11-25-at-10-16-37-am

And test the MQTT server on port 1883 using MQTTBox

screen-shot-2016-11-25-at-10-17-37-am

Recommended Posts

2 Comments

  1. This is great man thanks. Can you convert the script to text if you have it handy

    • Sorry about that.. Here is the text

      Vagrant.configure(“2”) do |config|

      config.vm.box = “ubuntu/trusty64”

      config.vm.network “forwarded_port”, guest: 15672, host: 15672
      config.vm.network “forwarded_port”, guest: 5672, host: 5672
      config.vm.network “forwarded_port”, guest: 1883, host: 1883

      config.vm.provision “shell”, inline: <<-SHELL apt-get update apt-get -y install emacs apt-get -y install apt-transport-https ca-certificates apt-key adv --keyserver hkp://ha.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D echo "deb https://apt.dockerproject.org/repo ubuntu-trusty main” | sudo tee /etc/apt/sources.list.d/docker.list
      apt-get update
      apt-get -y install linux-image-extra-$(uname -r) linux-image-extra-virtual
      apt-get update
      apt-get -y install linux-image-generic-lts-trusty
      apt-get -y install docker-engine
      usermod -aG docker vagrant
      docker pull rabbitmq
      docker pull rabbitmq:3-management
      docker run -d -p 4369:4369 -p 5672:5672 -p 15672:15672 -p 25672:25672 -p 1883:1883 –name rabbitmq rabbitmq:3-management
      docker exec rabbitmq rabbitmq-plugins enable rabbitmq_mqtt
      docker pull nginx
      docker run -d -p 80:80 –name nginx nginx
      SHELL
      end


Add a Comment

Your email address will not be published. Required fields are marked *