How To Touch together ? MQTT is here.

One of the most critical part of the project will be the communication. Whether it is between the Touchs of with the backend we need our device to be able to communicate.

The communication challenge:

The first thing we had to do was to choose the protocol. As we wanted to allow both a communication with a backend and between devices, we chose the MQTT protocol. It has the advantages to be easy to use and to easily allow us to switch from listening to the server to listening an other device.

The first step: the broker:

In MQTT, all devices (may it be a server or an actual connected thing) are clients. They can decide to talk (post) or to listen (subscribe). But for it to work we need a broker. It is the part that will spread the information from the posters to the subscribers. We decided to use Mosquitto. It is a free open-source broker that can be installed very easily on Linux (and also on Windows but… well it is Windows).

The second step: the server

In the same time as the search for the components, we started implementing a very basic server. We used the python library paho-mqtt which is very easy to use. The issue we wanted to deal with first was the representation of the box in the MQTT packets. As our marble will have two positions, we decided to code each one by a bit. So the first idea was to send one integer per lines which binary representation would have been the state of each marble in the line. Doing so we could easily communicate the state of the box. Yet the issue was that doing so we could only retain the last integer. The consequence would be that when a new box connects between to images it would only receive the last line.

To avoid that we decided we needed to send one MQTT post by images. The first idea was to send a string with all the integers. Yet this would have increase the size of the message and we found a more elegant solution: the byte array. So as of now we have a server that send images represented by a byte array. The first byte being the first eight marbles on the top left corner, the eight right next to those and so one to the end of the line (we don’t know yet the numbers of marble). Once we are at the end of the line, we start a new byte with the left part of the second line.


So far we have a Mosquitto broker installed on one of our computers and the server sending bytes array representing the image to show. The issue we have now is that the broker is only reachable from the same computer. We will try to figure out if it comes from the computer, the broker or from the network. Yet as we have received our coils and Hall captors the next weeks will be dedicated to testing them.

2 Replies to “How To Touch together ? MQTT is here.”

Leave a Reply

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