If you've set a password for your MQTT broker, you could write in the cell below or use environemental variables as I do:

Then each MQTT canal in a dic key, and I set its nickname as value. As example, we'll be using the office's sensor

We can now fetch data from this canal using the paho-mqtt library:

Note the retained=True option would have been without effect would you have not set it in the broker configuration file.

Sensor's data are in payload, in binary.

We can now use the stream module from holoviews package. A stream is simply a named tuple within which we can update each element for each coming new message comes from the sensor.

A metaclass was created. Several streams could indeed have the same paramters and init but with different sources. We need now to create the streaming object:

Let's now subscribe to the TH_Chambre channel to feed our bureau_stream object. Rather than using subscribe function, we will create a MQTT client.

I give it a name with client_id. We could also the library let it give it a random name. It could be more practical: the broker accepts only one client with a given id.

Zero indicates that the connection was successfull. We now do two things:

  1. we make a function that will feed our holoviews stream with new data
  2. let our MQTT client sub to the TH_bureau channel.

Some time later...

The stream can now be visualized. For this, we create a function that will return a holoviews object. Panel being what it is, it can accept this kind of function to create a dynamic Pane. Our dashboard will be dynamic!

Each time new data comes in, the plot must update. We use the depends decorator for this from param's library. It is used by Holoviews and Panel. Notice how the decorator's paramters are named as the function parameters.

And voilà! The same can be done for each MQTT channel, in other words for each sensor. There are certainly things to do better for each sensor.