Working with last will and testament in Java
Now, we will take advantage of the last will and testament feature. We will create the main class named Main
that uses the asynchronous API of the Paho Java Client, the previously coded SecurityHelper
class to establish an encrypted connection with an MQTT server, and the SensorsManager
class to process the received messages with commands. The code will configure a message to be sent as the last will when the connection is lost. In addition, the Main
class will call the loop method for a SensorsManager
instance to publish messages with data retrieved from the sensors when they are turned on with the appropriate commands.
We will split the code for the Main
class into many code snippets to make it easier ...
Get MQTT Essentials - A Lightweight IoT Protocol now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.