Azure / azure-iot-sdk-csharp

A C# SDK for connecting devices to Microsoft Azure IoT services
Other
466 stars 493 forks source link

Callback registered with SetDesiredPropertyUpdateCallbackAsync not called unless desired properties set while active connection #450

Closed v-tbert closed 5 years ago

v-tbert commented 6 years ago

If you use RegistryManager to set a desired property on a twin, create a DeviceClient (AMQP or MQTT), register a callback with DeviceClient SetDesiredPropertyUpdateCallbackAsync, and OpenAsync() the client your handler registered does not get called. However, if you set the desired property after OpenAsync, the callback is called. This would then seem to necessitate that every time a client connects it needs to make a second call to GetTwinAsync to get any pre-existing desired changes.

General flow:

await registryManager.UpdateTwinAsync(twin.DeviceId, twin, twin.ETag);
await deviceClient.SetDesiredPropertyUpdateCallbackAsync(OnDevicePropertyUpdateRequestedAsync, deviceClient);
await deviceClient.OpenAsync();

Packages: `

`

zolvarga commented 6 years ago

@v-tbert

Thanks for reporting the issue we will take a look at it.

Best Regards, Zoltan

msivers commented 5 years ago

Is there a response to this open issue - experiencing the same scenario and is not ideal to have to implement multiple ways to ensure desired property updates are managed depending on connectivity state... This issue was labeled as investigation-required over a year ago. Has this scenario been looked at?

prmathur-microsoft commented 5 years ago

Sorry about the delay in addressing this. Could you please provide details such as below for us to start investigation.

OS, version, SKU and CPU architecture used: Application's .NET Target Framework : Device: SDK version used:

prmathur-microsoft commented 5 years ago

As I have not received more details on this issue I'm closing it for now. Feel free to reopen this issue if you have further information.

az-iot-builder-01 commented 5 years ago

@v-tbert, @msivers, @prmathur-microsoft, thank you for your contribution to our open-sourced project! Please help us improve by filling out this 2-minute customer satisfaction survey

v-tbert commented 4 years ago

I'm working on a DeviceClient again and I hit this issue again. It seems like a intentional design decision that I think should be changed. It appears that existing desired properties don't get sent to the deviceclient when it first connects. In my opinion, an overload of SetDesiredPropertyUpdateCallbackAsync should be added that specifies that you want to receive any existing desired properties upon connection. That would be more efficient than the client always getting the device twin when it connects just to see if it has desired properties.

v-tbert commented 4 years ago

How can I re-open this as a feature request?