
上QQ阅读APP看书,第一时间看更新
How to do it...
Let's follow the following steps to use the device twin operation:
- Store the device metadata:
var patch = new
{
properties = new
{
desired = new
{
deviceConfig = new
{
configId = Guid.NewGuid().ToString(),
DeviceOwner = "yatish",
latitude = "17.5122560",
longitude = "70.7760470"
}
},
reported = new
{
deviceConfig = new
{
configId = Guid.NewGuid().ToString(),
DeviceOwner = "yatish",
latitude = "17.5122560",
longitude = "70.7760470"
}
}
},
tags = new
{
location = new
{
region = "US",
plant = "Redmond43"
}
}
};
await registryManager.UpdateTwinAsync(deviceTwin.DeviceId, JsonConvert.SerializeObject(patch), deviceTwin.ETag);
- Query the device metadata:
var query = registryManager.CreateQuery("SELECT * FROM devices WHERE deviceId = '" + deviceTwin.DeviceId + "'");
- Report the current state of the device:
var results = await query.GetNextAsTwinAsync();