use of org.thingsboard.server.transport.lwm2m.server.rpc.composite.RpcWriteCompositeRequest in project thingsboard by thingsboard.
the class DefaultLwM2mDownlinkMsgHandler method sendWriteCompositeRequest.
@Override
public void sendWriteCompositeRequest(LwM2mClient client, RpcWriteCompositeRequest rpcWriteCompositeRequest, DownlinkRequestCallback<WriteCompositeRequest, WriteCompositeResponse> callback, ContentFormat contentFormatComposite) {
try {
WriteCompositeRequest downlink = new WriteCompositeRequest(contentFormatComposite, rpcWriteCompositeRequest.getNodes());
// TODO: replace config.getTimeout();
sendWriteCompositeRequest(client, downlink, this.config.getTimeout(), callback);
} catch (InvalidRequestException e) {
callback.onValidationError(rpcWriteCompositeRequest.toString(), e.getMessage());
} catch (Exception e) {
callback.onError(toString(rpcWriteCompositeRequest), e);
}
}
use of org.thingsboard.server.transport.lwm2m.server.rpc.composite.RpcWriteCompositeRequest in project thingsboard by thingsboard.
the class DefaultLwM2MRpcRequestHandler method sendWriteCompositeRequest.
/**
* WriteComposite {"nodes":{"/3/0/14":"+04", "/1/0/2":100, "/5/0/1":"coap://localhost:5685"}}
* {"result":"CHANGED"}
* Map<String, Object> nodes = new HashMap<>();
* nodes.put("/3/0/14", "+02");
* nodes.put("/1/0/2", 100);
* nodes.put("/5/0/1", "coap://localhost:5685");
*/
private void sendWriteCompositeRequest(LwM2mClient client, TransportProtos.ToDeviceRpcRequestMsg requestMsg, ContentFormat contentFormatComposite) {
RpcWriteCompositeRequest rpcWriteCompositeRequest = JacksonUtil.fromString(requestMsg.getParams(), RpcWriteCompositeRequest.class);
Map<String, Object> validNodes = validateNodes(client, rpcWriteCompositeRequest.getNodes());
if (validNodes.size() > 0) {
rpcWriteCompositeRequest.setNodes(validNodes);
var mainCallback = new TbLwM2MWriteResponseCompositeCallback(uplinkHandler, logService, client, null);
var rpcCallback = new RpcEmptyResponseCallback<>(transportService, client, requestMsg, mainCallback);
downlinkHandler.sendWriteCompositeRequest(client, rpcWriteCompositeRequest, rpcCallback, contentFormatComposite);
} else {
throw new IllegalArgumentException(String.format("nodes: %s is not validate value", rpcWriteCompositeRequest.getNodes().toString()));
}
}
Aggregations