Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MQTT: Unable to connect to Azure IoT Hub #811

Open
noefischerch opened this issue Feb 27, 2024 · 1 comment
Open

MQTT: Unable to connect to Azure IoT Hub #811

noefischerch opened this issue Feb 27, 2024 · 1 comment

Comments

@noefischerch
Copy link

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.

@Sultan-Kathat
Copy link

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

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants