Home/Support/Support Forum/MQTT connect example doesn't work
Welcome to Digi Forum, where you can ask questions and receive answers from other members of the community.

MQTT connect example doesn't work

0 votes
We are working with a Digi cellular modem, and we need to use the MQTT protocol, so I'm using XCTU to run the "Get Started With MQTT"->"Send a command packet", and I've done everything in the instructions to connect to the test.mosquitto.org broker, but I'm not getting a response. I went back to the "Connect to echo server", and I am able to get a response there, so I know the modem works.

Any suggestions?
asked Mar 1 in Digi Connect Cellular by Bit Banger New to the Community (1 point)

Please log in or register to answer this question.

1 Answer

0 votes
Does it ]give you any Error messages?
answered Mar 1 by mvut Veteran of the Digi Community (14,297 points)
I'm not seeing anything.  When I set AP (0), DL (test.mosquitto.org), and DE (75B) with the console connected I can see the modem accepting the commands with the "OK" response, but when I send the connect packet I get no response.
What example are you using?  The one I show in the documentation uses Micro Python.
I was using the simpler example without micro-python, "Send a connect packet".  In addition to the configuration parameters above, I created and sent the packet as specified, {10 10 00 04 4D 51 54 54 04 02 00 3C 00 04 44 49 47 49}, but I don't get a response.  I'm sure I can connect to a server, because the Echo server example gives me a reply.  I also tried the HiveMQ broker (broker.hivemq.com) in addition to test.mosquitto.org, with the same result, no response.
Since I have run this test before both using Micro Python and the direct option you are working with, I am suspecting that there is an issue with the server side that is keeping it from allowing you to connect.
So what do you recommend I try?  I'm dead in the water until I can make MQTT connect.  I have tried running the other examples on Micro Python, but I get an error when I try execute "import paho.mqtt.client as mqtt", and I'm confused because I need to change the AP setting to MicroPython, not transparent mode, as described in the examples.  Unless the python examples are run on a PC and not MicroPython.  If you can provide a step by step example that I can get a reply to a MQTT connect command I will be happy.  I'm looking for a simple solution to connect and publish, since we don't have the resources to run the paho library on our embedded target.  If MicroPython can do it, we may use that in our solution, but I need to know how to integrate the paho library into MicroPython.
For the Micro Python code to work, you need to import into the LIB directory, the MQTT lib file. That file can be found on GetHub or in the PyCharm Plugin.
Micro Python is not necessary to make it work.  I contacted technical support, and they suggested adding a <CR> at the end of the packet, which becomes {10 10 00 04 4D 51 54 54 04 02 00 3C 00 04 44 49 47 49 0D}.  That did the trick.
It should be mentioned that I tried that yesterday and from the looks of it, the 3rd party server was having issues as today it now works.
Fair enough, the person I communicated with in tech support mentioned that as well, so I will bear that in mind moving forward, thanks.