Messages and Topics from IoT Hub

Alexander Schäpper 96 Reputation points
2021-08-26T08:59:47.163+00:00

Hello together

I'm currently building a project on IoT Hub / Node-RED as well as SQL Server based on Azure. I was able to write Data from Iot Hub via Stream Analytics Service into my Azure MSSQL Database, and read it from Node-RED. This just as a background.

Now I tried to read "live" values via MQTT Node in Node-RED from the IoT Hub. There I can specify a topic and it would do the rest for me and I would have the value.

So the basic thing I would like to have is just to read a message by topic from IoT Hub, so I could specify something like:
devices/mydevice/messages/myvalue

My question is, is there any way to subscribe to a topic from Azure IoT Hub with a general purpose MQTT client? Is this planned in the future or is this completely against the purpose of IoT Hub? I'm searching now for hours and I don't seem to find this...

Or is there a service which can connect to IoT Hub, which then allows me to subscribe to topics?

Thank you for your answers!

Azure IoT Hub
Azure IoT Hub
An Azure service that enables bidirectional communication between internet of things (IoT) devices and applications.
1,272 questions
0 comments No comments
{count} votes

Accepted answer
  1. Alexander Schäpper 96 Reputation points
    2021-08-27T11:16:51.367+00:00

    Thanks a lot for your Answer!

    Yes I came across the links you mentioned, I don't have the ability to use C resp. implement the framework or use the SDK's, resp. it would be complete overkill. And from the description and manuals everywhere in the internet mentioned I was not 100% sure it doesn't work.

    Knowing that its not directly possible is also fine so I can stop searching for a way, I will no go by SQL Server only (Device - IotHub - StreamAnalyticsService - SQL - Node-RED)

    Greetings!

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. QuantumCache 20,366 Reputation points Moderator
    2021-08-27T00:05:07.003+00:00

    Hello @Alexander Schäpper

    Azure IoT Hub is not a generic MQTT broker, so you can't directly subscribe to messages sent from the device.
    devices/{device_id}/messages/events/ is used to send(not receive) D2C messages.

    To receive the Device-To-Cloud messages, you need to use the build-in endpoint messages/events. It is only exposed using AMQP protocol as this document mentioned. You can use Event Hub SDK to receive the C2D messages since the IoT Hub's endpoints are compatible with Event Hub's. You can refer to the link for the code sample and Event Hub SDK for this scenario:

    If you want to receive these messages(C2D) that sent by Device Explorer, the topic is devices/{device_id}/messages/devicebound/#.

    I hope you have come across these documentations:

    Receiving cloud-to-device messages

    Example in C using MQTT without an Azure IoT SDK

    Using the MQTT protocol directly (as a device)

    1 person found this answer helpful.

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.