Receiving Measurements from Sensor over MQTT Tool

This use case makes use of MQTT communication protocol to transfer the data to all entities is interested in receiving the data. These entities are called subscribers. The distance measure sensor plays the role of the publisher, meaning that the device publishes the measured sensor data and the subscriber receives this data from the publisher. The whole communication is conducted over the MQTT broker. An MQTT broker is required to to be able to utilize MQTT communication protocol. The easiest way to connect to one of the online MQTT protocols given in [nline-mqtt-brokers-iot-connected-objects-cloud/">https://diyprojects.io/surprisenline- nline-mqtt-brokers-iot-connected-objects-cloud/">mqtt-brokers-iot-connected-objects-cloud/]. Otherwise, a local broker must be installed. An online broker (test.mosquitto.org) is used in the following example. The goal of this section is to receive the data from the device through an available MQTT tool called MQTT.fx.

https://mqttfx.jensd.de/

MQTT.fx is recommended as a tool as it is java-based and can run on any platform that supports java.

Installing MQTT.fx and Configuration

In this section, we first download MQTT.fx tool from [ http://mqttfx.org/ ] and execute it. Once the execution is succeeded, the next step is to set up the mqtt-broker configuration. As mentioned before and as shown in Figure 2, a free online mqtt broker is used in this example.

https://mntolia.com/10-free-public-private-mqtt-brokers-for-testing-prototyping/

image-14

Figure 5: MQTT client connection profile


Testing MQTT Broker & Topic Subscription

The second step is to subscribe and publish to the interested topic. Below, /test/distance topic is entered and added as a topic. In order to test, a message can be published under the publish section with the given topic name as done. The message is sent to the subscriber as illustrated in Figure 3.

image-14

Figure 6: MQTT client subscription to a topic

image-15

Figure 7: MQTT client receiving data under the subscribed topic

After testing the broker, the broker address and the topic name should be written in the python source code of the distance sensor. After their replacement, we should see all incoming results as in Figure 4.