MQTT Broker Connection Issue

We have been experiencing issues in connecting to an MQTT broker using SSL/TLS authentication. We are using a Digi XBee 3 Cellular LTE-M/NB-IoT modem in trying to establish this connection.

I have been using a modified version of the script from page 158 of the “Digi MicroPython Programming guide” in conjunction with the simple.py MQTT connection module in this testing. I’ve installed the modem in a Digi XBee TH development board and monitor the testing progress using the MicroPython Terminal in XCTU.

I’ve found that if I use an unmodified version of simple.py, I receive a “TypeError: must use IPPROTO_SEC” message from MicroPython. If I use a modified version of simple.py that supports IPPROTO_SEC connections, a connection occurs, but I receive a CONNACK message from the broker indicating that the connection was refused due to an authentication failure.

The following is the main.py script I’m using in this testing (I’ve masked the USERNAME and PASSWORD for security reasons):

======================

from umqtt.simple import MQTTClient
import time, network

CLIENT_ID = ‘B4KZWFYIBE3LZO35ZUGWKZQG4YTSOJQHE3GMMJUGQ3DAMBQ’
MQTT_BROKER = ‘x658ebb8.ala.us-east-1.emqxsl.com
PORT = 8883
USERNAME = 'XXXXXXXXXX
PASSWORD = ‘XXXXXXXXXX’
TOPIC = ‘testtopic/1’

import socket, ssl
ssl_params = {‘ca_certs’: “/flash/cert/emqxsl-ca.crt”} # ssl certs
conn = network.Cellular()
while not conn.isconnected():
print(“waiting for network connection…”)
time.sleep(4)
print(“network connected”)

def publish_test(clientId=CLIENT_ID, hostname=MQTT_BROKER, sslp=ssl_params):

c = MQTTClient(CLIENT_ID, MQTT_BROKER, port=PORT, user=USERNAME, password=PASSWORD, ssl=True, ssl_params=sslp)
print("connecting...")
print(USERNAME)
print(PASSWORD)
c.connect()
print("connected")

print("publishing message...")
c.publish(TOPIC, '{"message": "HELLO"}')
print("published")
c.disconnect()
print("DONE")

publish_test()

=====================
]
I should mention that this problem only occurs using MicroPython code with the Digi modem. Running similar scripts using the PyCharm IDE with CPython on a PC results in successful connections with the broker.

Any help with this would be appreciated.