PelionIoT / mbed-cloud-sdk-dotnet

Pelion Device Management SDK for .NET
Apache License 2.0
10 stars 2 forks source link

Enclosing quotes pushed to device? #192

Closed stevew817 closed 6 years ago

stevew817 commented 6 years ago

I'm exercising the API like so: capi.SetResourceValueAsync(dev.Id, "/32111/0/32101", "Free", true);

I'm expecting this to set the resource 32111/0/32101 (which is a string-type resource) to Free. However, on my device, I see that the resource value is being written as "Free". Something along the chain is thus inserting double quotes. Any idea where this might come from?

stevew817 commented 6 years ago

Okay, so the SetResourceValueAsync call ends up here: https://github.com/ARMmbed/mbed-cloud-sdk-dotnet/blame/7c3822bed9eb332306a31a86e9b8d11df2163d95/MbedCloudSDK/Backends/Mds/Api/ResourcesApi.cs#L1043

This line is pointless and faulty for the C# .NET version of the mbed cloud SDK. The function has an input type of 'string' for resourceValue, which means it will never be typed as a byte array. Which also means every resource value will be passed through a serializer, and if you pass a string through the serializer, the serializer will enclose it with double quotes. I think the meaning was to 'stringify' any non-string object, but then it needs to be possible to pass in any Object, and not just a String.

Please fix @alexl0gan

alexl0gan commented 6 years ago

@stevew817 The serialisation of the string is an issue with the Swagger Codegen templates and a fix is being looked at. All files in the /Backends folder are autogenerated using generic templates which is why the line you linked appears pointless for this scenario, but will be used in other parts of the SDK.

We are aware that only being able to set a resource value to a string is a limitation and have plans to address it as part of a larger effort to support more LWM2M features.

stevew817 commented 6 years ago

Hi @alexl0gan Thanks for the explanation. My issue is not so much in that you can only set a string through the SDK (stringifying numbers is easy enough), the issue is that the SDK will add double quotes to the passed string, which will show up on the device side. Ergo, what I push in on one side, doesn't come out the same on the other end. Hope for that fix to come soon.

alexl0gan commented 6 years ago

I thought I addressed the double quotes issue in my first comment. I am aware of this and have updated the templates so the fix will come with the next release.

stevew817 commented 6 years ago

Thanks! 👍

stevew817 commented 6 years ago

@alexl0gan I can't see a fix in the release you just made... Was this the release the fix was supposed to be in?

alexl0gan commented 6 years ago

Is this issue still happening in the new version?

https://github.com/ARMmbed/mbed-cloud-sdk-dotnet/blob/master/MbedCloudSDK/Backends/Mds/Client/ApiClient.cs#L379

This is a bit of a hack but it stops the double quotes.

The way the swagger codegen template is written is not ideal and I would have rather spent time to fix it properly but the team has other priorities at the moment and our next block of work will involve re-writing the templates any way so will keep it in mind for then.

alexl0gan commented 6 years ago

No reply so closing