14

I am working on the Azure IoT platform, and I understand how devices send data to the IoT hub (if I am not wrong, It is just web service call or something similar to that).

But I wonder how the IoT hub sends Data/Command/Input to the devices, because we are not working on the IoT hub for Device communication (we don't have any requirement to push data to devices). Can the IoT hub directly interact with the devices? (Using the unique Id of device or using any unique identity like IP, Mac address, etc).

Somewhere I've read that devices keep requesting to the IoT hub if IoT hub have any input for them, and the IoT hub then sends Data/Command/Input to devices in response. Is that true? If not, then please explain.

peterh
  • 551
  • 1
  • 3
  • 16
Shri
  • 341
  • 1
  • 10

1 Answers1

14

The model that IoT Hub connected devices use is that they will never accept incoming connections. IoT Hub devices never act as a 'server', and this is a crucial part of the security model in Azure IoT. The definitive model on this is encapsulated in Clemens Vasters' 'Service Assisted Communication'.

Therefore devices are always 'polling' an external service in order to send data or receive commands. The APIs make it look like data is being sent to a device, but it is always the device making the outgoing connection.

IoT hub does this in two ways:

  1. By sending data to the device endpoint /devices/{deviceId}/messages/devicebound. This is an AMQP messaging endpoint, similar to a queue or topic subscription. The device, when reading commands, needs to acknowledged receipt if needed, which is part of the underlying AMQP protocol. This works the same with MQTT, and https is a valid fallback. The API wraps all of this up for you. There are additional concepts, such as 'direct methods' which are an API wrapper around essentially the same underlying message protocol
  2. By using the server-side device twin, which is a way to logically keep properties in sync between device and server. You set a property on the device twin, and when the device syncs up that property will be synced to the device. This is less message-based and built on top of the LWM2M device management protocol.

A lot of the 'polling', connecting, sharing connections, receipts, etc should be taken care of as part of the AMQP (or MQTT) protocol, which in turn is wrapped up in the IoT Hub SDK. So the above is highly simplified, but to reiterate, IoT Hub cannot, and will not (ever) try and send data to a ip address/port on your device.

Simon Munro
  • 1,493
  • 10
  • 13