Search in sources :

Example 6 with BasicToDeviceActorSessionMsg

use of org.thingsboard.server.common.msg.session.BasicToDeviceActorSessionMsg in project thingsboard by thingsboard.

the class DeviceApiController method process.

private void process(HttpSessionCtx ctx, FromDeviceMsg request) {
    AdaptorToSessionActorMsg msg = new BasicAdaptorToSessionActorMsg(ctx, request);
    processor.process(new BasicToDeviceActorSessionMsg(ctx.getDevice(), msg));
}
Also used : BasicAdaptorToSessionActorMsg(org.thingsboard.server.common.msg.session.BasicAdaptorToSessionActorMsg) AdaptorToSessionActorMsg(org.thingsboard.server.common.msg.session.AdaptorToSessionActorMsg) BasicToDeviceActorSessionMsg(org.thingsboard.server.common.msg.session.BasicToDeviceActorSessionMsg) BasicAdaptorToSessionActorMsg(org.thingsboard.server.common.msg.session.BasicAdaptorToSessionActorMsg)

Example 7 with BasicToDeviceActorSessionMsg

use of org.thingsboard.server.common.msg.session.BasicToDeviceActorSessionMsg in project thingsboard by thingsboard.

the class GatewaySessionCtx method onDeviceTelemetry.

public void onDeviceTelemetry(MqttPublishMessage mqttMsg) throws AdaptorException {
    JsonElement json = validateJsonPayload(gatewaySessionId, mqttMsg.payload());
    int requestId = mqttMsg.variableHeader().messageId();
    if (json.isJsonObject()) {
        JsonObject jsonObj = json.getAsJsonObject();
        for (Map.Entry<String, JsonElement> deviceEntry : jsonObj.entrySet()) {
            String deviceName = checkDeviceConnected(deviceEntry.getKey());
            if (!deviceEntry.getValue().isJsonArray()) {
                throw new JsonSyntaxException(CAN_T_PARSE_VALUE + json);
            }
            BasicTelemetryUploadRequest request = new BasicTelemetryUploadRequest(requestId);
            JsonArray deviceData = deviceEntry.getValue().getAsJsonArray();
            for (JsonElement element : deviceData) {
                JsonConverter.parseWithTs(request, element.getAsJsonObject());
            }
            GatewayDeviceSessionCtx deviceSessionCtx = devices.get(deviceName);
            processor.process(new BasicToDeviceActorSessionMsg(deviceSessionCtx.getDevice(), new BasicAdaptorToSessionActorMsg(deviceSessionCtx, request)));
        }
    } else {
        throw new JsonSyntaxException(CAN_T_PARSE_VALUE + json);
    }
}
Also used : JsonArray(com.google.gson.JsonArray) JsonSyntaxException(com.google.gson.JsonSyntaxException) JsonElement(com.google.gson.JsonElement) BasicToDeviceActorSessionMsg(org.thingsboard.server.common.msg.session.BasicToDeviceActorSessionMsg) JsonObject(com.google.gson.JsonObject) BasicAdaptorToSessionActorMsg(org.thingsboard.server.common.msg.session.BasicAdaptorToSessionActorMsg)

Example 8 with BasicToDeviceActorSessionMsg

use of org.thingsboard.server.common.msg.session.BasicToDeviceActorSessionMsg in project thingsboard by thingsboard.

the class GatewaySessionCtx method onDeviceAttributesRequest.

public void onDeviceAttributesRequest(MqttPublishMessage msg) throws AdaptorException {
    JsonElement json = validateJsonPayload(gatewaySessionId, msg.payload());
    if (json.isJsonObject()) {
        JsonObject jsonObj = json.getAsJsonObject();
        int requestId = jsonObj.get("id").getAsInt();
        String deviceName = jsonObj.get(DEVICE_PROPERTY).getAsString();
        boolean clientScope = jsonObj.get("client").getAsBoolean();
        Set<String> keys;
        if (jsonObj.has("key")) {
            keys = Collections.singleton(jsonObj.get("key").getAsString());
        } else {
            JsonArray keysArray = jsonObj.get("keys").getAsJsonArray();
            keys = new HashSet<>();
            for (JsonElement keyObj : keysArray) {
                keys.add(keyObj.getAsString());
            }
        }
        BasicGetAttributesRequest request;
        if (clientScope) {
            request = new BasicGetAttributesRequest(requestId, keys, null);
        } else {
            request = new BasicGetAttributesRequest(requestId, null, keys);
        }
        GatewayDeviceSessionCtx deviceSessionCtx = devices.get(deviceName);
        processor.process(new BasicToDeviceActorSessionMsg(deviceSessionCtx.getDevice(), new BasicAdaptorToSessionActorMsg(deviceSessionCtx, request)));
        ack(msg);
    } else {
        throw new JsonSyntaxException(CAN_T_PARSE_VALUE + json);
    }
}
Also used : JsonObject(com.google.gson.JsonObject) BasicAdaptorToSessionActorMsg(org.thingsboard.server.common.msg.session.BasicAdaptorToSessionActorMsg) JsonArray(com.google.gson.JsonArray) JsonSyntaxException(com.google.gson.JsonSyntaxException) JsonElement(com.google.gson.JsonElement) BasicToDeviceActorSessionMsg(org.thingsboard.server.common.msg.session.BasicToDeviceActorSessionMsg)

Example 9 with BasicToDeviceActorSessionMsg

use of org.thingsboard.server.common.msg.session.BasicToDeviceActorSessionMsg in project thingsboard by thingsboard.

the class GatewaySessionCtx method onDeviceAttributes.

public void onDeviceAttributes(MqttPublishMessage mqttMsg) throws AdaptorException {
    JsonElement json = validateJsonPayload(gatewaySessionId, mqttMsg.payload());
    int requestId = mqttMsg.variableHeader().messageId();
    if (json.isJsonObject()) {
        JsonObject jsonObj = json.getAsJsonObject();
        for (Map.Entry<String, JsonElement> deviceEntry : jsonObj.entrySet()) {
            String deviceName = checkDeviceConnected(deviceEntry.getKey());
            if (!deviceEntry.getValue().isJsonObject()) {
                throw new JsonSyntaxException(CAN_T_PARSE_VALUE + json);
            }
            long ts = System.currentTimeMillis();
            BasicUpdateAttributesRequest request = new BasicUpdateAttributesRequest(requestId);
            JsonObject deviceData = deviceEntry.getValue().getAsJsonObject();
            request.add(JsonConverter.parseValues(deviceData).stream().map(kv -> new BaseAttributeKvEntry(kv, ts)).collect(Collectors.toList()));
            GatewayDeviceSessionCtx deviceSessionCtx = devices.get(deviceName);
            processor.process(new BasicToDeviceActorSessionMsg(deviceSessionCtx.getDevice(), new BasicAdaptorToSessionActorMsg(deviceSessionCtx, request)));
        }
    } else {
        throw new JsonSyntaxException(CAN_T_PARSE_VALUE + json);
    }
}
Also used : JsonObject(com.google.gson.JsonObject) BasicAdaptorToSessionActorMsg(org.thingsboard.server.common.msg.session.BasicAdaptorToSessionActorMsg) JsonSyntaxException(com.google.gson.JsonSyntaxException) JsonElement(com.google.gson.JsonElement) BasicToDeviceActorSessionMsg(org.thingsboard.server.common.msg.session.BasicToDeviceActorSessionMsg) BaseAttributeKvEntry(org.thingsboard.server.common.data.kv.BaseAttributeKvEntry)

Aggregations

BasicToDeviceActorSessionMsg (org.thingsboard.server.common.msg.session.BasicToDeviceActorSessionMsg)9 BasicAdaptorToSessionActorMsg (org.thingsboard.server.common.msg.session.BasicAdaptorToSessionActorMsg)6 JsonElement (com.google.gson.JsonElement)4 JsonObject (com.google.gson.JsonObject)4 JsonSyntaxException (com.google.gson.JsonSyntaxException)4 AdaptorToSessionActorMsg (org.thingsboard.server.common.msg.session.AdaptorToSessionActorMsg)4 AdaptorException (org.thingsboard.server.common.transport.adaptor.AdaptorException)3 JsonArray (com.google.gson.JsonArray)2 MqttQoS (io.netty.handler.codec.mqtt.MqttQoS)1 ArrayList (java.util.ArrayList)1 Device (org.thingsboard.server.common.data.Device)1 BaseAttributeKvEntry (org.thingsboard.server.common.data.kv.BaseAttributeKvEntry)1 EntityRelation (org.thingsboard.server.common.data.relation.EntityRelation)1