Page 1 of 1

Pico w mqtt_as to HiveMQ Cloud

Posted: Thu Aug 18, 2022 8:02 pm
by karl60
Newbie trying to understand MQTT

Situation: With a HiveMQ Cloud broker I can simultaneously pub/sub using:
  • * Mosquitto command line
    * Standard Python (on laptop) using HiveMQ code examples
    * Windows MQTT Explorer app
So I'm happy the HiveMQ Broker side of things is working OK.

But I can't get a Pico W with MQTT_AS connected to the HiveMQ Broker

I've added the following to the MQTT_AS config.py file and obviously populated secrets.py accordingly:

Code: Select all

config['server'] = secrets['hivemq_broker']
config['port'] = secrets['port']
config['user'] = secrets['hivemq_username']
config['password'] = secrets['hivemq_key']
With port set to 8883 I get the following error (I'm using the mqtt_as code example range.py as a basis):

Code: Select all

Checking WiFi integrity.
Got reliable connection
Connecting to broker.
Connection failed. Error: (-1, 'Connection closed by host')

I would appreciate a push in the right direction to solving this problem.
Thanks

Re: Pico w mqtt_as to HiveMQ Cloud

Posted: Mon Aug 22, 2022 2:23 pm
by danjperron
So I'm happy the HiveMQ Broker side of things is working OK.

But I can't get a Pico W with MQTT_AS connected to the HiveMQ Broker
Maybe print the config just in case something is not ok.

What is your source code ? Giving the config won't tell us if your code is OK!
Do you have the micropython reference code url?

If you have a Raspberry Pi or a linux server, try a local mosquitto broker first. Then when it is working you could try the internet broker.

Re: Pico w mqtt_as to HiveMQ Cloud

Posted: Mon Aug 22, 2022 4:51 pm
by pythoncoder
If you're using TLS (as implied by 8883) you need to set config['ssl'] = True. Please study the various tls examples.

The suggestion of developing code with a local mosquitto broker is a good one. Getting TLS working can be tricky and it's good to know that your code is solid before you attempt it.

Re: Pico w mqtt_as to HiveMQ Cloud

Posted: Thu Sep 15, 2022 10:12 am
by fishjoe
Im having the same problem so I wish to get some help.

Just few questions:
How should I get ssl work? Do i have to have any certificate file? Why do I not need when I using other client app.(they only need to "tick" on option "using SSL"). If so, where should I get whatever certificate file and where do I need to place it onto the device? How do I put it onto device, as it does not connect as flash drive?

Many thanks.

Re: Pico w mqtt_as to HiveMQ Cloud

Posted: Sat Oct 08, 2022 9:46 am
by fishjoe
worked out solution.

Code: Select all

client = MQTTClient(secrets.client_id, secrets.mqtt_server, port=secrets.mqtt_port, user=secrets.mqtt_username, password=secrets.mqtt_psd, ssl=True, ssl_params={
        "server_hostname": secrets.mqtt_server})
especially:

Code: Select all

ssl=True, ssl_params={
        "server_hostname": secrets.mqtt_server}