Do Not Make It a Mess - Why There're So Many Endpoints in IoT Hub


点击此处查看中文版本

If you are a beginner for Azure IoT Hub, you may confused in IoT Hub endpoints.

Before we start, you must clear that IoT Hub is a channel, and a channel has two sides, device side and cloud side. The two sides have different ways to connect to IoT Hub.

On device side, you probably use an IoT Hub device SDK to connect to IoT Hub with device connection string which in format of HostName=xxx.azure-devices.net;DeviceId=xxx;SharedAccessKey=xxx. Then the SDK may use HTTP, AMQP or MQTT protocol to connect to IoT Hub. It's easy for device side cause you can send D2C messages, receive C2D messages, listen direct method and get or update device twin all in one endpoint.

However, it's another thing for cloud side. The cloud side can ONLY use AMQP to connect to IoT Hub. Also, you may have a question, why there isn't a receive-D2C-message sample in official IoT Hub service SDK repo on GitHub? Because you cannot receive D2C messages by using the same endpoint as sending C2D messages, there're two endpoints to send C2D messages and listen D2C messages independently.

If you would like to send C2D message, you can simply use the IoT Hub service SDK with IoT Hub connection string (find it from Shared access policies), but if you wanna receive D2C messages, you have to use an Event Hub SDK with IoT Hub Event Hub-compatible name and Event Hub-compatible endpoint (find them from Endpoints - Built-in endpoints - Events).

It's not the whole thing for cloud side. If you want to call direct method or get or update device twin, you need use RESTful API. You cannot do it in other ways on cloud side, but just RESTful API. There's nothing help for this in Azure portal, you need go to https://docs.microsoft.com/en-us/rest/api/iothub/devicetwinapi to learn more details.

Comments (0)

Skip to main content