List of usage examples for com.amazonaws.services.iotdata.model UpdateThingShadowRequest UpdateThingShadowRequest
UpdateThingShadowRequest
From source file:com.erudika.para.iot.AWSIoTService.java
License:Apache License
@Override public void updateThing(Thing thing) { if (thing == null || StringUtils.isBlank(thing.getId())) { return;/*from ww w. j a v a 2 s .c o m*/ } ByteArrayOutputStream baos = new ByteArrayOutputStream(); String id = cloudIDForThing(thing); try { Object data = Collections.singletonMap("state", Collections.singletonMap("desired", thing.getDeviceState())); ParaObjectUtils.getJsonWriterNoIdent().writeValue(baos, data); getDataClient().updateThingShadow(new UpdateThingShadowRequest().withThingName(id) .withPayload(ByteBuffer.wrap(baos.toByteArray()))); } catch (Exception ex) { logger.warn("Failed to connect to IoT device {}: {}", id, ex.getMessage()); } finally { IOUtils.closeQuietly(baos); } }
From source file:io.klerch.alexa.state.handler.AWSIotStateHandler.java
License:Open Source License
private void publishState(final String thingName, final String json) throws AlexaStateException { final ByteBuffer buffer; try {//from w w w. j av a 2 s . co m buffer = ByteBuffer.wrap(json.getBytes("UTF-8")); } catch (UnsupportedEncodingException e) { final String error = format("Could not prepare JSON for model state publication to thing shadow '%1$s'", thingName); log.error(error, e); throw AlexaStateException.create(error).withCause(e).withHandler(this).build(); } final UpdateThingShadowRequest iotRequest = new UpdateThingShadowRequest().withThingName(thingName) .withPayload(buffer); awsDataClient.updateThingShadow(iotRequest); }