Search in sources :

Example 1 with ResultsAddKeyValueProto

use of org.thingsboard.server.transport.lwm2m.server.client.ResultsAddKeyValueProto in project thingsboard by thingsboard.

the class DefaultLwM2mUplinkMsgHandler method getParametersFromProfile.

/**
 * //     * @param attributes   - new JsonObject
 * //     * @param telemetry    - new JsonObject
 *
 * @param registration - Registration LwM2M Client
 * @param path         -
 */
private ResultsAddKeyValueProto getParametersFromProfile(Registration registration, Set<String> path) {
    if (path != null && path.size() > 0) {
        ResultsAddKeyValueProto results = new ResultsAddKeyValueProto();
        var profile = clientContext.getProfile(registration);
        List<TransportProtos.KeyValueProto> resultAttributes = new ArrayList<>();
        profile.getObserveAttr().getAttribute().forEach(pathIdVer -> {
            if (path.contains(pathIdVer)) {
                TransportProtos.KeyValueProto kvAttr = this.getKvToThingsBoard(pathIdVer, registration);
                if (kvAttr != null) {
                    resultAttributes.add(kvAttr);
                }
            }
        });
        List<TransportProtos.KeyValueProto> resultTelemetries = new ArrayList<>();
        profile.getObserveAttr().getTelemetry().forEach(pathIdVer -> {
            if (path.contains(pathIdVer)) {
                TransportProtos.KeyValueProto kvAttr = this.getKvToThingsBoard(pathIdVer, registration);
                if (kvAttr != null) {
                    resultTelemetries.add(kvAttr);
                }
            }
        });
        if (resultAttributes.size() > 0) {
            results.setResultAttributes(resultAttributes);
        }
        if (resultTelemetries.size() > 0) {
            results.setResultTelemetries(resultTelemetries);
        }
        return results;
    }
    return null;
}
Also used : ResultsAddKeyValueProto(org.thingsboard.server.transport.lwm2m.server.client.ResultsAddKeyValueProto) ArrayList(java.util.ArrayList) TransportProtos(org.thingsboard.server.gen.transport.TransportProtos) ResultsAddKeyValueProto(org.thingsboard.server.transport.lwm2m.server.client.ResultsAddKeyValueProto)

Example 2 with ResultsAddKeyValueProto

use of org.thingsboard.server.transport.lwm2m.server.client.ResultsAddKeyValueProto in project thingsboard by thingsboard.

the class DefaultLwM2mUplinkMsgHandler method updateAttrTelemetry.

/**
 * send Attribute and Telemetry to Thingsboard
 * #1 - get AttrName/TelemetryName with value from LwM2MClient:
 * -- resourceId == path from LwM2MClientProfile.postAttributeProfile/postTelemetryProfile/postObserveProfile
 * -- AttrName/TelemetryName == resourceName from ModelObject.objectModel, value from ModelObject.instance.resource(resourceId)
 * #2 - set Attribute/Telemetry
 *
 * @param registration - Registration LwM2M Client
 */
private void updateAttrTelemetry(Registration registration, Set<String> paths) {
    try {
        ResultsAddKeyValueProto results = this.getParametersFromProfile(registration, paths);
        SessionInfoProto sessionInfo = this.getSessionInfoOrCloseSession(registration);
        if (results != null && sessionInfo != null) {
            if (results.getResultAttributes().size() > 0) {
                this.helper.sendParametersOnThingsboardAttribute(results.getResultAttributes(), sessionInfo);
            }
            if (results.getResultTelemetries().size() > 0) {
                this.helper.sendParametersOnThingsboardTelemetry(results.getResultTelemetries(), sessionInfo);
            }
        }
    } catch (Exception e) {
        log.error("UpdateAttrTelemetry", e);
    }
}
Also used : SessionInfoProto(org.thingsboard.server.gen.transport.TransportProtos.SessionInfoProto) ResultsAddKeyValueProto(org.thingsboard.server.transport.lwm2m.server.client.ResultsAddKeyValueProto) LwM2MClientStateException(org.thingsboard.server.transport.lwm2m.server.client.LwM2MClientStateException)

Aggregations

ResultsAddKeyValueProto (org.thingsboard.server.transport.lwm2m.server.client.ResultsAddKeyValueProto)2 ArrayList (java.util.ArrayList)1 TransportProtos (org.thingsboard.server.gen.transport.TransportProtos)1 SessionInfoProto (org.thingsboard.server.gen.transport.TransportProtos.SessionInfoProto)1 LwM2MClientStateException (org.thingsboard.server.transport.lwm2m.server.client.LwM2MClientStateException)1