--- title: "trustedge mqtt" source_url: https://dev.digicert.com/trustedge/cli-reference/trustedge-mqtt.html --- | **Usage** | `trustedge mqtt [options]` | | **Description** | Uses MQTT to subscribe to topics and publish messages. | ## Overview TrustEdge MQTT provides functionality for managing MQTT communications. TrustEdge MQTT supports both MQTT 3.1.1 and MQTT 5.0 protocols for publishing messages to an MQTT broker and subscribing to MQTT topics. ## Examples ### TrustEdge MQTT help (--help) To view usage details and available options for TrustEdge MQTT, use the `--help` option: ```bash trustedge mqtt --help ``` > **Tip** > > You can add `--help` to the end of any TrustEdge CLI command to view help information. ### Publish a message to a topic (--mqtt_pub_topic) To publish a message to an MQTT topic, use the following command: ```bash trustedge mqtt --mqtt_servername broker.hivemq.com --mqtt_pub_topic house/bulb1 --mqtt_pub_message "test message" --mqtt_port 1883 --mqtt_clean_start ``` - **`--mqtt_servername `** Specifies the MQTT broker to connect to. In this case, the broker is `broker.hivemq.com`. - **`--mqtt_pub_topic `** Defines the topic to which the message will be published. In this example, the topic is `house/bulb1`. - **`--mqtt_pub_message `** The message that will be published to the topic specified by `--mqtt_pub_topic`. In this case, the message is `"test message"`. - **`--mqtt_port `** Specifies the network port used to connect to the MQTT broker. The port being used in this example is `1883`, which is the default for MQTT over TCP. - **`--mqtt_clean_start`** Discards any saved session state. Every new connection starts with no subscriptions or queued messages from previous sessions. ### Subscribe to a topic (--mqtt_sub_topic) To subscribe to an MQTT topic, use the following command: ```bash trustedge mqtt --mqtt_servername broker.hivemq.com --mqtt_sub_topic house/bulb1 --mqtt_port 1883 --mqtt_clean_start ``` After running the above command, trustedge enters a "listening" state and waits for messages to arrive on that topic. - **`--mqtt_servername `** Specifies the MQTT broker to connect to. In this case, the broker is `broker.hivemq.com`. - **`--mqtt_sub_topic `** Subscribes to the specified topic. In this example, the client will subscribe to the topic `house/bulb1`. - **`--mqtt_port `** Specifies the network port used to connect to the MQTT broker. The port being used in this example is `1883`, which is the default for MQTT over TCP. - **`--mqtt_clean_start`** Discards any saved session state. Every new connection starts with no subscriptions or queued messages from previous sessions.