The connect command creates a client and connects it to the specified broker. The client will stay connected until it is disconnected by the broker or the disconnect method is called. To list all the connected clients of this mqtt-cli shell session use the list method.
|Creates and connects a new MQTT client with the default settings.
mqtt> con -V 3 -h myHost
|Creates and connects an MQTT 3.1.1 client at myHost with the default port.
mqtt> con -i mqtt-client -p 1884
|Creates and connects an MQTT client at localhost with port 1884 which is identified by
|The MQTT host.
|The MQTT port.
|The MQTT version can be set to 3 or 5.
|A unique client identifier can be defined.
|A randomly generated UTF-8 String.
|The prefix for randomly generated client identifiers, if no identifier is given.
|Whether the client should start a clean session.
|The keep alive of the client (in seconds).
|The session expiry value in seconds.
0 (Instant Expiry)
|A user property of the connect message.
|Use WebSocket transport protocol.
|The path to the WebSocket located at the given broker host.
|Will delay interval in seconds.
|Lifetime of the will message in seconds.
Can be disabled by setting it to
|Payload of the will message.
|QoS level of the will message.
|Retain the will message.
|Topic of the will message.
|Correlation data of the will message.
|Description of the will message’s content.
|Payload format can be explicitly specified as
UTF8 else it may be
|Topic name for a response message.
|A user property of the will message.
|The maximum amount of not acknowledged publishes with QoS 1 or 2 the client accepts from the server concurrently.
|The maximum amount of not acknowledged publishes with QoS 1 or 2 the client sends to the server concurrently.
|The maximum packet size the client accepts from the server.
|The maximum packet size the client sends to the server.
|The maximum amount of topic aliases the client accepts from the server.
|The maximum amount of topic aliases the client sends to the server.
|The client requests problem information from the server.
|The client requests response information from the server.
|Define the username for authentication.
|Define the password for authentication directly.
If left blank the user will be prompted for the password in the console.
|Define that the password for authentication is read in from an environment variable.
MQTT_CLI_PW if the option is specified without a value
|Define the path to a file from which the password is read from.
|Whether a default (properties file) TLS configuration is used.
|The path to the file containing a trusted CA certificate, to enable encrypted certificate based communication.
|The path to the directory containing trusted CA certificates, to enable encrypted certificate based communication.
|The path to the client certificate to use for client-side authentication.
|The path to the corresponding private key for the given client certificate.
|The password for the client private key.
|The path to the client keystore for client side authentication.
|The password for the keystore.
|The password for the private key inside the keystore.
|The path to the client truststore, to enable encrypted certificate based communication.
|The password for the truststore.
|The supported cipher suites in IANA string format concatenated by the ‘:’ character, if more than one cipher should be supported.
See IANA Format for supported cipher suite strings.
|The TLS version to use -
|Display help message for command.
|Display version information of the cli.
Connect a client to myHost on port 1884
mqtt> con -h myHost -p 1884
Connect a client to the default host and port using authentication
mqtt> con -u username -pw password
# Or omit the password to get it prompted
mqtt> con -u username -P
Enter value for --password (The password for the client UTF-8 String.):
Connect a client with default settings and use it to publish
mqtt> con -i myClient
myClient@localhost> pub -t test -m "Hello World"
Connect a client with a will message
mqtt> con -wt willtopic -wq 2 -wm "Client disconnected ungracefully"
Connect a client with SSL using client side and server side authentication with a password encrypted private key
mqtt> con --cafile pathToServerCertificate.pem --tls-version TLSv.1.3
--cert pathToClientCertificate.pem --key pathToClientKey.pem
Enter private key password:
Connect a client which is identified by myClient and disconnect it afterward using default settings
mqtt> con -i myClient
Connect a client which is identified by myClient on specific settings and disconnect it afterward
mqtt> con -i myClient -h broker.hivemq.com -V 3
myClient@localhost> exit # client is still connected
mqtt> dis -i myClient -h broker.hivemq.com
NOTE: When specifying the identifier in order to uniquely identify the desired client, the hostname must also be provided. If you don’t specify these, the default settings for these attributes will be used which may lead to unexpected behavior.