Reputation: 43
I'm trying to read the twin of my device from the registry manager. This is my code:
DeviceClient client =
DeviceClient.CreateFromConnectionString(DeviceConnectionString,
TransportType.Mqtt);
Twin deviceTwin = await deviceClient.GetTwinAsync();
Console.WriteLine(deviceTwin.ToJson());
However, the Json I'm getting is the following.
{"deviceId":null,"etag":null,"version":null,"properties":{"desired":{"$version":1},"reported":{"$version":1}}}
Upvotes: 3
Views: 835
Reputation: 21
This is not an issue and/or workaround. Documentation states:
Retrieve the device twin properties for the current device. For the complete device twin object, use Microsoft.Azure.Devices.RegistryManager.GetTwinAsync(string deviceId).
Upvotes: 1
Reputation: 9700
I reproduced your issue.
For this problem, you can open an issue on azure-iot-sdk-csharp repository.
For workarounds, you can either use REST API like this:
Or use Azure IoT Service SDK like this:
using Microsoft.Azure.Devices;
...
var client = RegistryManager.CreateFromConnectionString(IoTHubConnectionString);
var twinData = await client.GetTwinAsync(deviceId);
Console.WriteLine(twinData.ToJson());
Upvotes: 3