---
title: "Publish and subscribe to MQTT from Pico LTE"
description: "Publish and subscribe to MQTT topics from the Pico LTE over the cellular connection, with MQTTHQ as the test broker."
url: "https://docs.sixfab.com/cellular/pico-lte/micropython-sdk/mqtt-publish-subscribe/"
last_updated: "2026-11-26"
---

# Publish and subscribe to MQTT from Pico LTE

Publish and subscribe to MQTT topics from the Pico LTE over the cellular connection, with MQTTHQ as the test broker.

These examples publish and subscribe to MQTT topics from the Pico LTE over the cellular connection. MQTT is a lightweight messaging protocol for constrained devices and low-bandwidth, high-latency or unreliable networks, common in IoT. The test broker is [MQTTHQ](https://mqtthq.com/), with its web client on the other side. No extra hardware is needed.

## Before you begin

**Required**

**Hardware**

- **Sixfab Pico LTE or Pico LTE 2**: Registered and active in Sixfab Connect, connected to the computer with the micro USB cable.

**Software**

- **Thonny with MicroPython and the Pico LTE SDK**: Set up as in the [quickstart](https://docs.sixfab.com/cellular/pico-lte/quickstart/).
- **config.json**: In the root of the board: [Prepare the configuration file](https://docs.sixfab.com/cellular/pico-lte/micropython-sdk/configuration-file/).

## Prepare broker

Go to [MQTTHQ](https://mqtthq.com/), note the **Broker URL** and the **TCP Port**, and click **Try our Web Client Now**.

![MQTTHQ broker settings: URL public.mqtthq.com, TCP port 1883, and the Try our Web Client Now button](https://docs.sixfab.com/wp-content/uploads/sixfab-docs/PicoLTE-MQTT-Example-1.png)

In the web client, set the QoS to **1** (At Least Once) and note the topic and the QoS.

## Run examples

The scripts are in the `examples/mqtt` folder of the [SDK repository](https://github.com/sixfab/pico_lte_micropython-sdk).

**Publish**

1. **Subscribe in web client.**

   Click **Subscribe**, so that the client shows the messages of the board.

   ![MQTTHQ web client Subscribe to topic form with topic mqttHQ-client-test, QoS 1 - At Least Once and Subscribe button](https://docs.sixfab.com/wp-content/uploads/sixfab-docs/PicoLTE-MQTT-Example-2.png)

2. **Set broker in config.json.**

   MQTTHQ needs no client ID, username or password: delete them. The full set of parameters:

   ```json
   {
       "mqtts":{
         "host":"[HOST_ADDRESS]",
         "port": [PORT_NUMBER],
         "pub_qos": [QoS],
         "client_id": "[CLIENT_ID]",
         "username":"[MQTT_USERNAME]",
         "password":"[MQTT_PASSWORD]"
       }
   }
   ```

   For MQTTHQ:

   ```json
   {
       "mqtts":{
             "host":"public.mqtthq.com",
             "port": 1883,
             "pub_qos": 1
         }
   }
   ```

3. **Set message and topic.**

   Open `examples/mqtt/publish.py` in Thonny and set `PAYLOAD` to your message and `TOPIC` to the topic of the web client.

   ![Pico LTE MQTT publish example code with PAYLOAD "Hello!" and TOPIC "mqttHQ-client-test" highlighted](https://docs.sixfab.com/wp-content/uploads/sixfab-docs/PicoLTE-MQTT-Example-3.png)

4. **Run script.**

   The log reports the publication, and the message appears in the web client.

   ![MQTTHQ web client subscribed to mqttHQ-client-test showing the received payload Hello!](https://docs.sixfab.com/wp-content/uploads/sixfab-docs/PicoLTE-MQTT-Example-4.png)

   ```text
   INFO: Publishing a message.
   INFO: Result: {'response': ['OK'], 'status': 0}
   INFO: Publish succeeded.
   ```

**Subscribe**

1. **Prepare message in web client.**

   Write the message to publish to the topic.

   ![MQTTHQ web client Publish to topic form with topic mqttHQ-client-test, QoS 1 and payload Hello World!](https://docs.sixfab.com/wp-content/uploads/sixfab-docs/PicoLTE-MQTT-Example-7.png)

2. **Set broker and topics in config.json.**

   The full set of parameters:

   ```json
   {
       "mqtts":{
           "host":"[HOST_ADDRESS]",
           "port": [PORT_NUMBER],
           "client_id": "[CLIENT_ID]",
           "username":"[MQTT_USERNAME]",
           "password":"[MQTT_PASSWORD]",
           "sub_topics": [
                   ["[YOUR_MQTT_TOPIC_1]", [QoS]],
                   ["[YOUR_MQTT_TOPIC_2]", [QoS]],
                   ...
               ]
       }
   }
   ```

   MQTTHQ needs no client ID, username or password; set the host, the port and the topics:

   ```json
   {
       "mqtts":{
         "host":"public.mqtthq.com",
         "port": 1883,
         "sub_topics": [
                 ["mqttHQ-client-test", 1]
             ]
     }
   }
   ```

3. **Run script.**

   Open `examples/mqtt/subscribe.py` in Thonny and run it. When the log shows `Reading messages from subscribed topics...`, click **Publish** in the web client.

   ![MQTTHQ web client Publish to topic form with the Publish button highlighted and payload Hello World!](https://docs.sixfab.com/wp-content/uploads/sixfab-docs/PicoLTE-MQTT-Example-6.png)

4. **Read message.**

   The log shows the message received:

   ```text
   INFO: Subscribing to topics...
   INFO: Result: {'response': ['+QMTSUB: 0,1,0,1'], 'status': 0}
   INFO: Reading messages from subscribed topics...
   INFO: []
   INFO: [{'message_id': 3, 'topic': 'mqttHQ-client-test', 'message': 'Hello World!'}]
   ```

## Troubleshooting

A `timeout` error with QoS 0: set the QoS to 1 or 2 on the board and on all other clients.
