Search in sources :

Example 1 with RpcWriteCompositeRequest

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);
    }
}
Also used : RpcWriteCompositeRequest(org.thingsboard.server.transport.lwm2m.server.rpc.composite.RpcWriteCompositeRequest) WriteCompositeRequest(org.eclipse.leshan.core.request.WriteCompositeRequest) InvalidRequestException(org.eclipse.leshan.core.request.exception.InvalidRequestException) ClientSleepingException(org.eclipse.leshan.core.request.exception.ClientSleepingException) TimeoutException(org.eclipse.leshan.core.request.exception.TimeoutException) InvalidRequestException(org.eclipse.leshan.core.request.exception.InvalidRequestException)

Example 2 with RpcWriteCompositeRequest

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()));
    }
}
Also used : TbLwM2MWriteResponseCompositeCallback(org.thingsboard.server.transport.lwm2m.server.downlink.composite.TbLwM2MWriteResponseCompositeCallback) RpcWriteCompositeRequest(org.thingsboard.server.transport.lwm2m.server.rpc.composite.RpcWriteCompositeRequest)

Aggregations

RpcWriteCompositeRequest (org.thingsboard.server.transport.lwm2m.server.rpc.composite.RpcWriteCompositeRequest)2 WriteCompositeRequest (org.eclipse.leshan.core.request.WriteCompositeRequest)1 ClientSleepingException (org.eclipse.leshan.core.request.exception.ClientSleepingException)1 InvalidRequestException (org.eclipse.leshan.core.request.exception.InvalidRequestException)1 TimeoutException (org.eclipse.leshan.core.request.exception.TimeoutException)1 TbLwM2MWriteResponseCompositeCallback (org.thingsboard.server.transport.lwm2m.server.downlink.composite.TbLwM2MWriteResponseCompositeCallback)1