locked
Multiple MQTT connections on a single IOT device RRS feed

  • Question

  • Using the azure-iot-sdk for python I have a program that opens a connection to the IoT Hub and continually listens for direct methods, using the MQTT protocol. This is working as expected. I have a second python program that I invoke from cron hourly, that connects to the IoT Hub and updates the device twin for my device. Again this is using MQTT. Everything is working fine.

    However I've come across in the documentation that a device can only have one MQTT connection at a time and the second will drop cause the first to drop. I'm not seeing this, however is what I'm doing unsupported?

    Should I have a single program doing both tasks and sharing a single connection?

    Friday, November 30, 2018 10:28 PM

Answers

  • Hello ADW555,

    Yes that is correct, you can't have more than one connection with the same device ID to the IoTHub. Eventually in time you will have inconsistency behaviors and that scenario is unsupported. You should use a single program with a unique device ID doing both tasks.

    Depending on the scenario you may want to consider using an iothubowner connection string to do service side operations like manage your IoT hub, and optionally send messages, schedule jobs, invoke direct methods, or send desired property updates to your IoT devices or modules.

    I noticed you asked the same question on SO here as well.

    Thank you!

     

    Monday, December 3, 2018 8:30 PM

All replies

  • Hello ADW555,

    Yes that is correct, you can't have more than one connection with the same device ID to the IoTHub. Eventually in time you will have inconsistency behaviors and that scenario is unsupported. You should use a single program with a unique device ID doing both tasks.

    Depending on the scenario you may want to consider using an iothubowner connection string to do service side operations like manage your IoT hub, and optionally send messages, schedule jobs, invoke direct methods, or send desired property updates to your IoT devices or modules.

    I noticed you asked the same question on SO here as well.

    Thank you!

     

    Monday, December 3, 2018 8:30 PM
  • Hello Antonio,

    Thanks for the confirmation. It seems from the documentation that this restriction applies to MQTT only? Could I have an MQTT connection open on my device for twin updates etc and periodically open an HTTP connection to the iothub as well for file uploads for example?

    Thanks

    Monday, December 3, 2018 11:33 PM
  • Hi,

    This applies to any protocol - you can't have more than one connection using the same deviceID. Can you detail better your scenario and why would you need to have two separate applications?

    Thanks

    Wednesday, December 5, 2018 2:26 AM