This chapter introduces the MQTT protocol, often used in the context of IoT.
MQTT, short for Message Queuing Telemetry Transport is actually a machine-to-machine (M2M) connectivity protocol. It was designed as an extremely lightweight publish/subscribe messaging protocol. It is useful for connections with remote locations where a small code footprint is required and/or network bandwidth is limited. It is also ideal for mobile applications because of its small size, low power usage, minimized data packets, and efficient distribution of information to one or many receivers (more...). Basically MQTT is one of pillars of the Internet of Things.
Now you should be able to import the classes into your application:
A Simple MQTT Client
The UML class diagram of the SimpleMQTTClient class is shown below:
UML Class Diagram of SimpleMQTTClient
To create a SimpleMQTTClient object, you can use any of the given contructors. The ones without a broker will automatically connect to mqtt.labict.be.
For example using the default constructor:
From this point on messages can be easily published to a given topic:
A Message Handler Interface
When subscribing to a topic, the client needs to know where to redirect the received messages. This is handled using an interface called IMQTTMessageHandler. Implementing the messageArrived method in your own classes, allows your objects to be registered as message receivers.
You can pass an object of a class that implements the IMQTTMessageHandler explicitly, for example an FXMLController: