2

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?

TheCat
  • 31
  • 3
  • I don't know about Azure IoT in particular, but normally, as long as your Python programs use different MQTT `ClientId`s to connect to the broker, they should not interfere with each other. – Kit. Nov 30 '18 at 22:34
  • "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?" - For Azure IoT specifically, only one connection can be opened for one device identity at a time. You can connect multiple MQTT clients using different connection strings. – Yi Zhong - MSFT Dec 03 '18 at 17:27

1 Answers1

0

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.

asergaz
  • 996
  • 5
  • 17
  • 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? – TheCat Dec 04 '18 at 20:53
  • You can have a new connection to the IoTHub (from the same device) using any protocol as long as it doesn't use the same device ID – asergaz Jan 24 '19 at 12:09
  • @asergaz are you saying here that he would want to use an IoT MQTT broker that would connect to multiple clients usinga pub/sub method that would thus allow multiple bidirectional communications from other services/clients that are connected? – Christian Matthew Mar 30 '21 at 17:19
  • That can be an alternative. See also Azure IoT Edge MQTT Broker: https://learn.microsoft.com/en-us/azure/iot-edge/how-to-publish-subscribe?view=iotedge-2020-11 – asergaz Apr 07 '21 at 14:13