hivemq / mqtt-cli

MQTT CLI is a useful command line interface for connecting various MQTT clients supporting MQTT 5.0 and 3.1.1
https://hivemq.github.io/mqtt-cli/
Apache License 2.0
305 stars 48 forks source link

MQTT Usage Error on Nvidia Jetson #433

Closed Avinash-Gahlowt closed 2 days ago

Avinash-Gahlowt commented 2 days ago

I have Ubuntu 22.04 installed and communicating with a device installed with NVidia Jetson. I have installed MQTT-Cli v4.25.0 on my OS. However, I am getting the following error which trying to publish a simple message: For a simple publish command mqtt pub -h localhost -t test -m "Hello", the terminal throws the following error:

usage: mqtt [-h] [--host HOST] [--port PORT] [--transport {tcp,websockets}] [--clientid CLIENTID] [--user USER] [--password PASSWORD]
            [--protocol {MQTTProtocolVersion.MQTTv31,MQTTProtocolVersion.MQTTv311,MQTTProtocolVersion.MQTTv5}] [--path PATH] [--tls]
            [--clean-start] [--log-level LOG_LEVEL]
            {publish,subscribe} ...
mqtt: error: invalid choice: 'pub' (choose from 'publish', 'subscribe')

I tried reinstalling the mqtt-cli multiple times but the error persists. On trying find the version using mqtt --version, it generates the following traceback:

Traceback (most recent call last):
  File "/home/nvidia/.local/bin/mqtt", line 8, in <module>
    sys.exit(main())
  File "/home/nvidia/.local/lib/python3.8/site-packages/mqtt_cli.py", line 221, in main
    args = parser.parse_args()
  File "/usr/lib/python3.8/argparse.py", line 1780, in parse_args
    args, argv = self.parse_known_args(args, namespace)
  File "/usr/lib/python3.8/argparse.py", line 1812, in parse_known_args
    namespace, args = self._parse_known_args(args, namespace)
  File "/usr/lib/python3.8/argparse.py", line 2047, in _parse_known_args
    ', '.join(required_actions))
TypeError: sequence item 0: expected str instance, NoneType found

I have used the same API earlier successfully on the same OS to communicate with devices without GPU. Any idea why could this be happening for the device with GPU?

As an aside, when I use mosquitto as a broker, I am able to communicate with the same device successfully.

LukasBrand commented 2 days ago

Hello @Avinash-Gahlowt,

you uninstalled the wrong mqtt-cli. I could reproduce your issue by installing it via pip:

pip install mqtt-cli

which ultimately installs this tool: https://github.com/MO-RISE/mqtt-cli


Solution

Unfortunately it looks like you installed it to the global package scope of python, i.e. not in an environment which makes it hard to remove the wrong package with all of its dependencies but you should be able to remove it all with:

pip uninstall -y mqtt-cli paho-mqtt parse persist-queue

Once everything is removed the command should not be found anymore, something like this:

$ mqtt
zsh: command not found: mqtt

Now, follow the guide in our documentation to install the cli: https://hivemq.github.io/mqtt-cli/docs/installation/#debian-package

wget https://github.com/hivemq/mqtt-cli/releases/download/v4.30.0/mqtt-cli-4.30.0.deb
sudo apt install ./mqtt-cli-4.30.0.deb

After you successfully installed our mqtt-cli you should get the following output:

$ mqtt 

Usage:  mqtt [-hV] { pub | sub | shell | test | hivemq | swarm }

MQTT Command Line Interpreter.

Options:
  -h, --help      Show this help message and exit.
  -V, --version   Print version information and exit.

Commands:
  pub, publish    Publish a message to a list of topics.
  sub, subscribe  Subscribe an MQTT client to a list of topics.
  shell, sh       Starts MqttCLI in shell mode, to enable interactive mode with further sub commands.
  test            Tests the specified broker on different MQTT feature support and prints the results.
  hivemq          HiveMQ Command Line Interpreter.
  swarm           HiveMQ Swarm Command Line Interpreter.

Or the version option should print something like the following:

$ mqtt --version
4.30.0
Picocli 4.7.6
JVM: 11.0.22 (Azul Systems, Inc. OpenJDK 64-Bit Server VM 11.0.22+7-LTS)
OS: Mac OS X 14.5 aarch64
Avinash-Gahlowt commented 2 days ago

Thanks @LukasBrand
The solution worked for me , i didn't have to reinstall, just by firing the first command it started working properly.

LukasBrand commented 22 hours ago

https://hivemq.kanbanize.com/ctrl_board/22/cards/23975/details/