We are going to use Field Gateways(hardware and software) for connecting 1 or more devices behind the Gateway to Azure IoT Hub. The devices can't connect to Azure IoT Hub themselves. Since only our Gateways will be connected to the Iot Hub we face with problem of Cloud to Sensor communication(we can connect only to the Gateway but not to the each Sensor directly as far as I understand). What is the best practices in this case to provide the Sensor's management through the Gateway from the Iot Hub side?
Of course it depends to what we actually need. In our case we need to support at least direct messages for Sensors (when user interact with Sensor through UI). Also the Sensors firmware update can be required.
One of the possible way is just using Cloud-to-Device messages and put the Sensor data in message body(including sensor id etc). So, the Gateway can receive the message and understand which Sensor should be called. But if the Gateway manages 100 Sensors it can be a problem since the max size of cloud-to-device queue is 50 messages. So this can be a bottleneck if more than 50 Sensors have to be notified at once(we still not have final business requirements). And of course we won't have the responses from the Gateway side(this approach can't be used for long term operation on the Sensors side), however the "Message feedback" feature can be enough in our case.
The other possible way is using Desired and Reported properties to store the Sensor specific information in Gateway device twin metadata. So both the Gateway and Cloud can manage the processes on the specific Sensor through device twin of the Gateway.
According to this scenario we should update the necessary information related to the specific Sensor in device twin of Gateway. Then the Gateway can handle this operation, determines the sensor_id and calls required Sensor. To avoid big size of JSON we can storing only the data for "in-progress" Sensors. For example if we are working with Sensor1 and Sensor10, both Desired and Reported properties will contain the related information of these Sensors. When the Cloud and\or Gateway finished communication we can remove the processed item of Sensor from device twin.
This solution looks ugly. Especially when the gateway will have 100 connected sensors for example.
Both these two solutions can be used together depending on our needs. But maybe somebody knows the best way to do it, we haven't enough experience with Azure and IoT.
UPD: Looks like I found the answer. And all other solutions is not our choices Act for other devices on Azure IoT Hub