Filtering raw data

PhangGuanRongEE-8742 20 Reputation points
2023-06-09T06:00:01.8733333+00:00

I have a device that sends a string of hexadecimal values to Azure IoT Hub device, is there any service that allows us to program to filter the raw data from Azure IoT hub device?

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

Accepted answer
  1. LeelaRajeshSayana-MSFT 13,456 Reputation points
    2023-06-10T02:19:43.3433333+00:00

    Hi @PhangGuanRongEE-8742 Greetings! Welcome to Microsoft Q&A forum. Thank you for posting the question here.

    When you say the string is received in hexadecimal format, does the body of the routed message from IoT Hub look something like this - "Body":"eyJ0ZW1wZXJhdHVyZSI6MTIsImh1bWlkaXR5Ijo0NX0="

    If so, it implies that the telemetry data being sent from the device is not properly formatted in UTF-8 and the content type is not set to application/json before sent to Azure IoT Hub. By using Message class from Microsoft.Azure.Devices.Client in your code, you can set these properties to your message before sending event to Azure IoT Hub. Please refer the below sample code for more details

                var telemetryDataPoint1 = new
                {
                    messageId = _messageId1++,
                    deviceId = deviceId1,
                    source = channel[Rand.Next(0,2)],
                    temperature = currentTemperature,
                    humidity = currentHumidity
                };
                string messageString = JsonConvert.SerializeObject(telemetryDataPoint1);
                Message message = new Message(Encoding.ASCII.GetBytes(messageString));
                message.ContentEncoding = "utf-8"; 
                message.ContentType = "application/json";
                message.Properties.Add("temperatureAlert", (currentTemperature > 30) ? "true" : "false");
    
                await deviceClient1.SendEventAsync(message);
    

    After setting these properties, you should be able to receive the data in plain string on IoT Hub. Hope this helps.

    If you are using a different SDK or other approach to send data, kindly share the information with us so that the community can provide more specific feedback for your use case.


    If the response helped, please do click Accept Answer and Yes for the answer provided. Doing so would help other community members with similar issue identify the solution. I highly appreciate your contribution to the community.

    0 comments No comments

0 additional answers

Sort by: Most helpful