diff --git a/common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/LwM2MTransportHandler.java b/common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/LwM2MTransportHandler.java index 1e84af7d48..14d06eb7e6 100644 --- a/common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/LwM2MTransportHandler.java +++ b/common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/LwM2MTransportHandler.java @@ -99,11 +99,13 @@ public class LwM2MTransportHandler { /** * Replaces the Object Instance or the Resource(s) with the new value provided in the “Write” operation. (see * section 5.3.3 of the LW M2M spec). + * if all resources are to be replaced */ public static final String POST_TYPE_OPER_WRITE_REPLACE = "replace"; /** * Adds or updates Resources provided in the new value and leaves other existing Resources unchanged. (see section * 5.3.3 of the LW M2M spec). + * if this is a partial update request */ public static final String PUT_TYPE_OPER_WRITE_UPDATE = "update"; public static final String PUT_TYPE_OPER_WRITE_ATTRIBUTES = "wright-attributes"; @@ -152,34 +154,6 @@ public class LwM2MTransportHandler { return coapConfig; } -// public static String getValueTypeToString (Object value, ResourceModel.Type type, int val) { -// try{ -// switch (type) { -// case STRING: // String -// case OBJLNK: // ObjectLink -// return value.toString(); -// case INTEGER: // Long -// return Long.toString((long) value); -// case BOOLEAN: // Boolean -// return Boolean.toString((Boolean) value); -// case FLOAT: // Double -// return Double.toString((Double) value); -// case TIME: // Date -// return Long.toString(((Date) value).getTime()); -//// String DATE_FORMAT = "MMM d, yyyy HH:mm a"; -//// DateFormat formatter = new SimpleDateFormat(DATE_FORMAT); -//// return formatter.format(new Date(Integer.toUnsignedLong((Integer) value))); -// case OPAQUE: // byte[] value, base64 -// return Hex.encodeHexString((byte[])value); -// default: -// return null; -// } -// } catch (Exception e) { -// log.error(e.getStackTrace().toString()); -// return null; -// } -// } - public static boolean equalsResourceValue(Object valueOld, Object valueNew, ResourceModel.Type type, LwM2mPath resourcePath) throws CodecException { switch (type) { case BOOLEAN: diff --git a/common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/LwM2MTransportRequest.java b/common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/LwM2MTransportRequest.java index f0b96d0225..e34cfdd34e 100644 --- a/common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/LwM2MTransportRequest.java +++ b/common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/LwM2MTransportRequest.java @@ -20,6 +20,7 @@ import org.eclipse.californium.core.coap.Response; import org.eclipse.leshan.core.attributes.Attribute; import org.eclipse.leshan.core.attributes.AttributeSet; import org.eclipse.leshan.core.model.ResourceModel; +import org.eclipse.leshan.core.node.LwM2mNode; import org.eclipse.leshan.core.node.LwM2mPath; import org.eclipse.leshan.core.node.LwM2mSingleResource; import org.eclipse.leshan.core.node.ObjectLink; @@ -146,7 +147,6 @@ public class LwM2MTransportRequest { break; case POST_TYPE_OPER_EXECUTE: if (params != null && resource != null && !resource.multiple) { -// request = new ExecuteRequest(target, LwM2MTransportHandler.getValueTypeToString(params, resType)); request = new ExecuteRequest(target, (String) this.converter.convertValue(params, resource.type, ResourceModel.Type.STRING, resultIds)); } else { request = new ExecuteRequest(target); @@ -168,7 +168,8 @@ public class LwM2MTransportRequest { if (resultIds.getResourceId() >= 0) { ResourceModel resourceModel = lwServer.getModelProvider().getObjectModel(registration).getObjectModel(resultIds.getObjectId()).resources.get(resultIds.getResourceId()); ResourceModel.Type typeRes = resourceModel.type; -// request = getWriteRequestResource(resultIds.getObjectId(), resultIds.getInstanceId(), resultIds.getResourceId(), params, typeRes); + LwM2mNode node = LwM2mSingleResource.newStringResource(resultIds.getResourceId(), (String) this.converter.convertValue(params, resource.type, ResourceModel.Type.STRING, resultIds)); + request = new WriteRequest(WriteRequest.Mode.UPDATE, contentFormat, target, node); } break; case PUT_TYPE_OPER_WRITE_ATTRIBUTES: diff --git a/common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/LwM2MTransportService.java b/common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/LwM2MTransportService.java index 5e4d4198f0..9c953f4069 100644 --- a/common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/LwM2MTransportService.java +++ b/common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/LwM2MTransportService.java @@ -515,7 +515,6 @@ public class LwM2MTransportService { private void getParametersFromProfile(JsonObject attributes, JsonObject telemetry, Registration registration, Set path) { AttrTelemetryObserveValue attrTelemetryObserveValue = lwM2mInMemorySecurityStore.getProfiles().get(lwM2mInMemorySecurityStore.getSessions().get(registration.getId()).getProfileUuid()); attrTelemetryObserveValue.getPostAttributeProfile().forEach(p -> { -// ResultIds pathIds = new ResultIds(p.getAsString().toString()); LwM2mPath pathIds = new LwM2mPath(p.getAsString().toString()); if (pathIds.isResource()) { if (path == null || path.contains(p.getAsString())) { @@ -524,7 +523,6 @@ public class LwM2MTransportService { } }); attrTelemetryObserveValue.getPostTelemetryProfile().forEach(p -> { -// ResultIds pathIds = new ResultIds(p.getAsString().toString()); LwM2mPath pathIds = new LwM2mPath(p.getAsString().toString()); if (pathIds.isResource()) { if (path == null || path.contains(p.getAsString())) { @@ -545,10 +543,8 @@ public class LwM2MTransportService { if (resName != null && !resName.isEmpty()) { String resValue = null; try { -// resValue = lwM2mInMemorySecurityStore.getSessions().get(registration.getId()).getResourceValueString(path); resValue = this.getResourceValueToString(lwM2MClient, path); if (resValue != null) { -// log.info("addParameters Path: [{}] ResValue : [{}] nameParam [{}]", path, lwM2mInMemorySecurityStore.getSessions().get(registration.getId()).getResourceValue(path), nameParam); parameters.addProperty(resName, resValue); } } catch (Exception e) { @@ -1061,10 +1057,7 @@ public class LwM2MTransportService { */ private void updateResourceValueObserve(LeshanServer lwServer, Registration registration, LwM2MClient lwM2MClient, Set targets, String typeOper) { targets.forEach(target -> { -// ResultIds pathIds = new ResultIds(target); LwM2mPath pathIds = new LwM2mPath(target); -// if (pathIds.isResource() && lwM2MClient.getModelObjects().get(pathIds.getObjectId()) -// .getInstances().get(pathIds.getObjectInstanceId()).getResource(pathIds.getResourceId()).getValue() != null) { if (pathIds.isResource()) { if (GET_TYPE_OPER_READ.equals(typeOper)) { lwM2MTransportRequest.sendAllRequest(lwServer, registration, target, typeOper,