问题
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.
回答1:
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.
回答2:
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()
}
回答3:
I think the Azure IoT Gateway is still in Beta which might explain an absence of examples.
Here's a couple of pages that offer a little more insight:
Introducing the Azure IoT Gateway SDK (posted April 2016)
https://azure.microsoft.com/en-gb/blog/introducing-the-azure-iot-gateway-sdk-beta/
Supporting additional protocols for IoT Hub (Updated August 2016)
https://azure.microsoft.com/en-gb/documentation/articles/iot-hub-protocol-gateway/
Finally the actual beta SDK on GitHub, but assume you already have this:
https://github.com/Azure/azure-iot-gateway-sdk
I'd be interested to know the output of this. Most architecture I've encountered so far just has the devices talking to the hub directly so not had a requirement for the gateway yet.
回答4:
You may find this walkthrough useful: https://azure.microsoft.com/documentation/articles/iot-hub-linux-gateway-sdk-simulated-device/
It uses simulated devices to show how you can connect multiple devices through a gateway built using the Gateway SDK.
来源:https://stackoverflow.com/questions/39258588/azure-iot-hub-amqp-communication-multiplexing