Search in sources :

Example 1 with TbLwM2MReadCallback

use of org.thingsboard.server.transport.lwm2m.server.downlink.TbLwM2MReadCallback in project thingsboard by thingsboard.

the class DefaultLwM2MRpcRequestHandler method sendReadRequest.

private void sendReadRequest(LwM2mClient client, TransportProtos.ToDeviceRpcRequestMsg requestMsg, String versionedId) {
    TbLwM2MReadRequest request = TbLwM2MReadRequest.builder().versionedId(versionedId).timeout(clientContext.getRequestTimeout(client)).build();
    var mainCallback = new TbLwM2MReadCallback(uplinkHandler, logService, client, versionedId);
    var rpcCallback = new RpcReadResponseCallback<>(transportService, client, requestMsg, mainCallback);
    downlinkHandler.sendReadRequest(client, request, rpcCallback);
}
Also used : TbLwM2MReadCallback(org.thingsboard.server.transport.lwm2m.server.downlink.TbLwM2MReadCallback) TbLwM2MReadRequest(org.thingsboard.server.transport.lwm2m.server.downlink.TbLwM2MReadRequest)

Example 2 with TbLwM2MReadCallback

use of org.thingsboard.server.transport.lwm2m.server.downlink.TbLwM2MReadCallback in project thingsboard by thingsboard.

the class LwM2MModelConfigServiceImpl method doSend.

private void doSend(LwM2mClient lwM2mClient, LwM2MModelConfig modelConfig) {
    log.trace("Send LwM2M Model updates: [{}]", modelConfig);
    String endpoint = lwM2mClient.getEndpoint();
    Map<String, ObjectAttributes> attrToAdd = modelConfig.getAttributesToAdd();
    attrToAdd.forEach((id, attributes) -> {
        TbLwM2MWriteAttributesRequest request = TbLwM2MWriteAttributesRequest.builder().versionedId(id).attributes(attributes).timeout(clientContext.getRequestTimeout(lwM2mClient)).build();
        downlinkMsgHandler.sendWriteAttributesRequest(lwM2mClient, request, createDownlinkProxyCallback(() -> {
            attrToAdd.remove(id);
            if (modelConfig.isEmpty()) {
                modelStore.remove(endpoint);
            }
        }, new TbLwM2MWriteAttributesCallback(logService, lwM2mClient, id)));
    });
    Set<String> attrToRemove = modelConfig.getAttributesToRemove();
    attrToRemove.forEach((id) -> {
        TbLwM2MWriteAttributesRequest request = TbLwM2MWriteAttributesRequest.builder().versionedId(id).attributes(new ObjectAttributes()).timeout(clientContext.getRequestTimeout(lwM2mClient)).build();
        downlinkMsgHandler.sendWriteAttributesRequest(lwM2mClient, request, createDownlinkProxyCallback(() -> {
            attrToRemove.remove(id);
            if (modelConfig.isEmpty()) {
                modelStore.remove(endpoint);
            }
        }, new TbLwM2MWriteAttributesCallback(logService, lwM2mClient, id)));
    });
    Set<String> toRead = modelConfig.getToRead();
    toRead.forEach(id -> {
        TbLwM2MReadRequest request = TbLwM2MReadRequest.builder().versionedId(id).timeout(clientContext.getRequestTimeout(lwM2mClient)).build();
        downlinkMsgHandler.sendReadRequest(lwM2mClient, request, createDownlinkProxyCallback(() -> {
            toRead.remove(id);
            if (modelConfig.isEmpty()) {
                modelStore.remove(endpoint);
            }
        }, new TbLwM2MReadCallback(uplinkMsgHandler, logService, lwM2mClient, id)));
    });
    Set<String> toObserve = modelConfig.getToObserve();
    toObserve.forEach(id -> {
        TbLwM2MObserveRequest request = TbLwM2MObserveRequest.builder().versionedId(id).timeout(clientContext.getRequestTimeout(lwM2mClient)).build();
        downlinkMsgHandler.sendObserveRequest(lwM2mClient, request, createDownlinkProxyCallback(() -> {
            toObserve.remove(id);
            if (modelConfig.isEmpty()) {
                modelStore.remove(endpoint);
            }
        }, new TbLwM2MObserveCallback(uplinkMsgHandler, logService, lwM2mClient, id)));
    });
    Set<String> toCancelObserve = modelConfig.getToCancelObserve();
    toCancelObserve.forEach(id -> {
        TbLwM2MCancelObserveRequest request = TbLwM2MCancelObserveRequest.builder().versionedId(id).timeout(clientContext.getRequestTimeout(lwM2mClient)).build();
        downlinkMsgHandler.sendCancelObserveRequest(lwM2mClient, request, createDownlinkProxyCallback(() -> {
            toCancelObserve.remove(id);
            if (modelConfig.isEmpty()) {
                modelStore.remove(endpoint);
            }
        }, new TbLwM2MCancelObserveCallback(logService, lwM2mClient, id)));
    });
}
Also used : TbLwM2MCancelObserveCallback(org.thingsboard.server.transport.lwm2m.server.downlink.TbLwM2MCancelObserveCallback) TbLwM2MObserveCallback(org.thingsboard.server.transport.lwm2m.server.downlink.TbLwM2MObserveCallback) TbLwM2MCancelObserveRequest(org.thingsboard.server.transport.lwm2m.server.downlink.TbLwM2MCancelObserveRequest) TbLwM2MWriteAttributesRequest(org.thingsboard.server.transport.lwm2m.server.downlink.TbLwM2MWriteAttributesRequest) TbLwM2MReadCallback(org.thingsboard.server.transport.lwm2m.server.downlink.TbLwM2MReadCallback) TbLwM2MReadRequest(org.thingsboard.server.transport.lwm2m.server.downlink.TbLwM2MReadRequest) ObjectAttributes(org.thingsboard.server.common.data.device.profile.lwm2m.ObjectAttributes) TbLwM2MWriteAttributesCallback(org.thingsboard.server.transport.lwm2m.server.downlink.TbLwM2MWriteAttributesCallback) TbLwM2MObserveRequest(org.thingsboard.server.transport.lwm2m.server.downlink.TbLwM2MObserveRequest)

Example 3 with TbLwM2MReadCallback

use of org.thingsboard.server.transport.lwm2m.server.downlink.TbLwM2MReadCallback in project thingsboard by thingsboard.

the class DefaultLwM2mUplinkMsgHandler method sendReadRequests.

private void sendReadRequests(LwM2mClient lwM2MClient, Lwm2mDeviceProfileTransportConfiguration profile, Set<String> supportedObjects) {
    try {
        Set<String> targetIds = new HashSet<>(profile.getObserveAttr().getAttribute());
        targetIds.addAll(profile.getObserveAttr().getTelemetry());
        targetIds = diffSets(profile.getObserveAttr().getObserve(), targetIds);
        targetIds = targetIds.stream().filter(target -> isSupportedTargetId(supportedObjects, target)).collect(Collectors.toSet());
        CountDownLatch latch = new CountDownLatch(targetIds.size());
        targetIds.forEach(versionedId -> sendReadRequest(lwM2MClient, versionedId, new TbLwM2MLatchCallback<>(latch, new TbLwM2MReadCallback(this, logService, lwM2MClient, versionedId))));
        latch.await();
    } catch (InterruptedException e) {
        log.error("[{}] Failed to await Read requests!", lwM2MClient.getEndpoint(), e);
    } catch (Exception e) {
        log.error("[{}] Failed to process read requests!", lwM2MClient.getEndpoint(), e);
        logService.log(lwM2MClient, "Failed to process read requests. Possible profile misconfiguration.");
    }
}
Also used : TbLwM2MLatchCallback(org.thingsboard.server.transport.lwm2m.server.downlink.TbLwM2MLatchCallback) TbLwM2MReadCallback(org.thingsboard.server.transport.lwm2m.server.downlink.TbLwM2MReadCallback) LwM2MTransportUtil.convertOtaUpdateValueToString(org.thingsboard.server.transport.lwm2m.utils.LwM2MTransportUtil.convertOtaUpdateValueToString) CountDownLatch(java.util.concurrent.CountDownLatch) LwM2MClientStateException(org.thingsboard.server.transport.lwm2m.server.client.LwM2MClientStateException) HashSet(java.util.HashSet)

Aggregations

TbLwM2MReadCallback (org.thingsboard.server.transport.lwm2m.server.downlink.TbLwM2MReadCallback)3 TbLwM2MReadRequest (org.thingsboard.server.transport.lwm2m.server.downlink.TbLwM2MReadRequest)2 HashSet (java.util.HashSet)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ObjectAttributes (org.thingsboard.server.common.data.device.profile.lwm2m.ObjectAttributes)1 LwM2MClientStateException (org.thingsboard.server.transport.lwm2m.server.client.LwM2MClientStateException)1 TbLwM2MCancelObserveCallback (org.thingsboard.server.transport.lwm2m.server.downlink.TbLwM2MCancelObserveCallback)1 TbLwM2MCancelObserveRequest (org.thingsboard.server.transport.lwm2m.server.downlink.TbLwM2MCancelObserveRequest)1 TbLwM2MLatchCallback (org.thingsboard.server.transport.lwm2m.server.downlink.TbLwM2MLatchCallback)1 TbLwM2MObserveCallback (org.thingsboard.server.transport.lwm2m.server.downlink.TbLwM2MObserveCallback)1 TbLwM2MObserveRequest (org.thingsboard.server.transport.lwm2m.server.downlink.TbLwM2MObserveRequest)1 TbLwM2MWriteAttributesCallback (org.thingsboard.server.transport.lwm2m.server.downlink.TbLwM2MWriteAttributesCallback)1 TbLwM2MWriteAttributesRequest (org.thingsboard.server.transport.lwm2m.server.downlink.TbLwM2MWriteAttributesRequest)1 LwM2MTransportUtil.convertOtaUpdateValueToString (org.thingsboard.server.transport.lwm2m.utils.LwM2MTransportUtil.convertOtaUpdateValueToString)1