A simple command-line MQTT WebSocket client written in Go. This tool allows you to publish messages (including periodic timestamps) and subscribe to topics on an MQTT broker over WebSockets.
- Connect to any MQTT broker supporting WebSockets
- Publish custom messages or periodic timestamps
- Subscribe to topics and print received messages
- Configurable broker address, port, and topic
- Download the latest release:
- Go to the Releases page of this repository.
- Download the appropriate binary for your operating system (e.g.,
mqtt-client-darwin-amd64,mqtt-client-linux-amd64, etc.).
- (Optional) Rename and move the binary:
mv mqtt-client-* mqtt-client chmod +x mqtt-client sudo mv mqtt-client /usr/local/bin/ - Verify installation:
mqtt-client --help
Download the appropriate binary for your operating system and architecture using wget:
# For Linux
wget https://github.com/atakanaydinbas/mqtt-client/releases/download/v1.0.0/mqtt-client-linux-<arch>
# For macOS (darwin)
wget https://github.com/atakanaydinbas/mqtt-client/releases/download/v1.0.0/mqtt-client-darwin-<arch>After downloading, make it executable and move it to your PATH:
chmod +x mqtt-client-<os>-<arch>
sudo mv mqtt-client-<os>-<arch> /usr/local/bin/mqtt-clientNote:
Replace<os>withlinuxordarwindepending on your operating system.
Replace<arch>withamd64for most modern PCs (x86_64) orarm64for ARM-based devices (such as Apple Silicon Macs or Raspberry Pi).
For example, usemqtt-client-linux-amd64for Linux on x86_64, ormqtt-client-darwin-arm64for macOS on Apple Silicon.
If you cannot download the binary from the Releases section, you can build the CLI tool from source. Make sure you have Go 1.21+ installed.
- Clone the repository:
git clone https://github.com/atakanaydinbas/mqtt-client.git cd mqtt-client - Build the CLI:
go build -o mqtt-client
- (Optional) Move the binary to your PATH:
chmod +x mqtt-client sudo mv mqtt-client /usr/local/bin/
- Verify installation:
mqtt-client --help
All commands support the following global flags:
--broker,-b: MQTT broker address (default:localhost)--port,-p: MQTT WebSocket port (default:9001)--topic,-t: MQTT topic (default:test/topic)--username: Username for broker authentication (optional)--password: Password for broker authentication (optional)--tls: Enable TLS (wss://) connection (optional)--ca-cert: Path to CA certificate file (optional, for self-signed brokers)--client-cert: Path to client certificate file (optional, for mTLS)--client-key: Path to client private key file (optional, for mTLS)--insecure: Skip server certificate verification (not recommended)
- For most public brokers, just use
--tls(no certs needed). - For self-signed/private brokers, use
--tls --ca-cert <path>. - Only use
--client-certand--client-keyif the broker requires client authentication (mTLS). - Use
--insecureto skip server verification (for development only).
Examples:
# Connect to a public broker with TLS (no certs needed)
mqtt-client publish --tls -b test.mosquitto.org -p 8081 -t my/topic
# Connect to a broker with a self-signed certificate
mqtt-client subscribe --tls --ca-cert /path/to/ca.pem -b mybroker.local -p 8081 -t my/topic
# Connect with mutual TLS (client certs)
mqtt-client publish --tls --ca-cert /path/to/ca.pem --client-cert /path/to/client.crt --client-key /path/to/client.key -b mybroker.local -p 8081 -t my/topicPublish a message to a topic, or (by default) publish the current timestamp every 10 seconds.
mqtt-client publish [message] [flags][message](optional): Message to publish (overrides timestamp loop)--message,-m: Message to publish (overrides timestamp loop)
Examples:
mqtt-client publish "Hello, MQTT!" -b test.mosquitto.org -p 8081 -t my/topic
mqtt-client publish --message "Quick message"
mqtt-client publish # Publishes timestamp every 10 secondsSubscribe to a topic and print all received messages.
mqtt-client subscribe [flags]Example:
mqtt-client subscribe -b test.mosquitto.org -p 8081 -t my/topicflowchart TD
A["User (CLI)"] -->|"publish/subscribe commands"| B["mqtt-client (cobra CLI)"]
B -->|"Uses"| C["pkg/mqtt (Client)"]
C -->|"Connects via WebSocket"| D["MQTT Broker"]
This project is hosted at atakanaydinbas/mqtt-client.
License: This project is licensed under the MIT License.