Created
September 8, 2016 02:21
-
-
Save steveperkins/e6ffe08180d2d7c7366e532ec5279551 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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