diff --git a/common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/LwM2MTransportServiceImpl.java b/common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/LwM2MTransportServiceImpl.java index 3255d24760..10df996b79 100644 --- a/common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/LwM2MTransportServiceImpl.java +++ b/common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/LwM2MTransportServiceImpl.java @@ -154,7 +154,7 @@ public class LwM2MTransportServiceImpl implements LwM2MTransportService { lwM2MClient.setLwM2MTransportServiceImpl(this); lwM2MClient.setSessionUuid(UUID.randomUUID()); this.sentLogsToThingsboard(LOG_LW2M_INFO + ": Client Registered", registration); -// this.setLwM2mFromClientValue(lwServer, registration, lwM2MClient); + this.setLwM2mFromClientValue(lwServer, registration, lwM2MClient); SessionInfoProto sessionInfo = this.getValidateSessionInfo(registration); if (sessionInfo != null) { lwM2MClient.setDeviceUuid(new UUID(sessionInfo.getDeviceIdMSB(), sessionInfo.getDeviceIdLSB())); diff --git a/common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/client/LwM2MClient.java b/common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/client/LwM2MClient.java index f20853299d..3c1a886454 100644 --- a/common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/client/LwM2MClient.java +++ b/common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/client/LwM2MClient.java @@ -93,7 +93,7 @@ public class LwM2MClient implements Cloneable { this.pendingRequests.remove(path); if (this.pendingRequests.size() == 0) { this.initValue(); -// this.lwM2MTransportServiceImpl.putDelayedUpdateResourcesThingsboard(this); + this.lwM2MTransportServiceImpl.putDelayedUpdateResourcesThingsboard(this); } } @@ -106,7 +106,7 @@ public class LwM2MClient implements Cloneable { ((LwM2mObjectInstance)((ReadResponse)resp).getContent()).getResources().forEach((k, v) -> { String rez = pathIds.toString() + "/" + k; if (((LwM2mObjectInstance) ((ReadResponse) resp).getContent()).getResource(k) instanceof LwM2mMultipleResource){ -// this.resources.put(rez, new ResourceValue(v.getInstances().values(), null, true)); + this.resources.put(rez, new ResourceValue(v.getValues(), null, true)); } else { this.resources.put(rez, new ResourceValue(null, v.getValue(), false)); diff --git a/ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-device-profile-transport-configuration.component.ts b/ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-device-profile-transport-configuration.component.ts index e9b6b17edc..6451bbb0b8 100644 --- a/ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-device-profile-transport-configuration.component.ts +++ b/ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-device-profile-transport-configuration.component.ts @@ -271,6 +271,7 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro const observeArray: Array = []; const attributeArray: Array = []; const telemetryArray: Array = []; + const keyNameNew = {}; const observeJson: ObjectLwM2M[] = JSON.parse(JSON.stringify(val)); const paths = new Set(); let pathObj; @@ -293,18 +294,22 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro const resourcesJson = instanceValue as ResourceLwM2M[]; if (resourcesJson.length > 0) { resourcesJson.forEach(res => { - for (const [resourceKey, idResource] of Object.entries(res)) { + for (const [resourceKey, value] of Object.entries(res)) { if (resourceKey === 'id') { - pathRes = `/${pathObj}/${pathInst}/${idResource}`; - } else if (resourceKey === 'observe' && idResource) { + pathRes = `/${pathObj}/${pathInst}/${value}`; + } else if (resourceKey === 'observe' && value) { observeArray.push(pathRes); - } else if (resourceKey === 'attribute' && idResource) { + } else if (resourceKey === 'attribute' && value) { attributeArray.push(pathRes); paths.add(pathRes); - } else if (resourceKey === 'telemetry' && idResource) { + } else if (resourceKey === 'telemetry' && value) { telemetryArray.push(pathRes); paths.add(pathRes); } + else if (resourceKey === this.keyName && paths.has(pathRes)) { + console.warn(pathRes, value); + keyNameNew[pathRes] = value; + } } }); } @@ -326,7 +331,7 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro this.configurationValue[this.observeAttr][this.attribute] = attributeArray; this.configurationValue[this.observeAttr][this.telemetry] = telemetryArray; } - this.updateKeyName(paths); + this.configurationValue[this.observeAttr][this.keyName] = this.sortObjectKeyPathJson('keyName', keyNameNew); } sortObjectKeyPathJson = (key: string, value: object): object => { @@ -352,41 +357,6 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro }); } - private updateKeyName = (paths: Set): void => { - const keyNameNew = {}; - paths.forEach(path => { - const pathParameter = this.findIndexesForIds(path); - if (pathParameter.length === 3) { - keyNameNew[path] = this.lwm2mDeviceProfileFormGroup.get('observeAttrTelemetry').value - .clientLwM2M[pathParameter[0]].instances[pathParameter[1]].resources[pathParameter[2]][this.keyName]; - } - }); - this.configurationValue[this.observeAttr][this.keyName] = this.sortObjectKeyPathJson('keyName', keyNameNew); - } - - private findIndexesForIds = (path: string): number[] => { - const [objectId, instanceId, resourceId] = Array.from(path.substring(1).split('/'), Number); - // TODO: All paths to map - const pathParameterIndexes: number[] = []; - const objectsOld = this.lwm2mDeviceProfileFormGroup.get('observeAttrTelemetry').value.clientLwM2M as ObjectLwM2M[]; - let isIdIndex = (element) => element.id === objectId; - const objIndex = objectsOld.findIndex(isIdIndex); - if (objIndex >= 0) { - pathParameterIndexes.push(objIndex); - isIdIndex = (element) => element.id === instanceId; - const instIndex = objectsOld[objIndex].instances.findIndex(isIdIndex); - if (instIndex >= 0) { - pathParameterIndexes.push(instIndex); - isIdIndex = (element) => element.id === resourceId; - const resIndex = objectsOld[objIndex].instances[instIndex].resources.findIndex(isIdIndex); - if (resIndex >= 0) { - pathParameterIndexes.push(resIndex); - } - } - } - return pathParameterIndexes; - } - private getObjectsFromJsonAllConfig = (): number[] => { const objectsIds = new Set(); if (this.configurationValue[this.observeAttr]) {