6

I'm using a raspberry pi image that has the mosquitto broker installed. To troubleshoot, instruction was to run:

pi@raspberrypi:/ $ mosquitto_sub -v -t "gateway/+/rx"

However that resulted in:

-bash: mosquitto_sub: command not found

Even though mosquitto was running:

pi@raspberrypi:/ $ sudo service mosquitto status
● mosquitto.service - LSB: mosquitto MQTT v3.1 message broker
   Loaded: loaded (/etc/init.d/mosquitto; generated; vendor preset: enabled)
   Active: active (running) since Sun 2018-09-30 21:43:51 UTC; 5h 14min ago
     Docs: man:systemd-sysv-generator(8)
  Process: 347 ExecStart=/etc/init.d/mosquitto start (code=exited, status=0/SUCCESS)
   CGroup: /system.slice/mosquitto.service
           └─432 /usr/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf

Searching the problem did not produce easy to find answer.

9

The solution is to install mosquitto-clients as well.

pi@raspberrypi:/ $ apt-get install mosquitto-clients

Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
  libc-ares2 libmosquitto1
The following NEW packages will be installed:
  libc-ares2 libmosquitto1 mosquitto-clients
0 upgraded, 3 newly installed, 0 to remove and 0 not upgraded.
Need to get 178 kB of archives.
After this operation, 352 kB of additional disk space will be used.
Do you want to continue? [Y/n] y

Now the mosquitto_sub command is usable.

1
  • Most of the examples on the web starts by installing and testing both broker and client on the same machine. I only wanted the broker on pi1 and client on pi2 and I had the same question because it did not work. If I understand we need the broker to subscribe if the client publish data. Why the command mosquitto_sub not usable with the broker? I might find one day.
    – pierre
    Apr 1 at 1:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.