Steps to reproduce:
- Try to update any key using ModuleClient.UpdateReportedPropertiesAsync method.
- Get the latest twin using ModuleClient.GetTwinAsync method.
- When you get the twin after updating then it contains the older version of reported properties.
Note: The code is working in the Local environment but when we deploy it in azure as a custom module then it stops working.
I have attached a log for reference.
Twin Before Update:
{
"deviceId": null,
"etag": null,
"version": null,
"properties": {
"desired": {
"general": {
"autoUpdate": false
},
"specific": {
"autoUpdate": false
},
"$version": 1
},
"reported": {
"$version": 1
}
}
}
Twin After Update:
{
"deviceId": null,
"etag": null,
"version": null,
"properties": {
"desired": {
"general": {
"autoUpdate": false
},
"specific": {
"autoUpdate": false
},
"$version": 1
},
"reported": {
"$version": 1
}
}
}
Below code I have tried
public async Task UpdateReportedProperties(TwinCollection twinCollection)
{
await _moduleClient.UpdateReportedPropertiesAsync(twinCollection);
ModuleTwin = await _moduleClient!.GetTwinAsync();
}
The sample code below interacts with Azure IoT Hub using the Azure IoT SDK. It retrieves the device twin, updates the reported properties, and then retrieves the updated twin using
UpdateReportedPropertiesAsyncandGetTwinAsync. The code utilizesMicrosoft.Azure.Devices.Client, GetTwinAsync, and UpdateReported (or) with REST API with C#.Output:
Azure:
The code below is a sample for connecting to Azure IoT Devices Get Twin using the REST API.
Azure IoT Devices Update Twin can be done using the REST API with this link.