In the following code, at lines (8) and (9), we see how to register an onConnectionLost and onMessageArrived handler with our Paho-MQTT client instance:
client.onConnectionLost = function onConnectionLost(data) { // (8)
...
}
client.onMessageArrived = function onMessageArrived(message) { // (9)
...
}
These two functions are similar in principle to their corresponding functions in the socket.io example from the previous Chapter 3, Networking with RESTful APIs and Web Sockets Using Flask, in that they update the slider and web page text based on the data found in their respective data and message parameters.
Next, we have our document ready function.