Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure IoT Hub AMQP Communication Multiplexing

In some of the Microsoft documentation for working with Azure IoT hubs, it mentions that it is possible to multiplex the communication of multiple devices under a single TLS connection (using the AMQP protocol) for scenarios where multiple simple devices talk to a local hub device that is powerful enough to communicate with the IoT Hub. Are there any examples of how one would implement this multiplexing? The DeviceClient library does not appear to support this (although I could be wrong). There have also been mentions of the IoT Gateway SDK for this scenario, but I haven't found a clear example of how to set multiplexing up using that either. Any advice or references to other material would be appreciated.

like image 316
Nathan G Avatar asked Aug 31 '16 20:08

Nathan G


2 Answers

The C# DeviceClient does support multiplexing multiple devices using a single Amqp/TLS Connection. Here is a sample that connects three devices to IotHub using a single Amqp Connection:

             var devices = new Device[3];
             for(int i = 0; i < 3; i++)
             {
                devices[i] = new Device();
                devices[i].Id = Guid.NewGuid().ToString();
                devices[i] = await registryManager.RegisterDeviceAsync(device);
             }

             var deviceClients = new DeviceClient[3];
             for(int i = 0; i < 3; i++)
             {                          
                var auth = new DeviceAuthenticationWithRegistrySymmetricKey(devices[i].Id, devices[i].Authentication.SymmetricKey.PrimaryKey);
                var deviceClients[i] = DeviceClient.Create(
                    <IotHubHostName>,
                    auth,
                    new ITransportSettings[]
                    {
                        new AmqpTransportSettings(Client.TransportType.Amqp_Tcp_Only)
                        {
                            AmqpConnectionPoolSettings = new AmqpConnectionPoolSettings()
                            {
                                Pooling = true,
                                MaxPoolSize = 1
                            }
                        }
                    });
                 await deviceClients[i].OpenAsync()
              }
like image 116
Rajeev Vokkarne Avatar answered Sep 19 '22 13:09

Rajeev Vokkarne


I've recently built such an architecture, maybe it will help you as a reference. Our players:

  • Field Gateway - A local hub that is strong enough to handle communication to the IoT Hub and receive data from edge sensors.
  • Edge Sensors - devices that are unable to connect directly to the IoT Hub but implement some communication protocol that enable them to connect to the field gateway(Zwave, Zigbee...).
  • IoT Hub - Handles the D2C and C2D between the Field Gateway and the Hub.
  • Back end server - Receives the data from the IoT Hub.

The Edge Sensor sends their telemetry to the Field Gateway. The Field Gateway maintains a connection to the IoT Hub and the only device that the IoT Hub knows is the Field Gateway.

Each telemetry that is being received in the Field Gateway from the Edge Sensors contains a unique id in the message payload.

When the message is being received in the IoT Hub, The IoT Hub knows only about the Field Gateway. But when the message is being processed by the Back End it takes the unique id from the payload and therefore knows which is the correct device that sent the telemetry.

So we have multiple devices that are all "riding" on one connection.

Hope it will help.

like image 44
shachar Avatar answered Sep 18 '22 13:09

shachar