MQTT using HiveMQ and micropython-adafruit-mqtt-esp8266 lib

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
davef
Posts: 813
Joined: Thu Apr 30, 2020 1:03 am
Location: Christchurch, NZ

MQTT using HiveMQ and micropython-adafruit-mqtt-esp8266 lib

Post by davef » Mon Jan 31, 2022 4:09 am

I have been able to connect to io.adafruit.com using this library:
https://github.com/miketeachman/micropy ... tt-esp8266
However, as far as I can understand that platform will not retain messages. I would like a remote ESP32 to connect once a day to get any new operating conditions.

I can get HiveMQ Cloud to work using mqtt cli which is installed on my laptop, for example:

Code: Select all

mqtt sub -h 660b2377cb7bxxxxxxxx5fbeef99a9e4.s1.eu.hivemq.cloud -p 8883 -s -u davef -pw -t 'wateringtimer1'
However, I am struggling to form this line properly so that my ESP32 script will connect:

Code: Select all

client = MQTTClient(client_id, mqtt_server)
It just hangs even after adding user then password.

When I add port=8883 like this:

Code: Select all

client = MQTTClient(client_id, mqtt_server, port=8883, user=b'davef', passwood = xyz)
I get the error:

Code: Select all

  File "umqtt/simple.py", line 108, in connect
IndexError: bytes index out of range
Looking at line 107 in umqqt/simple.py:

Code: Select all

resp = self.sock.read(4)
Is this error saying mqtt_server is too long or you are only allowed a certain number of parameters in MQQTClient() ?

I am using umqqt.robust

Based on the mmqt cli script I assume that I don't need to worry about certificates.

Sure would appreciate a pointer to what I am missing out here.

davef
Posts: 813
Joined: Thu Apr 30, 2020 1:03 am
Location: Christchurch, NZ

Re: MQTT using HiveMQ and micropython-adafruit-mqtt-esp8266 lib

Post by davef » Tue Feb 01, 2022 10:48 am

Some progress?

Looking at umqqt/simple.py it appears to me that if you want to use port=8883 then you have to enter port=0 and ssl=True. Then simple.py sorts out what is required to do the connect phase.

Now I get:

Code: Select all

File "umqtt/simple.py", line 110, in connect
MQTTException: 5
which according to viewtopic.php?t=5544 is a
Section 3.2.2.3 of the MQTT spec show that this bit pattern signifies "connection refused, identifier rejected", "The Client identifier is correct UTF-8 but not allowed by the server".
I have tried different ways of generating client_id to no avail.

Because ssl=True does that mean I have to do something with ssl_parms={}?

My current client format

Code: Select all

client = MQTTClient(client_id, server, port=0, user=b'davef', password=b'xyz', keepalive=60, ssl=True, ssl_params={})

Post Reply