Connection Failure: RPI Pico W to HiveMQ Cloud

Newbie trying to connect RPI Pico W using module mqtt_as to HiveMQ Cloud.

Using Port 8883 gives error code -1 ‘Connection closed by host’ (Instant error)
Using Port 1883 gives error code -1 ‘Timeout on socket read’ (After a delay)

Any guidance on how to resolve the connection issue would be welcome.

PS The Pico connects to my wifi OK.

Does your code work to connect to other brokers such as or on port 1883?

Thank you for your response. Code works perfectly with the public brokers ‘’, ‘’, ‘’ on port 1883.

Hi @karl60 ,

Nice to see your interest in MQTT and HiveMQ Cloud, please welcome to our community :wave:

Using port 1883 on HiveMQ Cloud doesn’t make any sense, there are only following ports available:

Port (TLS): 8883
Port (Websocket + TLS): 8884

To connect to 8883 you need:

  • hostname of your cluster;
  • username and password from the clusters MQTT Credentials;
  • HiveMQ Cloud requires the TLS-SNI extension to be available and used, please refer here and check if it is available in your system.
  • some devices require the root certificate. You can download the root certificate here.

I hope this helps,
Kind regards,
Dasha from HiveMQ