device twin reported property

Bhavin Dhola 20 Reputation points
2024-04-11T07:37:00.1766667+00:00

Hello Everyone,

Is it possible to completely delete the device twin reported property.

I know I can use

{

"property1": null,  

"property2": null  

}

but i have added many new reported property and would like to delete all in one go.

If yes, how can i do it using mqtt topic ?

Thanks

Azure Digital Twins
Azure Digital Twins
An Azure platform that is used to create digital representations of real-world things, places, business processes, and people.
231 questions
0 comments No comments
{count} votes

Accepted answer
  1. Sander van de Velde | MVP 32,736 Reputation points MVP
    2024-04-11T10:28:17.6466667+00:00

    Hello @Bhavin Dhola,

    welcome to this moderated Azure community forum.

    If I compare your question to what is offered for desired properties maintenance, I expect your need to remove each (high level) reported property yourself.

    Look at the portal experience of Azure IoT device twin:

    User's image

    The Azure portal tells us to remove each item, we cannot remove all desired properties at once:

    set the value of the item to be removed to 'null'.

    Your devices are the owner of their own reported properties, so the code in the devices need to maintain their reported properties.

    Only nested properties can be deleted all at once but you still have to set the highest level property to null.

    As an alternative, you could request the full twin using the "$iothub/twin/GET/?$rid=42" topic.

    note: this contains the desired properties also. An example written in C# is seen here.

    Then, you could iterate through the reported properties and remove them dynamically.

    This is probably a lot of code and only viable when you do not know the exact names of each reported property.


    If the response helped, do "Accept Answer". If it doesn't work, please let us know the progress. All community members with similar issues will benefit by doing so. Your contribution is highly appreciated.


1 additional answer

Sort by: Most helpful
  1. Deepanshukatara-6769 10,130 Reputation points
    2024-04-11T08:01:15.5+00:00

    Hi, Welcome to MS Q&A

    I think yes please find below detailed steps

    1. Connect to Azure IoT Hub: Use an MQTT client library to connect to Azure IoT Hub. You'll need to provide the appropriate connection parameters like the hostname, device ID, and SAS token.
    2. Publish the PATCH Request: Publish a message to the appropriate MQTT topic for updating reported properties. The topic should look like $iothub/twin/PATCH/properties/reported/?$rid={request_id}. Replace {request_id} with a unique identifier for the request.
    3. Payload: In the payload of the message, send an empty JSON object {}. This indicates that you want to delete all reported properties.
    4. Receive Response: Subscribe to the response topic to receive acknowledgment or response messages from Azure IoT Hub.

    Please check these docs and imag for ref

    User's image

    https://learn.microsoft.com/en-us/azure/iot/iot-mqtt-connect-to-iot-hub

    kindly accept answer if it helps, Thanks!, if you have any further questions , please let me know


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.