Communication

The deployment diagram below shows today's distributed setup:

The setup consists of at least three components:

Note: When you work from home, you can work on your own MQTT broker too. However, other students not part of your home network may not be able to reach your MQTT broker. If you want to connect your applications and are in different networks (like in the last task) work with the central broker at NTNU, (mqtt.item.ntnu.no).

Tips for This Unit

Task: Running MQTT.FX

MQTT.FX is a desktop application that connects to an MQTT broker and that can publish and subscribe to arbitrary topics. This is a very tool useful during development. (If you wonder, the name MQTT.FX just comes from the fact that it is implemented in Java FX, but you can forget about that.) Essentially, MQTT.FX is a MQTT client, and can as such connect to an MQTT broker, subscribe to topics and send messages to topics. This does not sound like much. However, MQTT.FX has a generic user interface, you can use MQTT.FX while you construct your application to see how the other system components publish messages, and you can also "inject" messages into the system, by publishing to any topic you want. Using MQTT.FX is really simple, but because we have now talked about brokers, clients, publishers and subscribers, you may loose track and wonder what this MQTT.FX does: Think of it as a debugger for MQTT, and you can use it like Wireshark. Once the system is done, you don't need MQTT.FX anymore.

Download MQTT.FX

Publishing Messages

Imagine you have created a MQTT client that runs a certain action when it receives a message, but you are not done with the component that should send the message. To test at least the component that should receive the message, you can use MQTT.FX to publish a message with that content to the topic, and the component under test will behave as if the message was sent in the final system.

Observing Communication

Because MQTT uses the publish-subscribe pattern, it can simply subscribe to any topics that are interesting in your application and you can see which messages are sent to these topics, without disturbing the communication in the system. To achieve the same in HTTP, for instance, you need a tool like Wireshark.

Task: Observing a Public MQTT Broker

There are some public MQTT brokers to which anyone can connect.

List of Public MQTT Brokers

Task: Running Your Own MQTT Broker (Optional)

You can always use such a public broker for testing, but on most cases it is better to have your own broker running. Install the Mosquitto MQTT Broker on your laptop. This is an open-source MQTT broker that is relatively easy to install and run.

Task: Python Notebooks

Now we are going to combine what we learned about MQTT with Python.

MQTT Part 1 - Connect to Broker

This notebook explains Paho, the Python client for MQTT and connects to a broker.

MQTT Part 2 - Connect and Publish

This notebook extends the MQTT client and also publishes messages, forwarding to another topic.

MQTT Part 3 - MQTT and STMPY

This notebook shows you how to connect the MQTT client with state machines in STMPY.

Challenge: Quiz Show Buzzers

The tasks above did not require any programming from you so that you can focus on installing and setting up all the components as well as getting familiar with the APIs and how everything works.

So the following task should be doable now:

Create a small and very prototypical system that realizes the timer and buzzers for a quiz.

Some hints for the delivery:

Document your achievement in your document.

Put the document of your unit on Teams, into the folder for this week.

Reflection

Team Reflection for This Unit

Individual Reflection