MQTT Troubleshooting
To perform MQTT troubleshooting, you need to establish reliable reference for 3 involved parties separately, namely Subscriber, Publisher and Broker. For subscriber and publisher, you may use MQTT Spy as your MQTT clients, it is a small Java utility that you can run without installing. And it’s preconfigured with some public brokers or servers that you can use right away. So you need to get only one tool to isolate and troubleshoot on any of the scopes.
https://github.com/eclipse/paho.mqtt-spy/wiki/Downloads
-
Connect to public broker from start screen.
MQTT Spy is has a dashboard-like of Control Panel which you can click on any listed public broker.
You will then see a new tab openned with server name in light green indicating broker’s status.
-
Subscribe to a topic by clicking on ‘New’ tab
Enter your desired topic under Subscriptions and Received Message section , for example
ecava/igx/scada/#
, whereby#
is the wildcard.A new Tab with entered topic will be added in Subcriptions section.
-
Observe New Tab is added for receiving data
You are now good to receive any MQTT data from any Publisher in the specified topic. You may try to publish any data from the Publish Message pane itself to see if data get looped back.
Next step is to automate the publishing work, which is useful despite optional.
-
Add and Set the Script Directory
Copy the following script and save as a JavaScript (
filename.js
) file in a folder. And then set the directory as the Script Directory, in the pop up option when right clicking on Scripted Publications Pane.
(function (){
mqttspy.publish("ecava/igx/scada", (Math.random()*1000).toFixed(2));
try {
Java.type("java.lang.Thread").sleep(1000); //try to sleep
}
catch (e){
return false;
}
  ;return true;
})();
This script will automate a random data publishing sequence in every second.
-
Load and Start Script
Your script(s) shall appear in the script list after setting direcotry and refreshing list. Check on the Repeat option, then right click on the script to Start.
-
Observe messages being sent and received
You can now leave MQTT Spy running in the background, and proceed to your application to see if the same data can be received.
If you need to use Modbus in your work, you might be interested in the Modbus Troubleshooting Guide as well. Also, Ecava IGX SCADA can do both Pub/Sub and has a built-in MQTT broker or server. Download the latest copy for free and start enjoying many advanced benefits now.