In this chapter, we analyzed the requirements to control sensors wired to different IoT boards with MQTT messages. We defined the topics that we would use and the commands that would be part of the messages' payloads to control sensors. We decided to take advantage of the last will and testament feature of MQTT. Then, we worked with the Eclipse Paho Java Client to write Java code that connected a non-blocking (asynchronous) MQTT client to the MQTT server.
We created a security helper class to establish a TLS secured connection and we worked with asynchronous notifications and callbacks in Java. We subscribed to topics, understood how notification events worked, and we wrote code that processed commands that interacted with sensors.
Finally, we worked with a GUI utility to interact with our Java application through MQTT messages. We were able to turn the sensors on and off and retrieve data from them.
Now that we have understood how to use Java to work with MQTT, we will use MQTT over...