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, with its web client on the other side. No extra hardware is needed.
Before you begin
Hardware
- Sixfab Pico LTE or Pico LTE 2Registered and active in Sixfab Connect, connected to the computer with the micro USB cable.
Software
- Thonny with MicroPython and the Pico LTE SDKSet up as in the quickstart.
- config.jsonIn the root of the board: Prepare the configuration file.
Prepare broker
Go to MQTTHQ, note the Broker URL and the TCP Port, and click Try our Web Client Now.

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.
-
Subscribe in web client.
Click Subscribe, so that the client shows the messages of the board.

-
Set broker in config.json.
MQTTHQ needs no client ID, username or password: delete them. The full set of parameters:
{ "mqtts":{ "host":"[HOST_ADDRESS]", "port": [PORT_NUMBER], "pub_qos": [QoS], "client_id": "[CLIENT_ID]", "username":"[MQTT_USERNAME]", "password":"[MQTT_PASSWORD]" } }For MQTTHQ:
{ "mqtts":{ "host":"public.mqtthq.com", "port": 1883, "pub_qos": 1 } } -
Set message and topic.
Open
examples/mqtt/publish.pyin Thonny and setPAYLOADto your message andTOPICto the topic of the web client.
-
Run script.
The log reports the publication, and the message appears in the web client.

INFO: Publishing a message. INFO: Result: {'response': ['OK'], 'status': 0} INFO: Publish succeeded.
-
Prepare message in web client.
Write the message to publish to the topic.

-
Set broker and topics in config.json.
The full set of parameters:
{ "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:
{ "mqtts":{ "host":"public.mqtthq.com", "port": 1883, "sub_topics": [ ["mqttHQ-client-test", 1] ] } } -
Run script.
Open
examples/mqtt/subscribe.pyin Thonny and run it. When the log showsReading messages from subscribed topics..., click Publish in the web client.
-
Read message.
The log shows the message received:
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.