Not receiving message for subcribed topic from Azure IoT MQTT broker - azure

Please, help me to resolve this issue, I have tried all the options...
i used MqttClient client to subcribed iot hub mqtt broker using topic
devices/t2c-171bdd65-407d-4de9-992b-36cee0914b3f/messages/devicebound/#
but I wasn't able to receive any callback...
I am running this application from my local machine and connecting to Azure IoT hub MQTT broker. well, I am able to publish message to IoT hub, I can confirm this because IoT hub message count is increasing & device explorer running on my local machine is displaying message in monitor mode.

I'm supposing you're using M2MQTT nuget package for MQTT client.
I have some sample code that proves working on my local PC and my Azure IoT Hub. You can find it in https://github.com/ghjackie/AzureIoTDemo
You need to follow the tutorial from here to modify the deviceId, hostName, etc...

Related

Simulated device with Azure Function on IoT Hub is not able to trigger

Currently I have simulated device that receives message from IoT Hub and processes it and after it is done, device sends message to IoT Hub. The device is working but it is running as .exe file on computer and Im trying to transform it and upload on Azure as function so I can avoid it not working when computer turns off or freezes while Im not around it.
I wanted to make it function triggered by events on IoT Hub but Im facing problem. Currently the function that sends message, sends it directly to device on IoTHub(my device) but in case like this, message is not "displayed" on IoT Hub so Im unable to use it as trigger. I'm unable to change function that sends message to device. Are there any options how to catch those messages on IoTHub or possibility to trigger it any other way?
There is no direct way to send messages from Azure function to Azure IoT Hub. You can probably utilize Device event Azure IoT Hub Rest API end point from the Azure Function and send the message to the Azure IoT Hub. Here is the request you can make to send the message to Azure IoT Hub.
POST https://fully-qualified-iothubname.azure-devices.net/devices/{id}/messages/events?api-version=2020-03-13
Please find the following reference to all the Supported bindings for Azure Functions runtime
You can trigger the Azure Function by using the IoT Hub trigger. Refer the following resource that runs you through the steps needed to set up the Azure IoT Hub trigger for Azure Functions

What is the behavior of IoT Hub when the device send telemetry message without registered in IoT Hub?

I seems to cannot get this information anywhere. I would like to know what will happen to the telemetry message if the device that send this message is not registered in IoT Hub.
This is because I found a few messages from an unregistered device in IoT Hub being processed to the built-in event hub and progress to my next Function App after the built-in event hub.
Thus, I would like to know how is the behavior of IoT Hub if the message was sent without the device registered under the IoT Hub.
Thank you.
This is a really excellent question because it depends on how you connect to the IoT Hub. For my answer, I will take into account MQTT, AMQP, and HTTP. When you connect to an IoT Hub with a device ID that doesn't exist, you will see the following error codes:
MQTT: 401003 IotHubUnauthorized
AMQP: 404001 DeviceNotFound
HTTP: 404001 DeviceNotFound
Now if you have a registered a device but disabled it in IoT Hub, the errors are the same but you won't find the MQTT error in your trace. Instead client side you will receive a Server Unavailable error.
If you want, you can see these error codes for yourself by enabling tracing on the device connect/disconnect events.
So in closing: the behaviour of the IoT Hub is to not allow any devices to connect when unregistered.
In addition to Matthijs van der Veer answer, in the case of connection oriented direct protocol such as MQTT, when the registered device has been connected and the telemetry data is sent under the topic with unregistered device, for instance:
devices/UnregisteredDeviceId/messages/events/$.ct=application%2Fjson&$.ce=utf-8
then, the connected device is immediately disconnected from the IoT Hub.
I do recommend the following:
route your telemetry data messages to the blob storage
export ("excludeKeys":false) all device identities to the blob storage
find some messages which are not in the IoT hub identity registry entry
call the MS support and create the ticket for this issue

How to subscribes to topic on mqtt broker with Azure IOT HUB as i want the data to be stored in Azure iot hub when I published my topic

im new to mqtt and currently trying to setup a mqtt protocol to send data from a gateway devices to azure iot hub. The problem i facing was I couldn't figure out which way that I can received and store data on IoT Hub when i published my data on mqtt broker. The textbook way is to subscribe the mqtt broker using Azure IOT Hub but how should I do it?
Assuming I am doing testing using a laptop
Read data stored in json file -> published to topic "data/device1" -> Data stored in Azure IoT Hub
I tried reading the Azure IoT HUB MQTT Connections but it doesnt work out for me. PLease Help
By default Azure IoT Hub makes incoming telemetry messages available on its Event Hub-compatible endpoint: https://learn.microsoft.com/en-us/azure/iot-hub/iot-hub-devguide-messages-read-builtin It does not matter over which protocol (MQTT, AMQP or HTTPS) you sent in the messages to IoT Hub - they all will land in that endpoint.
From there you can read the information using HTTPS or AMQP. I would recommend to use the Event Hub SDK or use a stream processing service like Azure Stream Analytics or Spark Streaming, which supports Event Hub directly.

Receiving D2C messages from an IoT Hub in browser

I am working on a simple dashboard for showing IoT data in a browser.
So far, I was using the Paho MQTT client library and a public MQTT broker to receive data. However, I'd like to use the Azure IoT Hub from now on.
The data I'm sending is just simple temperature and humidity values.
I already found out that I can't connect to the IoT Hub via MQTT. So my question is:
Is there a possibility to connect (eg. using javascript) directly to IoT Hub and read the data?
If not, what's my best option?
I thought about saving the messages to an SQL Database and reading from that, but that seems quite complicated for what should be a simple IoT use case (showing real-time data)
Thank you in advance!
You can connect to IoT Hub via MQTT. Please take a look at this documentation for detail. We also have a Node.js SDK for connecting to IoT Hub if you don't want to deal with MQTT directly. I know you are working on your own dashboard, but have you looked at Azure IoT Solutions Accelerator? It's completely open source and you can modify it as you want.

Communication between Azure IoTHub and Azure IoTEdge?

I have cloned Azure IoT Edge from https://github.com/Azure/iot-edge. And build this using build.sh script resides in tools directory.
Now I run sample application "simulated device" and it communicates with the Azure IoT Hub. But now I want to send messages from IoTHub to this Simulated device app, it has Receive function which receive data from IoTHub. So I used device explorer to send messages, but every time it does not deliver to simulated device at instatnly, but when I restart simulated device program again, then that previous message has received. Could you please tell me, what I have to do for message receiving from IoT Hub to Azure IoT Edge?
If the simulated device is connecting to IoT Hub using HTTPS, it checks for cloud-to-device messages when it starts up, and then polls for cloud-to-device messages. The recommended polling time is to check every 25 minutes. If the simulated device uses AMQP or MQTT, cloud-to-device messages are pushed to the device. For more information see:
https://learn.microsoft.com/azure/iot-hub/iot-hub-devguide-protocols
https://learn.microsoft.com/azure/iot-hub/iot-hub-devguide-c2d-guidance

Resources