Command line (mosquitto)
The quickest way to check your credentials: two terminal windows, one subscriber and one publisher.
Install the clients
| OS | Command |
|---|---|
| Ubuntu / Debian | sudo apt install mosquitto-clients |
| macOS (Homebrew) | brew install mosquitto |
| Windows | Install Mosquitto from mosquitto.org/download; the tools are in C:\Program Files\mosquitto. |
Subscribe
Replace the placeholders with the values from Credentials & endpoints.
bash
mosquitto_sub -h broker.connectmq.com -p 8883 --capath /etc/ssl/certs \
-i YOUR_CLIENT_ID_sub \
-u YOUR_USERNAME -P 'YOUR_PASSWORD' \
-t 'acme/istanbul/assembly/#' -vPublish
In a second terminal:
bash
mosquitto_pub -h broker.connectmq.com -p 8883 --capath /etc/ssl/certs \
-i YOUR_CLIENT_ID_pub \
-u YOUR_USERNAME -P 'YOUR_PASSWORD' \
-t 'acme/istanbul/assembly/line1/cnc-01/telemetry' \
-m '{"temperature":62.4,"spindleRpm":11950}' -q 1The subscriber prints the message, and the topic appears in the console's topic tree a moment later.
TLS options
- Linux:
--capath /etc/ssl/certsuses the system CA store. - macOS / Windows: use
--tls-use-os-certs(Mosquitto 2.0+) instead of--capath. - The broker certificate is publicly trusted, so you never need
--insecure.
Useful flags
| Flag | Meaning |
|---|---|
-i | Client ID. Must be your issued client ID or start with <client ID>_, see Client IDs. Use different suffixes for the subscriber and the publisher. |
-q 0/1/2 | QoS level. |
-r | Publish as a retained message. |
-V mqttv5 | Use MQTT 5 (default is 3.1.1). |
-d | Debug output, shows CONNACK reason codes. |
--will-topic, --will-payload | Last Will and Testament. |
If the connection is refused, run with -d and look up the reason code in Troubleshooting.