skip to Main Content

I’m working Azure Function that sends data to few devices via IoT hub. I’m trying to log whole process and I am unsure if my current solution is sufficient.

So far I’m using message feedback(as mentioned in documentation) to log if device received send message.

"The IoT hub doesn’t generate a feedback message. If the cloud-to-device message reaches the Completed state, the IoT hub generates a feedback message." As I understand it if I receive said feedback it is confirmation that message was successfully/unsuccessfully received by device.

Is my understanding that this is absolute confirmation that message was or wasn’t received by device correct? Or is there another option to get is confirmation?

2

Answers


  1. I recommend reading through the section Receive Cloud to Device Delivery feedback for better understanding on this. The section explains how you can set the Acknowledgment feedback option. The Azure IoT Hub provides feedback in both Positive and Negative scenarios.

    If you have set the message Ack to full as indicated in the article using the following code commandMessage.Ack = DeliveryAcknowledgement.Full;, you will receive a message in both Completed as well as Dead lettered scenarios (Positive and Negative outcome).

    enter image description here

    If you are specifically targeting the success messages, you would need to set the acknowledgement to Positive. The feedback you then receive is a confirmation proving that message was successfully received by device.

    Hope this helps!

    Login or Signup to reply.
  2. I followed the below steps to send a message to an IoT device using azure function.

    Additional answer wrto @LeelaRajesh_Sayana.

    • Created a IoT hub and added the device
      enter image description here

    • Add the device name and click on save

    enter image description here

    • Select the device you created and click on send message

    enter image description here

    • Enter the message to send

    enter image description here

    • To create a particular condition, we have code it. I have used C# function time trigger to send message IoT Hub messages and added the below condition .
    try
    { 
        log.Loginformation($"Message sent : {message}");
    }
    catch (Exception ex)
    {
        log.LogError($"Error sending message :{ex.Message});
    }
    
    
    using System;
    using Microsoft.Azure.Devices;
    using Microsoft.Azure.WebJobs;
    using Microsoft.Extensions.Logging;
    
    namespace AzureFunctionIoT
    {
        public static class SendMessageToIoTDevices
        {
            [FunctionName("SendMessageToIoTDevices")]
            public static void Run([TimerTrigger("0 0 0 * * *")]TimerInfo myTimer, ILogger log)
            {
                string connectionString = Environment.GetEnvironmentVariable("IoTHubConnectionString");
                ServiceClient serviceClient = ServiceClient.CreateFromConnectionString(connectionString);
                
                var message = new Microsoft.Azure.Devices.Message(System.Text.Encoding.ASCII.GetBytes("Hello IoT Devices"));
                serviceClient.SendAsync("<DeviceId>", message).GetAwaiter().GetResult();
                
                log.LogInformation("Message sent successfully");
            }
        }
    }
    

    Run the messages with Azure IoT Hub (.NET) Code

    enter image description here

    enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search