Can PR58-1_MQTT connect to Azure IoT Hub?

Is it possible to connect the PR5801_MQTT directly to an Azure IoT Hub? I am trying but failing, any feedback if this is possible and what the settings would be, would be appreciated.

I actually have an article on that here:

Let us know if you have any questions on that.

Thank you,
Travis

Looks to be from AWS not Azure, but using certs instead of string. I will give cert auth a try and see how that goes.

Oh, I’m sorry. Not sure why I thought you were on AWS.

Azure is a bit trickier but I do believe you can manually provision a device on Azure IoT and download certs. That should do what you need. If not please let us know.

Thank you,
Travis

I created the device, generated a certs for a ca, then applied them and still get the red flasshing light. I also took the same device certs and used a python script to send a test message and that worked. I feel at this point i just dont have the right combo in the sensor’s settings.

Are you able to publish successfully to that same topic from the python script without being disconnected? Can you test with MQTT Explorer here:

In MQTT explorer, got it to work and i could send on the topic. When i executed the python while that was connected it would disconnect the mqtt explorer. I noticed getting that to work that mqtt explorer required a username, so i put that in there: {iot-hub-name}.azure-devices.net/{device-id}/?api-version=2021-04-12

Added the username to the device and still get the flashing reds.

The python if curious:

import logging
from azure.iot.device import IoTHubDeviceClient, X509, Message

logging.basicConfig(level=logging.DEBUG)

x509 = X509(
    cert_file="<filename>.pem",
    key_file="<filename>.key",
    pass_phrase=None  
)

client = IoTHubDeviceClient.create_from_x509_certificate(
    device_id="<device_id>",
    hostname="<hubname>.azure-devices.net",
    x509=x509
)

try:
    logging.info("Connecting to IoT Hub...")
    client.connect()
    logging.info("Connected to IoT Hub.")

    message = Message("Hello from device")
    message.custom_properties["$.ct"] = "text/plain"
    message.custom_properties["$.mid"] = "12345"
    
    # Set the topic for the message
    message.content_type = "text/plain"
    message.content_encoding = "utf-8"
    message.message_id = "12345"

    logging.info("Sending message to IoT Hub...")
    client.send_message(message)
    logging.info("Message sent successfully.")

except Exception as e:
    logging.error(f"An error occurred: {e}")

finally:
    logging.info("Disconnecting from IoT Hub...")
    client.disconnect()
    logging.info("Disconnected from IoT Hub.")

Let me do some testing on this today. I have not attempted connecting these sensors directly to Azure IoT Hub yet. It should be possible however. I will let you know what I find.

Thank you,
Travis