Reader small image

You're reading from  Practical Python Programming for IoT

Product typeBook
Published inNov 2020
Reading LevelIntermediate
PublisherPackt
ISBN-139781838982461
Edition1st Edition
Languages
Right arrow

The onConnectionLost and onMessageArrived handler methods

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.

lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Practical Python Programming for IoT
Published in: Nov 2020Publisher: PacktISBN-13: 9781838982461