Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.
|Page Name:||Tcl MQTT client|
The mqtt command
mqtt new ?options?
mqtt create name ?options?
The mqtt command creates an MQTT client instance. That instance can subsequently be used to communicate with an MQTT broker.
- -keepalive seconds
- Rate at which to send keepalive messages (default: 60)
- -retransmit milliseconds
- When to retransmit a message if no confirmation has been received (default: 5000)
- -username value
- The username to use to authenticate with the MQTT broker
- -password value
- The password to use to authenticate with the MQTT broker
- -clean boolean
- Whether to use a clean connection to the MQTT broker (default: on)
The client commandFor each client instance created with the mqtt command, a new Tcl command is created. This command may be used to invoke various mqtt related operations.
The valid forms of this command are:
- client configure ?option? ?value option value ...?
- Query or modify the configuration options of the instance. If one or more option-value pairs are specified, then the command modifies the given instance option(s) to have the given value(s); in this case the command returns an empty string. If option is specified with no value, then the command returns the current value of the option. If no option is specified, it returns a list of all available options and their values.
- client connect name ?host? ?port?
- Connect to the specified MQTT broker, using name as the MQTT ClientID. The default value for host is localhost. The default port is 1883.
- client publish topic message ?qos? ?retain?
- Publish an MQTT message to the broker. Valid values for qos are 0 (at most once), 1 (at least once), and 2 (exactly once). Default is 1. Valid values for retain are 0 and 1. Default is 0.
- client subscribe pattern prefix
- Subscribe to topics matching the specified pattern. When a matching MQTT message is received by the MQTT broker, the prefix is evaluated with two arguments appended: the topic of the message, and the contents of the message.
- client unsubscribe pattern prefix
- Unsubscribe from a previously subscribed topic pattern.
- client will topic message ?qos? ?retain?
- Include a last will and testament in all future connections to the MQTT broker. If topic is the empty string, no last will and testament will be included in future connections to the MQTT broker. Valid values for qos are 0 (at most once), 1 (at least once), and 2 (exactly once). Default is 1. Valid values for retain are 0 and 1. Default is 0.