Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UpdateReportedPropertiesAsync not updating device twin #340

Closed
amogh79 opened this issue Jan 18, 2018 · 9 comments
Closed

UpdateReportedPropertiesAsync not updating device twin #340

amogh79 opened this issue Jan 18, 2018 · 9 comments
Assignees
Labels
investigation-required Requires further investigation to root cause this.

Comments

@amogh79
Copy link

amogh79 commented Jan 18, 2018

  • OS and version used: Windows 10

  • SDK version used: Microsoft.Azure.Devices.Client 1.6.1

Description of the issue:

I am simulating a device for desired properties changed event. I am using UpdateReportedPropertiesAsync method on DeviceClient to update reported properties, I don't get any error but the reported properties for the device are not getting updated. I checked both on IoT hub and retrieving the devicetwin using GetTwinAsync from within the code. We are nearing a release next week and any help on this would be highly appreciated.

Code sample exhibiting the issue:

Console log of the issue:

@invinctus
Copy link

I can also reproduce this it seems to not write properties when you are using arrays.

var prop = new TwinCollection("{\"collection\":[{\"Id\": 1}]}"); This wont update the properties
var prop = new TwinCollection("{\"collection\":{\"Id\": 1}}"); This updates ok.

Is it not possible to have a json array in the twin data?
Should the method not return some indication that it is unable to write these properties?

@amogh79
Copy link
Author

amogh79 commented Jan 18, 2018

For me its failing in all cases. Following is the code snippet wherein it fails and doesn't update the reported properties for the device.

`TwinCollection test = new TwinCollection(
"{\r\n "softwareConfig": {\r\n "softwareName": "reg003SE",\r\n "version": "2.0.0",\r\n "softwareURL": "OneDrive_1_12-21-2017.zip",\r\n "serialNumber": "demotestdevice01",\r\n "softwarePackageId": "da475a46-405c-4388-bc3e-67e6fae83bba"\r\n },\r\n "$version": 6\r\n}");

            await _client.UpdateReportedPropertiesAsync(test);`

Following is the formatted Json

{
"softwareConfig": {
"softwareName": "reg003SE",
"version": "2.0.0",
"softwareURL": "OneDrive_1_12-21-2017.zip",
"serialNumber": "demotestdevice01",
"softwarePackageId": "da475a46-405c-4388-bc3e-67e6fae83bba"
},
"$version": 6
}

@invinctus
Copy link

@amogh79 you can get yours to work if you omit the "$" in the "$version" property it doesn't seem to like properties that begin with $

@amogh79
Copy link
Author

amogh79 commented Jan 18, 2018

Jeez how come I forgot that properties starting with "$" are readonly. Thanks for your inputs @invinctus.
You can use TwinCollection.ClearMetaData() to clean it off readonly properties.

@CIPop
Copy link
Member

CIPop commented Jan 18, 2018

Jeez how come I forgot that properties starting with "$" are readonly. Thanks for your inputs @invinctus.

@amogh79 does this mean that it worked for you after removing "$"?

Should the method not return some indication that it is unable to write these properties?

The service should return an error. If the "$" was the reason you couldn't update properties, I'd like to repurpose this issue to track the lack of error reporting.

I can also reproduce this it seems to not write properties when you are using arrays.

@invinctus Does it work if you add properties on the collection instead of parsing them from a string?
Also, please open a separate issue to track correct array parsing (I'd like to keep this as higher priority for updating properties / getting correct errors).

@CIPop CIPop added the investigation-required Requires further investigation to root cause this. label Jan 18, 2018
@amogh79
Copy link
Author

amogh79 commented Jan 19, 2018

@CIPop Yes it worked for me after removing '$'. As per device twins's documentation here it says some properties are readonly and are set by device/platform. I believe the one's starting with '$' are readonly.

@invinctus
Copy link

@CIPop the documentation does say arrays are not supported I didn't notice that initially. The biggest issue really is the lack of error reporting when you try to write something that is not supported.

@CIPop CIPop added the area-service Issue points to a problem in the service. label Jan 20, 2018
@CIPop
Copy link
Member

CIPop commented Jan 20, 2018

Thanks @amogh79 and @invinctus ! Glad to see you are unblocked!
I would like to investigate not getting an error which at this point seems to be a service-side issue.

@simonporter I'm not very familiar with the Service SDK but in general we would expect the server side to report back if any of the data was incorrect. Is there any reason that the server would accept both the array and $ param changes silently?

@zolvarga zolvarga self-assigned this Mar 1, 2018
@zolvarga zolvarga removed the area-service Issue points to a problem in the service. label Mar 6, 2018
@zolvarga
Copy link
Contributor

zolvarga commented Mar 6, 2018

@amogh79 @invinctus @CIPop

If we send invalid names in reported properties service will send back rejection with status 400.
The handling of those error codes were missing in the Device Client code.

I added handler for that, currently in PR. As soon it will be merged I will close this issue.

Best Regards,
Zoltan

varunpuranik pushed a commit to varunpuranik/azure-iot-sdk-csharp that referenced this issue Dec 13, 2018
timstewartm pushed a commit to timstewartm/azure-iot-sdk-csharp that referenced this issue May 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
investigation-required Requires further investigation to root cause this.
Projects
None yet
Development

No branches or pull requests

4 participants