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.
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()
}
I've recently built such an architecture, maybe it will help you as a reference. Our players:
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With