Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
AWSIotData iotDataClient = AWSIotDataClientBuilder
.standard()
.withRegion(Regions.US_WEST_2)
.withCredentials(new AWSStaticCredentialsProvider(new BasicAWSCredentials(CLIENT_TOKEN, CLIENT_SECRET))).build();
String thingName = "plant-manager";
GetThingShadowResult getThingShadowResult = iotDataClient.getThingShadow(new GetThingShadowRequest().withThingName(thingName));
String state = new String( getThingShadowResult.getPayload().array(), StandardCharsets.UTF_8);
// state is now a JSON string representing the plant-manager Thing Shadow's state
/* {
"desired":{
"watering":true,
"notifyOnComplete":"+14144768200"
},
"reported":{
"watering":false,
"notifyOnComplete":"+14144768200"
},
"delta":{
"watering":true
}
}
*/
// To update state, send an UpdateThingShadowRequest containing JSON with your requisite "desired" properties and values
String desiredJson = "{ "desired": { "watering": true } }";
UpdateThingShadowRequest shadowRequest = new UpdateThingShadowRequest()
.withThingName(thingName)
.withPayload(ByteBuffer.wrap(desiredJson.getBytes()));
UpdateThingShadowResult result = iotDataClient.updateThingShadow(shadowRequest);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment