micropython / micropython/micropython-lib
MQTT: Unable to connect to Azure IoT Hub
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 2.9k
- Forks
- 1.1k
- Avg merge
- 7d 6h
- Merged PRs (30d)
- 3
Description
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
The report centers on umqtt.robust.MQTTClient.connect(), ussl.wrap_socket(), and MicroPython v1.22.2; begin by reproducing the Azure IoT Hub connection with the supplied ssl_params and inspect the exception at the wrapping step. Compare the behavior with the openssl s_client check described in the issue. Done means the cause and a verified connectivity resolution are documented or covered by an appropriate regression test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- azure, python
- Domain
- cloud, networking
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100