← index #811Issue #977
Related · high · value 3.305
QUERY · ISSUE

MQTT: Unable to connect to Azure IoT Hub

openby noefischerchopened 2024-02-27updated 2024-03-10

I'm unable to connect to Azure IoT Hub using the umqtt.robust library with SSL using MicroPython v1.22.2. No explicit error message is provided by the connect method, making it difficult to diagnose the issue further (it fails when wrapping the socket:self.sock = ussl.wrap_socket(self.sock_raw, **self.ssl_params))

from umqtt.robust import MQTTClient

HUB_HOSTNAME = "AzureIoTHubHostName"
PORT = 8883
CLIENT_ID = "DeviceId"
USERNAME = f"{HUB_HOSTNAME}/{CLIENT_ID}/?api-version=2021-04-12"
PASSWORD = "SASToken"
TOPIC = f"devices/{CLIENT_ID}/messages/events/"
MESSAGE = b"Hello Azure IoT Hub!"
CADATA_PATH = "cadata_path"

with open(CADATA_PATH, "rb") as f:
    cadata = f.read()

ssl_params = {"cert_reqs": ussl.CERT_NONE, "cadata": cadata}

client = MQTTClient(
    CLIENT_ID,
    HUB_HOSTNAME,
    port=PORT,
    user=USERNAME,
    password=PASSWORD,
    ssl=True,
    ssl_params=ssl_params,
)

client.connect()

client.publish(TOPIC, MESSAGE)

client.disconnect()

I have tested my certificate file with openssl to check if the handshake occurs (openssl s_client -connect), and it works ok.

Could anyone advise on how to resolve this connectivity issue with Azure IoT Hub using MicroPython? Any guidance would be greatly appreciated.

1 comment
Sultan-Kathat · 2024-03-10

check this discussion, they have introduced some major change in the MQTTClient class

https://github.com/orgs/micropython/discussions/13624

CANDIDATE · ISSUE

Unable to connect to MQTT: unexpected keyword argument 'ssl_params'

closedby Oukayuuopened 2025-02-24updated 2025-02-24

I want to use MQTTClient to publish message to AWS IoT core.
So I use MQTTClient class in micropython/umqtt.simple/umqtt/simple.py as this blog saying.
mqtt = MQTTClient(client_id=client, server=endpoint, port=8883, keepalive=1200, ssl=True, ssl_params=sslp)

But I can not link to AWS IoT core for this error:
Unable to connect to MQTT: unexpected keyword argument 'ssl_params'

So I checked the class and found there is no ssl_params using any more.
class MQTTClient: def __init__( self, client_id, server, port=0, user=None, password=None, keepalive=0, ssl=None, ):

How can I fix this problem by using private key and certification to link AWS IoT core?

Thank you very much!

1 comment
Oukayuu · 2025-02-24

I have fixed this problem,so close this issue.
Thanks.

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied