How to run your web server and MQTT WebSockets broker on the same port

I was just asked how one can deploy a similar setup as the MQTT sandbox, where MQTT over WebSockets is available on port 80, just like the rest of the website.

There are actually two ways of achieving this.

Mosquitto as the main frontend

It’s a little-known fact but together with built-in WebSockets support (added in version 1.4), Mosquitto also can act as basic HTTP server, and directly serve a bunch of static resources for you. The config option you’re looking for is “http_dir“, that will allow you to serve the content of a directory over HTTP.

Granted you are running a version of Mosquitto that has WebSockets support, here how your mosquitto.conf file should look like to enable WebSockets *and* regular HTTP connections:

listener 80
protocol websockets
http_dir /home/johndoe/htdocs

Of course, you will need to make sure that you do not have any other daemons (like Apache, nginx, …) already running and using port 80 :-)

Once Mosquitto is setup this way, you can use any MQTT client that supports WebSockets to connect to ws://yourhost URI.

ws://yourhost/ws, or ws://yourhost:80/foobar would work just fine too – Mosquitto doesn’t care about the path at all!

Apache front-end + mod_websocket_mosquitto

Since it’s likely you actually want a “real” HTTP server to serve your website (for security reasons, for being able to run PHP, etc.), another approach is to use Apache as the main HTTP front-end, as you would normally do, and configure it to tunnel WebSockets connections made on a given URI to your Mosquitto broker.

You can download an Apache module that does exactly that at The instructions to compile and install it are pretty straightforward and you will end up with something like the following in your Apache configuration:

<IfModule mod_websocket.c>
Loadmodule mod_websocket_mosquitto /usr/lib/apache2/modules/
 <Location /mosquitto>
 MosBroker localhost
 MosPort 1883
 SetHandler websocket-handler
 WebSocketHandler /usr/lib/apache2/modules/ mosquitto_init

Unveiling the Eclipse IoT Demo Box

Now that the holiday season is over, we’re fully into “conference season” mode, as the fall is packed with IoT conferences (look at our Events Calendar to see where we will have a presence in the next couple months). Last week, the Eclipse Foundation was exhibiting at M2M Summit with three of our member companies: Logi.cals, Generative Software and Bitreactive (who blogged about it).

Since the number of Eclipse IoT projects keeps growing (we’re approaching 20!), it is sometimes difficult for people to quickly understand the problems each of these projects are trying to solve. While we’ve been pretty successful with the “Greenhouse demo™” over the past few years, this is a rather limited use case, and it does not really allow to showcase some of our newest projects.

This is why I started to create a new setup for Eclipse IoT demos, that I hope will be adopted by everyone interested in having an easy to setup platform for explaining what Eclipse IoT is all about. You should read this article until the end if you want to learn how to replicate this setup yourself!

Making the Raspberry Pi more demo friendly

First of all, it is worth mentioning that I have now adopted the Raspberry Pi 2 for IoT demos, since having more horsepower means you get to run more processes simultaneously, which is exactly what I need when I want to demo several projects at the same time (even though this is probably not what you would do in a real-life scenario).

→ Adding a touchscreen


In order to allow for easy interaction, I’ve added a touchscreen. I was one week early to get the brand new PITFT from the Pi Foundation, so I got a 7″ HDMI dispay from Adafruit, for about $90. It’s pretty nice as it doesn’t require external power, and uses an HDMI cable (vs. the much more fragile DSI ribbon cable of the PITFT).

→ Running the IoT servers locally

When you make demos on the fly, you do not always have Internet access. Therefore, the Raspberry Pi runs a Mosquitto MQTT broker and a Leshan LWM2M server to make it possible to run demos “offline”.

→ Enabling wireless hotspot feature

Since I wanted to be able to demo applications where e.g. a smartphone talks to the MQTT broker that’s running on the Pi, I needed it to be a Wi-Fi hotspot, to make it easily accessible to devices in its neighborhood.
I’ve used a very simple setup script that will walk you through all the steps to enable the hotspot.

A demonstration platform

The Eclipse IoT demo box makes it easy to navigate through the different projects, all from a web browser. For the projects that require command line interaction, the shell is also visible right from the web browser thanks to term.js.

I’ve made it as easy as possible to add new “tiles” to the demo box home screen, and associate the required actions to actually launch the demo behind a given tile.

Eclipse IoT Demo Box - Home screen

As of today, the demonstrators included in the “demo box” are:

  • IoT Gateways: This helps discover the capabilities of Kura, and reuses the existing “Greenhouse demo” (including sensors) to showcase how Kura can act as an IoT application container.
  • Smart Home: The Raspberry Pi runs the SmartHome/OpenHAB 2 demo bundle, and if you attach a WeMo plug or a Philips Hue to the same network as the Raspberry Pi, you can start showing some really cool features like automatic device discovery!
  • Device Management: The box runs the Leshan LWM2M server, and a simple Wakaama client registers against this server so as you can start performing device management operations
  • Service Discovery: Tiaki provides an implementation of DNS-SD, and the demo box allows you to quickly run its command line examples
  • MQTT and Mosquitto: For people not familiar with the MQTT “way of life”, I’ve packaged a nice live visualization of the MQTT topics hierarchy that allows to understand better what’s happening on the Mosquitto broker that is running on the demo box.

How to replicate the demo setup

As I said at the beginning of this post, I would really like to see lots of people building on top of this demo infrastructure, and start integrating their own open source or commercial demos with the existing ones.

It should actually be pretty easy and fun for you to recreate the Eclipse IoT Demo Box:

Please let me know if you try it out, I am very interested in getting your feedback!

3 hardware platforms of choice to get started with Eclipse IoT

When you prototype IoT solutions, it becomes necessary very early in your development phase to use an actual embedded platform to run your software, and to test it in an environment that is as close as possible of what you expect your production environment to be.

As I’m sure you know, there are lots of hardware prototyping platforms out there. In this article you will learn about three very popular options (from the cheapest/tiniest to the most capable) that can help you get started with Eclipse IoT projects in no time, and get pointers to useful docs and tutorials to make the initial setup as simple as possible!



With only 2KB of RAM and 32KB of Flash, the Arduino UNO really is what you would call a constrained device! And yet, the ATmega328P micro-controller powering the Arduino UNO is able to run a full-blown MQTT client, in the form of the Eclipse Paho embedded C Client.

Check out the Paho website for more information and get the pre-build, ready-to-use, Arduino ZIP library from the project’s download page

ARM mbed

nxp 1768

There is a vast ecosystem of micro-controllers compatible with the mbed environment. mbed devices are based on the Cortex-M architecture, and typically have more RAM and Flash than an Arduino UNO. For example, the NXP LPC1768 has 32K of RAM and 512KB of Flash.

An interesting thing to get started with the mbed platform would be for you to run a LWM2M stack, using the Eclipse Wakaama project. I actually blogged about it last month, so check it out!

Of course, it’s also possible to run a Paho MQTT client, and you can easily get started using the HelloMQTT code sample available from the online compiler.

Raspberry Pi

Raspberry Pi

Ah! The famous credit-card sized computer which more that 3 million units have been sold! With its 900MHz quad-core CPU and 1GB of RAM, the Raspberry Pi 2 is the kind of horse that could power a real-life IoT gateway, bridging sensors and actuators to a backend server.

Eclipse Kura is an open-source framework for building smart IoT gateways that can host and manage Java applications. It is very easy to get started with Kura on a Raspberry Pi as the project team provides a Debian package that can be installed by typing literally just two command lines!

If you’re interested in getting your hands dirty with home automation, Eclipse SmartHome is another project you may want to look at. The integrated distribution of SmartHome, OpenHAB, has a wiki page with all the important things you need to know to optimize the performance of your system.

… and many more!

Of course these are just 3 platforms among many, and as many of our projects are backed by companies whose business is indeed to make sure that the software – be it a protocol stack or a full-blown application framework – can run on heterogeneous hardware platforms, you can usually easily port them to your own platform. Actually, if you have experience with Eclipse IoT projects on other platforms, I’d love to hear from you!

Eclipse, open-source for the Internet of Things, and other random stuff