Configuring Grafana Dashboard with MQTT Data



Configuring Grafana Dashboard

In this Note, the Grafana Dashboard will be configured. Open Grafana via http://localhost:3000.

First, we will add the MQTT and InfluxDB data sources to our Grafana Dashboard.

Adding MQTT Data Source

To add an MQTT data source to Grafana, follow these steps:

  • In the left-hand menu, navigate to Connections -> Add new connection.

    A view of the Grafana Dashboard showing the "Add new connection" option under the "Connections" category.
  • Search for MQTT in the search field.

    The data source search window with the search bar populated with "mqtt" and the MQTT data source being shown underneath as an option.
  • Click the Select button for MQTT.

  • In the top right corner, click Install.

  • After it is installed, the Install button will turn into Add new data source, click it.

  • A new window will appear where you can configure the connection. For our case, since we did not choose authentication for our MQTT and no TLS, we just have to type in our host address of the MQTT Broker mqtt://192.168.4.187:1883 that we set up earlier. Also, give it a name to identify the broker, e.g., "Lathe Docker". Click Save & Test. If the connection is successful, a green box will appear saying "MQTT Connected".

    The data source configuration menu with the "URL" field populated with the host address listed above and the "Name" field populated with the name we selected.

Next, you can start visualizing data by clicking on building a dashboard.

Building a Dashboard

In this example, we will build a simple dashboard to show some of the data sent to the MQTT Broker from Node-RED, including Axes, Spindle, and Feed Data.

Step 1: Create a New Dashboard

  • In the menu, select Dashboards, and click New in the top right-hand corner to start your new dashboard by adding a visualization.

  • Select Data Source MQTT as shown below, since we want to stream the data from there.

    The dashboard menu with the newly created data source shown as an option.

Step 2: Add MQTT Topics

In the next window, add one of the topics that we decided to publish under for our MQTT Out Node in Node-RED. For example, if you want to subscribe to the Axes Data, choose Purdue/IE/Lambertus/BuildatScale/CNC/Acra/ATL-618EVS/Telemetry/Axes as a topic, as shown below. You also have the option to add another topic to your panel by adding another topic.

The dashboard query menu with the "Topic" field populated with the MQTT topic our data is transmitted across.

Step 3: Configure Panel Visualization

The data will now be streamed onto your panel. Since the default panel is a time series one, and we want to show the momentary Axes Data in digits, go to the top right corner and select another panel option from the drop-down menu. A suitable visualization would be the Stat one, as shown below.

The panel configuration menu with the "Stat" selected in the "visualizations" category.

Step 4: Format Panel

  • Once selected, you have the option to choose different formatting options. We chose the following formatting options. For example, under the Panel options, name it "Axes data" and set Text size for title to 40 and Value to 40, etc., see picture below:

    The panel formatting menu with the "Title" field populated with our selected Panel name. In addition to the "Title" and "Value" fields underneath "Text Size" in the "Stat Styles" category populated with our selected text size.
  • With these options, the dashboard will look like the following. You can see Time, timestamp, clientID, z, and x axis values. This is because we are creating those values in Node-RED and publishing them on this topic in MQTT.

    The dashboard view showing Time, timestamp, clientID, z, and x information.

Step 5: Transform Data

  • Since we don't want to show Time, timestamp, and clientID, select Transform data and click + Add transformation.

  • In the transformation window, look for the Organize fields by name option and click it.

  • Disable the fields that you don't want to see and optionally rename them.

    The field configuration menu with the visibility option, the eyeball, marked off for the Time, timestamp, and clientID fields.

Step 6: Add Units to Data

  • Use the Overrides option to add the units of the data shown. Click on + Add field override, select Fields with name, and choose "x". Add the override property > Standard options > Unit. Search for "inch (in)" and select it. Do the same for the "z" axis. The override options will look like this:

  • Click Save and then Apply. Your panel will now look like this:

    The newly configured dashboard view with only the z and x information being displayed

You can drag the panel to different positions or change its size.

Step 7: Add Another Panel (e.g., Spindle Speed)

  • Click Add > Visualization and add the MQTT Topic Purdue/IE/Lambertus/BuildatScale/CNC/Acra/ATL-618EVS/Telemetry/Spindle.

  • Select Gauge in the visualization options.

  • Transform Data > Organize fields by name. Disable all except for "spindle_speed_RPM", and rename it to "Spindle Speed".

  • Add necessary formatting options, e.g., Standard options > No value > 0, Standard options > Max > 800.

  • Open the override options, Fields with name > "spindle_speed_RPM"; + Add override property > Standard options > Unit > Revolutions per minute (rpm).

  • Add Value mappings for color changes based on ranges. Example:

    The value mapping configuration menu with the first range being from 0 to 535 with the color set to green and the other range being from 536 to 3000 with the color set to red.
  • Save and Apply, then you will see your Gauge in the dashboard with color changes based on thresholds.

There are many more options available in Grafana. For detailed documentation, refer to Grafana Documentation.