How to display array telemetry?

Zhihao Zhang 1 Reputation point
2022-12-22T15:06:09.79+00:00

Hello,
In my case, i have a device which sometimes will generate many alarms, i want to send a JSON {"alarms":[1,2,3,4]}.
Is there anyway to display the alarms separately? 273411-image.png
And can i map the value to string? for example, if the value is 1 then print the value "Alarm 1".

Regards.

Azure IoT
Azure IoT
A category of Azure services for internet of things devices.
418 questions
{count} votes

2 answers

Sort by: Most helpful
  1. chbeier 1,871 Reputation points
    2023-02-16T13:12:54.81+00:00

    Hello Zhiaho Zhang,

    Have you checked the internal and external mapping guides?
    I am not sure if the internal mapping can deal with arrays, the external data transformation with device bridge due to custom code in an additional Azure Function should provide you the capabilities to achieve your expected results.

    0 comments No comments

  2. AshokPeddakotla-MSFT 35,961 Reputation points Moderator
    2023-03-02T03:21:51.27+00:00

    We have not heard from you for a long time, Hope you have found an answer to your query.

    If not, In addition to the above response. See the below suggestions which might help you with your scenario.

    We have more or less 100 types of alarm, and depend on the device, the alarm code will change, the device which is connected to Azure is esp32, so if it is possible we want to send the alarm code to save the memory and let the server side to parse the value, and if it is possible, we also want to map the value depend on the id field, for example,
    {"id":x, "alarms":[2]} if the id is 0 then 2 means "Emergency stop", if the id is 1 then 2 means "High temperature".

    You could try creating a property graph that maps the "alarms" JSON array to individual properties. For example, you could create properties named "Alarm 1", "Alarm 2", "Alarm 3", etc., and map the values of the "alarms" array to these properties. This would allow you to display each alarm separately on your dashboard.

    Here's an example of how you can define a device template that includes an "alarms" telemetry property with mappings for the alarm codes:

    {
        "$schema": "https://azureiotcentral.com/schemas/1-preview/device-template.json",
        "contents": {
            "devices": {
                "<device-template-id>": {
                    "displayName": "<device-template-display-name>",
                    "description": "<device-template-description>",
                    "telemetry": [
                        {
                            "name": "alarms",
                            "displayName": "Alarms",
                            "type": "Object",
                            "mapping": {
                                "type": "map",
                                "fields": [
                                    {
                                        "name": "1",
                                        "displayName": "Alarm 1"
                                    },
                                    {
                                        "name": "2",
                                        "displayName": "Alarm 2"
                                    },
                                    {
                                        "name": "3",
                                        "displayName": "Alarm 3"
                                    },
                                    {
                                        "name": "4",
                                        "displayName": "Alarm 4"
                                    }
                                    // You can add more mappings as needed till 100 in your case
                                ]
                            }
                        }
                    ]
                }
            }
        }
    }
    
    

    In the above example, the "alarms" telemetry property is defined as an object with a mapping type of "map", which allows you to define a set of key-value pairs for the alarm codes and their corresponding display names. You can add more mappings as needed to support your 100 types of alarms.

    Once you have defined your device template, you can use it to create a device in Azure IoT Central and start sending telemetry data with the "alarms" property set to a JSON object containing the alarm codes. For example:

    {
        "alarms": {
            "1": true,
            "2": true,
            "3": false,
            "4": false
        }
    }
    
    

    This will send an "alarms" telemetry message indicating that alarms 1 and 2 are active, and alarms 3 and 4 are inactive.

    Hope this helps you to get started and succeed in achieving your scenario.

    Feel free to comment in the below section for further help in this matter.

    0 comments No comments

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.