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

Task: Apply properties on each thing in the group #1870

Open
Tracked by #1868
kbeaugrand opened this issue Mar 11, 2023 · 0 comments
Open
Tracked by #1868

Task: Apply properties on each thing in the group #1870

kbeaugrand opened this issue Mar 11, 2023 · 0 comments
Labels

Comments

@kbeaugrand
Copy link
Member

kbeaugrand commented Mar 11, 2023

US: #1868

Description

Once the dynamic group is created, we can iterate on devices in that group to apply the configuration.

For example:

using Amazon.IotData;
using Amazon.IotData.Model;
using Newtonsoft.Json.Linq;

// Define the device group details
string groupName = "my-group";
string desiredState = "{ \"power\": \"on\", \"brightness\": 80 }";

// Create a new instance of the AWS IoT Data client
var iotDataClient = new AmazonIotDataClient();

// Retrieve the list of devices in the group
var listThingsRequest = new ListThingsInThingGroupRequest
{
    ThingGroupName = groupName
};
var listThingsResponse = await iotClient.ListThingsInThingGroupAsync(listThingsRequest);

// Update the device shadows of the devices in the group
foreach (var thing in listThingsResponse.Things)
{
    var updateShadowRequest = new UpdateThingShadowRequest
    {
        ThingName = thing.ThingName,
        ShadowName = "default",
        Payload = JObject.Parse(desiredState)
    };
    var updateShadowResponse = await iotClient.UpdateThingShadowAsync(updateShadowRequest);

    // Synchronize the device shadows with the devices
    var getShadowRequest = new GetThingShadowRequest
    {
        ThingName = thing.ThingName,
        ShadowName = "default"
    };
    var getShadowResponse = await iotClient.GetThingShadowAsync(getShadowRequest);
    var reportedState = JObject.Parse(getShadowResponse.Payload.ToString())["state"]["reported"];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: 📝 Todo
Development

No branches or pull requests

3 participants