Documentation#

MQTT Plot creates dynamic plots using the Bokeh Visualization Library. It listens to broker mqtt://iot49.local:1883 for data. Plots are rendered at http://iot49.local:5006.

Create a Plot#

To start a new plot, send a message to topic public/vis/new with the following json content:

{
    "columns": [ "time [s]", "y1", "y2", ... ], 
    "rollover": 200, 
    "args": { "title": "MQTT Plot Demo" }, 
    "layout": "scatter_plot" 
}
  • columns is an array of column names

  • rollover is the maximum number of data points plotted. If more data is sent, older points are discarded. The plot scrolls as necessary.

  • args are passed to the layout, e.g. Bokeh figure.

  • layout is the type of plot. Layouts are defined in folder code/mqtt_plot/layouts. Consult the Bokeh gallery for ideas and instructions for creating custom layouts.

MQTT Plot can render only one plot at a time and in a single browser window. New plots “replace” existing plots

Data#

Numeric data for plotting can be sent either as json dict or binary data.

Json#

Send json formatted data to topic public/vis/add. Example:

{ 
    "time [s]": 5.39, 
    "y1": float('nan'), 
    "y2": -0.3 
}

The dict keys must match the column names submitted when the plot was created. Omitted values default to float('nan') and result in “gaps” in the plot. Values not declared when the plot was created are ignored.

Binary#

Format binary as follows:

from struct import pack
data = pack("!3f", 3.5, float('nan'), -77)

and send to topic public/vis/bin.