Commit ef54e5580ec55ffcc521bebd47e5d43324ffe5bc

Authored by Andrii Shvaika
1 parent c61c52bb

Slect default LwM2M content type based on the version of the client

@@ -31,7 +31,6 @@ import org.eclipse.leshan.core.node.LwM2mObjectInstance; @@ -31,7 +31,6 @@ import org.eclipse.leshan.core.node.LwM2mObjectInstance;
31 import org.eclipse.leshan.core.node.LwM2mPath; 31 import org.eclipse.leshan.core.node.LwM2mPath;
32 import org.eclipse.leshan.core.node.LwM2mResource; 32 import org.eclipse.leshan.core.node.LwM2mResource;
33 import org.eclipse.leshan.core.observation.Observation; 33 import org.eclipse.leshan.core.observation.Observation;
34 -import org.eclipse.leshan.core.request.ContentFormat;  
35 import org.eclipse.leshan.core.request.WriteRequest; 34 import org.eclipse.leshan.core.request.WriteRequest;
36 import org.eclipse.leshan.core.response.ReadResponse; 35 import org.eclipse.leshan.core.response.ReadResponse;
37 import org.eclipse.leshan.server.registration.Registration; 36 import org.eclipse.leshan.server.registration.Registration;
@@ -100,6 +99,7 @@ import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.L @@ -100,6 +99,7 @@ import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.L
100 import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.LOG_LW2M_INFO; 99 import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.LOG_LW2M_INFO;
101 import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.LOG_LW2M_TELEMETRY; 100 import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.LOG_LW2M_TELEMETRY;
102 import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.LOG_LW2M_VALUE; 101 import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.LOG_LW2M_VALUE;
  102 +import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.LOG_LW2M_WARN;
103 import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.LWM2M_STRATEGY_2; 103 import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.LWM2M_STRATEGY_2;
104 import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.LwM2mTypeOper.DISCOVER; 104 import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.LwM2mTypeOper.DISCOVER;
105 import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.LwM2mTypeOper.EXECUTE; 105 import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.LwM2mTypeOper.EXECUTE;
@@ -183,39 +183,38 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler @@ -183,39 +183,38 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler
183 */ 183 */
184 public void onRegistered(Registration registration, Collection<Observation> previousObservations) { 184 public void onRegistered(Registration registration, Collection<Observation> previousObservations) {
185 registrationExecutor.submit(() -> { 185 registrationExecutor.submit(() -> {
  186 + LwM2mClient lwM2MClient = this.clientContext.getClientByEndpoint(registration.getEndpoint());
186 try { 187 try {
187 log.warn("[{}] [{{}] Client: create after Registration", registration.getEndpoint(), registration.getId()); 188 log.warn("[{}] [{{}] Client: create after Registration", registration.getEndpoint(), registration.getId());
188 - LwM2mClient lwM2MClient = this.clientContext.getClientByEndpoint(registration.getEndpoint());  
189 if (lwM2MClient != null) { 189 if (lwM2MClient != null) {
190 this.clientContext.register(lwM2MClient, registration); 190 this.clientContext.register(lwM2MClient, registration);
  191 + this.sendLogsToThingsboard(lwM2MClient, LOG_LW2M_INFO + ": Client registered with registration id: " + registration.getId());
191 SessionInfoProto sessionInfo = lwM2MClient.getSession(); 192 SessionInfoProto sessionInfo = lwM2MClient.getSession();
192 - if (sessionInfo != null) {  
193 - transportService.registerAsyncSession(sessionInfo, new LwM2mSessionMsgListener(this, sessionInfo));  
194 - TransportProtos.TransportToDeviceActorMsg msg = TransportProtos.TransportToDeviceActorMsg.newBuilder()  
195 - .setSessionInfo(sessionInfo)  
196 - .setSessionEvent(DefaultTransportService.getSessionEventMsg(SessionEvent.OPEN))  
197 - .setSubscribeToAttributes(TransportProtos.SubscribeToAttributeUpdatesMsg.newBuilder().build())  
198 - .setSubscribeToRPC(TransportProtos.SubscribeToRPCMsg.newBuilder().build())  
199 - .build();  
200 - transportService.process(msg, null);  
201 - this.getInfoFirmwareUpdate(lwM2MClient, null);  
202 - this.getInfoSoftwareUpdate(lwM2MClient, null);  
203 - this.initLwM2mFromClientValue(registration, lwM2MClient);  
204 - this.sendLogsToThingsboard(lwM2MClient, LOG_LW2M_INFO + ": Client create after Registration");  
205 - } else {  
206 - log.error("Client: [{}] onRegistered [{}] name [{}] sessionInfo ", registration.getId(), registration.getEndpoint(), null);  
207 - } 193 + transportService.registerAsyncSession(sessionInfo, new LwM2mSessionMsgListener(this, sessionInfo));
  194 + TransportProtos.TransportToDeviceActorMsg msg = TransportProtos.TransportToDeviceActorMsg.newBuilder()
  195 + .setSessionInfo(sessionInfo)
  196 + .setSessionEvent(DefaultTransportService.getSessionEventMsg(SessionEvent.OPEN))
  197 + .setSubscribeToAttributes(TransportProtos.SubscribeToAttributeUpdatesMsg.newBuilder().build())
  198 + .setSubscribeToRPC(TransportProtos.SubscribeToRPCMsg.newBuilder().build())
  199 + .build();
  200 + transportService.process(msg, null);
  201 + this.getInfoFirmwareUpdate(lwM2MClient, null);
  202 + this.getInfoSoftwareUpdate(lwM2MClient, null);
  203 + this.initClientTelemetry(lwM2MClient);
208 } else { 204 } else {
209 - log.error("Client: [{}] onRegistered [{}] name [{}] lwM2MClient ", registration.getId(), registration.getEndpoint(), null); 205 + log.error("Client: [{}] onRegistered [{}] name [{}] lwM2MClient ", registration.getId(), registration.getEndpoint(), null);
210 } 206 }
211 } catch (LwM2MClientStateException stateException) { 207 } catch (LwM2MClientStateException stateException) {
212 if (LwM2MClientState.UNREGISTERED.equals(stateException.getState())) { 208 if (LwM2MClientState.UNREGISTERED.equals(stateException.getState())) {
213 log.info("[{}] retry registration due to race condition: [{}].", registration.getEndpoint(), stateException.getState()); 209 log.info("[{}] retry registration due to race condition: [{}].", registration.getEndpoint(), stateException.getState());
214 // Race condition detected and the client was in progress of unregistration while new registration arrived. Let's try again. 210 // Race condition detected and the client was in progress of unregistration while new registration arrived. Let's try again.
215 onRegistered(registration, previousObservations); 211 onRegistered(registration, previousObservations);
  212 + } else {
  213 + this.sendLogsToThingsboard(lwM2MClient, LOG_LW2M_WARN + ": Client registration failed due to invalid state: " + stateException.getState());
216 } 214 }
217 } catch (Throwable t) { 215 } catch (Throwable t) {
218 log.error("[{}] endpoint [{}] error Unable registration.", registration.getEndpoint(), t); 216 log.error("[{}] endpoint [{}] error Unable registration.", registration.getEndpoint(), t);
  217 + this.sendLogsToThingsboard(lwM2MClient, LOG_LW2M_WARN + ": Client registration failed due to: " + t.getMessage());
219 } 218 }
220 }); 219 });
221 } 220 }
@@ -232,7 +231,7 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler @@ -232,7 +231,7 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler
232 clientContext.updateRegistration(lwM2MClient, registration); 231 clientContext.updateRegistration(lwM2MClient, registration);
233 TransportProtos.SessionInfoProto sessionInfo = lwM2MClient.getSession(); 232 TransportProtos.SessionInfoProto sessionInfo = lwM2MClient.getSession();
234 this.reportActivityAndRegister(sessionInfo); 233 this.reportActivityAndRegister(sessionInfo);
235 - if (registration.getQueueMode()) { 234 + if (registration.usesQueueMode()) {
236 LwM2mQueuedRequest request; 235 LwM2mQueuedRequest request;
237 while ((request = lwM2MClient.getQueuedRequests().poll()) != null) { 236 while ((request = lwM2MClient.getQueuedRequests().poll()) != null) {
238 request.send(); 237 request.send();
@@ -292,8 +291,11 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler @@ -292,8 +291,11 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler
292 @Override 291 @Override
293 public void setCancelObservationsAll(Registration registration) { 292 public void setCancelObservationsAll(Registration registration) {
294 if (registration != null) { 293 if (registration != null) {
295 - this.lwM2mTransportRequest.sendAllRequest(registration, null, OBSERVE_CANCEL_ALL,  
296 - null, null, this.config.getTimeout(), null); 294 + LwM2mClient client = clientContext.getClientByEndpoint(registration.getEndpoint());
  295 + if (client != null && client.getRegistration() != null && client.getRegistration().getId().equals(registration.getId())) {
  296 + this.lwM2mTransportRequest.sendAllRequest(client, null, OBSERVE_CANCEL_ALL,
  297 + null, null, this.config.getTimeout(), null);
  298 + }
297 } 299 }
298 } 300 }
299 301
@@ -459,13 +461,14 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler @@ -459,13 +461,14 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler
459 this.rpcSubscriptions.put(requestUUID, toDeviceRpcRequestMsg.getExpirationTime()); 461 this.rpcSubscriptions.put(requestUUID, toDeviceRpcRequestMsg.getExpirationTime());
460 Lwm2mClientRpcRequest lwm2mClientRpcRequest = null; 462 Lwm2mClientRpcRequest lwm2mClientRpcRequest = null;
461 try { 463 try {
462 - Registration registration = clientContext.getClientBySessionInfo(sessionInfo).getRegistration(); 464 + LwM2mClient client = clientContext.getClientBySessionInfo(sessionInfo);
  465 + Registration registration = client.getRegistration();
463 lwm2mClientRpcRequest = new Lwm2mClientRpcRequest(lwM2mTypeOper, bodyParams, toDeviceRpcRequestMsg.getRequestId(), sessionInfo, registration, this); 466 lwm2mClientRpcRequest = new Lwm2mClientRpcRequest(lwM2mTypeOper, bodyParams, toDeviceRpcRequestMsg.getRequestId(), sessionInfo, registration, this);
464 if (lwm2mClientRpcRequest.getErrorMsg() != null) { 467 if (lwm2mClientRpcRequest.getErrorMsg() != null) {
465 lwm2mClientRpcRequest.setResponseCode(BAD_REQUEST.name()); 468 lwm2mClientRpcRequest.setResponseCode(BAD_REQUEST.name());
466 this.onToDeviceRpcResponse(lwm2mClientRpcRequest.getDeviceRpcResponseResultMsg(), sessionInfo); 469 this.onToDeviceRpcResponse(lwm2mClientRpcRequest.getDeviceRpcResponseResultMsg(), sessionInfo);
467 } else { 470 } else {
468 - lwM2mTransportRequest.sendAllRequest(registration, lwm2mClientRpcRequest.getTargetIdVer(), lwm2mClientRpcRequest.getTypeOper(), 471 + lwM2mTransportRequest.sendAllRequest(client, lwm2mClientRpcRequest.getTargetIdVer(), lwm2mClientRpcRequest.getTypeOper(),
469 null, 472 null,
470 lwm2mClientRpcRequest.getValue() == null ? lwm2mClientRpcRequest.getParams() : lwm2mClientRpcRequest.getValue(), 473 lwm2mClientRpcRequest.getValue() == null ? lwm2mClientRpcRequest.getParams() : lwm2mClientRpcRequest.getValue(),
471 this.config.getTimeout(), lwm2mClientRpcRequest); 474 this.config.getTimeout(), lwm2mClientRpcRequest);
@@ -520,17 +523,6 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler @@ -520,17 +523,6 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler
520 } 523 }
521 524
522 /** 525 /**
523 - * Trigger Server path = "/1/0/8"  
524 - * <p>  
525 - * Trigger bootStrap path = "/1/0/9" - have to implemented on client  
526 - */  
527 - @Override  
528 - public void doTrigger(Registration registration, String path) {  
529 - lwM2mTransportRequest.sendAllRequest(registration, path, EXECUTE,  
530 - ContentFormat.TLV.getName(), null, this.config.getTimeout(), null);  
531 - }  
532 -  
533 - /**  
534 * Deregister session in transport 526 * Deregister session in transport
535 * 527 *
536 * @param sessionInfo - lwm2m client 528 * @param sessionInfo - lwm2m client
@@ -572,7 +564,7 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler @@ -572,7 +564,7 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler
572 * @param registrationId - Id of Registration LwM2M Client 564 * @param registrationId - Id of Registration LwM2M Client
573 */ 565 */
574 @Override 566 @Override
575 - public void sendLogsToThingsboard2(String registrationId, String logMsg) { 567 + public void sendLogsToThingsboard(String registrationId, String logMsg) {
576 sendLogsToThingsboard(clientContext.getClientByRegistrationId(registrationId), logMsg); 568 sendLogsToThingsboard(clientContext.getClientByRegistrationId(registrationId), logMsg);
577 } 569 }
578 570
@@ -595,24 +587,23 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler @@ -595,24 +587,23 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler
595 * - Read Request to the client after registration to read all resource values for all objects 587 * - Read Request to the client after registration to read all resource values for all objects
596 * - then Observe Request to the client marked as observe from the profile configuration. 588 * - then Observe Request to the client marked as observe from the profile configuration.
597 * 589 *
598 - * @param registration - Registration LwM2M Client  
599 - * @param lwM2MClient - object with All parameters off client 590 + * @param lwM2MClient - object with All parameters off client
600 */ 591 */
601 - private void initLwM2mFromClientValue(Registration registration, LwM2mClient lwM2MClient) {  
602 - LwM2mClientProfile lwM2MClientProfile = clientContext.getProfile(registration);  
603 - Set<String> clientObjects = clientContext.getSupportedIdVerInClient(registration); 592 + private void initClientTelemetry(LwM2mClient lwM2MClient) {
  593 + LwM2mClientProfile lwM2MClientProfile = clientContext.getProfile(lwM2MClient.getProfileId());
  594 + Set<String> clientObjects = clientContext.getSupportedIdVerInClient(lwM2MClient);
604 if (clientObjects != null && clientObjects.size() > 0) { 595 if (clientObjects != null && clientObjects.size() > 0) {
605 if (LWM2M_STRATEGY_2 == LwM2mTransportUtil.getClientOnlyObserveAfterConnect(lwM2MClientProfile)) { 596 if (LWM2M_STRATEGY_2 == LwM2mTransportUtil.getClientOnlyObserveAfterConnect(lwM2MClientProfile)) {
606 // #2 597 // #2
607 lwM2MClient.getPendingReadRequests().addAll(clientObjects); 598 lwM2MClient.getPendingReadRequests().addAll(clientObjects);
608 - clientObjects.forEach(path -> lwM2mTransportRequest.sendAllRequest(registration, path, READ, ContentFormat.TLV.getName(), 599 + clientObjects.forEach(path -> lwM2mTransportRequest.sendAllRequest(lwM2MClient, path, READ,
609 null, this.config.getTimeout(), null)); 600 null, this.config.getTimeout(), null));
610 } 601 }
611 // #1 602 // #1
612 - this.initReadAttrTelemetryObserveToClient(registration, lwM2MClient, READ, clientObjects);  
613 - this.initReadAttrTelemetryObserveToClient(registration, lwM2MClient, OBSERVE, clientObjects);  
614 - this.initReadAttrTelemetryObserveToClient(registration, lwM2MClient, WRITE_ATTRIBUTES, clientObjects);  
615 - this.initReadAttrTelemetryObserveToClient(registration, lwM2MClient, DISCOVER, clientObjects); 603 + this.initReadAttrTelemetryObserveToClient(lwM2MClient, READ, clientObjects);
  604 + this.initReadAttrTelemetryObserveToClient(lwM2MClient, OBSERVE, clientObjects);
  605 + this.initReadAttrTelemetryObserveToClient(lwM2MClient, WRITE_ATTRIBUTES, clientObjects);
  606 + this.initReadAttrTelemetryObserveToClient(lwM2MClient, DISCOVER, clientObjects);
616 } 607 }
617 } 608 }
618 609
@@ -749,15 +740,9 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler @@ -749,15 +740,9 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler
749 } 740 }
750 } 741 }
751 742
752 - /**  
753 - * Start observe/read: Attr/Telemetry  
754 - * #1 - Analyze: path in resource profile == client resource  
755 - *  
756 - * @param registration -  
757 - */  
758 - private void initReadAttrTelemetryObserveToClient(Registration registration, LwM2mClient lwM2MClient, 743 + private void initReadAttrTelemetryObserveToClient(LwM2mClient lwM2MClient,
759 LwM2mTypeOper typeOper, Set<String> clientObjects) { 744 LwM2mTypeOper typeOper, Set<String> clientObjects) {
760 - LwM2mClientProfile lwM2MClientProfile = clientContext.getProfile(registration); 745 + LwM2mClientProfile lwM2MClientProfile = clientContext.getProfile(lwM2MClient.getProfileId());
761 Set<String> result = null; 746 Set<String> result = null;
762 ConcurrentHashMap<String, Object> params = null; 747 ConcurrentHashMap<String, Object> params = null;
763 if (READ.equals(typeOper)) { 748 if (READ.equals(typeOper)) {
@@ -789,7 +774,7 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler @@ -789,7 +774,7 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler
789 lwM2MClient.getPendingReadRequests().addAll(pathSend); 774 lwM2MClient.getPendingReadRequests().addAll(pathSend);
790 ConcurrentHashMap<String, Object> finalParams = params; 775 ConcurrentHashMap<String, Object> finalParams = params;
791 pathSend.forEach(target -> { 776 pathSend.forEach(target -> {
792 - lwM2mTransportRequest.sendAllRequest(registration, target, typeOper, ContentFormat.TEXT.getName(), 777 + lwM2mTransportRequest.sendAllRequest(lwM2MClient, target, typeOper,
793 finalParams != null ? finalParams.get(target) : null, this.config.getTimeout(), null); 778 finalParams != null ? finalParams.get(target) : null, this.config.getTimeout(), null);
794 }); 779 });
795 if (OBSERVE.equals(typeOper)) { 780 if (OBSERVE.equals(typeOper)) {
@@ -1023,7 +1008,7 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler @@ -1023,7 +1008,7 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler
1023 if (sendAttrToThingsboard.getPathPostParametersAdd().size() > 0) { 1008 if (sendAttrToThingsboard.getPathPostParametersAdd().size() > 0) {
1024 // update value in Resources 1009 // update value in Resources
1025 clients.forEach(client -> { 1010 clients.forEach(client -> {
1026 - this.readObserveFromProfile(client.getRegistration(), sendAttrToThingsboard.getPathPostParametersAdd(), READ); 1011 + this.readObserveFromProfile(client, sendAttrToThingsboard.getPathPostParametersAdd(), READ);
1027 }); 1012 });
1028 } 1013 }
1029 // #4.2 del 1014 // #4.2 del
@@ -1050,12 +1035,12 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler @@ -1050,12 +1035,12 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler
1050 clients.forEach(client -> { 1035 clients.forEach(client -> {
1051 Registration registration = client.getRegistration(); 1036 Registration registration = client.getRegistration();
1052 if (postObserveAnalyzer.getPathPostParametersAdd().size() > 0) { 1037 if (postObserveAnalyzer.getPathPostParametersAdd().size() > 0) {
1053 - this.readObserveFromProfile(registration, postObserveAnalyzer.getPathPostParametersAdd(), OBSERVE); 1038 + this.readObserveFromProfile(client, postObserveAnalyzer.getPathPostParametersAdd(), OBSERVE);
1054 } 1039 }
1055 // 5.3 del 1040 // 5.3 del
1056 // send Request cancel observe to Client 1041 // send Request cancel observe to Client
1057 if (postObserveAnalyzer.getPathPostParametersDel().size() > 0) { 1042 if (postObserveAnalyzer.getPathPostParametersDel().size() > 0) {
1058 - this.cancelObserveFromProfile(registration, postObserveAnalyzer.getPathPostParametersDel()); 1043 + this.cancelObserveFromProfile(client, postObserveAnalyzer.getPathPostParametersDel());
1059 } 1044 }
1060 }); 1045 });
1061 } 1046 }
@@ -1092,19 +1077,18 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler @@ -1092,19 +1077,18 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler
1092 * Update Resource value after change RezAttrTelemetry in config Profile 1077 * Update Resource value after change RezAttrTelemetry in config Profile
1093 * send response Read to Client and add path to pathResAttrTelemetry in LwM2MClient.getAttrTelemetryObserveValue() 1078 * send response Read to Client and add path to pathResAttrTelemetry in LwM2MClient.getAttrTelemetryObserveValue()
1094 * 1079 *
1095 - * @param registration - Registration LwM2M Client  
1096 - * @param targets - path Resources == [ "/2/0/0", "/2/0/1"] 1080 + * @param targets - path Resources == [ "/2/0/0", "/2/0/1"]
1097 */ 1081 */
1098 - private void readObserveFromProfile(Registration registration, Set<String> targets, LwM2mTypeOper typeOper) { 1082 + private void readObserveFromProfile(LwM2mClient client, Set<String> targets, LwM2mTypeOper typeOper) {
1099 targets.forEach(target -> { 1083 targets.forEach(target -> {
1100 LwM2mPath pathIds = new LwM2mPath(convertPathFromIdVerToObjectId(target)); 1084 LwM2mPath pathIds = new LwM2mPath(convertPathFromIdVerToObjectId(target));
1101 if (pathIds.isResource()) { 1085 if (pathIds.isResource()) {
1102 if (READ.equals(typeOper)) { 1086 if (READ.equals(typeOper)) {
1103 - lwM2mTransportRequest.sendAllRequest(registration, target, typeOper,  
1104 - ContentFormat.TLV.getName(), null, this.config.getTimeout(), null); 1087 + lwM2mTransportRequest.sendAllRequest(client, target, typeOper,
  1088 + null, this.config.getTimeout(), null);
1105 } else if (OBSERVE.equals(typeOper)) { 1089 } else if (OBSERVE.equals(typeOper)) {
1106 - lwM2mTransportRequest.sendAllRequest(registration, target, typeOper,  
1107 - null, null, this.config.getTimeout(), null); 1090 + lwM2mTransportRequest.sendAllRequest(client, target, typeOper,
  1091 + null, this.config.getTimeout(), null);
1108 } 1092 }
1109 } 1093 }
1110 }); 1094 });
@@ -1153,13 +1137,12 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler @@ -1153,13 +1137,12 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler
1153 // #6.2 1137 // #6.2
1154 if (analyzerParameters.getPathPostParametersAdd().size() > 0) { 1138 if (analyzerParameters.getPathPostParametersAdd().size() > 0) {
1155 clients.forEach(client -> { 1139 clients.forEach(client -> {
1156 - Registration registration = client.getRegistration();  
1157 - Set<String> clientObjects = clientContext.getSupportedIdVerInClient(registration); 1140 + Set<String> clientObjects = clientContext.getSupportedIdVerInClient(client);
1158 Set<String> pathSend = analyzerParameters.getPathPostParametersAdd().stream().filter(target -> clientObjects.contains("/" + target.split(LWM2M_SEPARATOR_PATH)[1])) 1141 Set<String> pathSend = analyzerParameters.getPathPostParametersAdd().stream().filter(target -> clientObjects.contains("/" + target.split(LWM2M_SEPARATOR_PATH)[1]))
1159 .collect(Collectors.toUnmodifiableSet()); 1142 .collect(Collectors.toUnmodifiableSet());
1160 if (!pathSend.isEmpty()) { 1143 if (!pathSend.isEmpty()) {
1161 ConcurrentHashMap<String, Object> finalParams = lwm2mAttributesNew; 1144 ConcurrentHashMap<String, Object> finalParams = lwm2mAttributesNew;
1162 - pathSend.forEach(target -> lwM2mTransportRequest.sendAllRequest(registration, target, WRITE_ATTRIBUTES, ContentFormat.TEXT.getName(), 1145 + pathSend.forEach(target -> lwM2mTransportRequest.sendAllRequest(client, target, WRITE_ATTRIBUTES,
1163 finalParams.get(target), this.config.getTimeout(), null)); 1146 finalParams.get(target), this.config.getTimeout(), null));
1164 } 1147 }
1165 }); 1148 });
@@ -1168,7 +1151,7 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler @@ -1168,7 +1151,7 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler
1168 if (analyzerParameters.getPathPostParametersDel().size() > 0) { 1151 if (analyzerParameters.getPathPostParametersDel().size() > 0) {
1169 clients.forEach(client -> { 1152 clients.forEach(client -> {
1170 Registration registration = client.getRegistration(); 1153 Registration registration = client.getRegistration();
1171 - Set<String> clientObjects = clientContext.getSupportedIdVerInClient(registration); 1154 + Set<String> clientObjects = clientContext.getSupportedIdVerInClient(client);
1172 Set<String> pathSend = analyzerParameters.getPathPostParametersDel().stream().filter(target -> clientObjects.contains("/" + target.split(LWM2M_SEPARATOR_PATH)[1])) 1155 Set<String> pathSend = analyzerParameters.getPathPostParametersDel().stream().filter(target -> clientObjects.contains("/" + target.split(LWM2M_SEPARATOR_PATH)[1]))
1173 .collect(Collectors.toUnmodifiableSet()); 1156 .collect(Collectors.toUnmodifiableSet());
1174 if (!pathSend.isEmpty()) { 1157 if (!pathSend.isEmpty()) {
@@ -1176,8 +1159,7 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler @@ -1176,8 +1159,7 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler
1176 Map<String, Object> params = (Map<String, Object>) lwm2mAttributesOld.get(target); 1159 Map<String, Object> params = (Map<String, Object>) lwm2mAttributesOld.get(target);
1177 params.clear(); 1160 params.clear();
1178 params.put(OBJECT_VERSION, ""); 1161 params.put(OBJECT_VERSION, "");
1179 - lwM2mTransportRequest.sendAllRequest(registration, target, WRITE_ATTRIBUTES, ContentFormat.TEXT.getName(),  
1180 - params, this.config.getTimeout(), null); 1162 + lwM2mTransportRequest.sendAllRequest(client, target, WRITE_ATTRIBUTES, params, this.config.getTimeout(), null);
1181 }); 1163 });
1182 } 1164 }
1183 }); 1165 });
@@ -1185,12 +1167,10 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler @@ -1185,12 +1167,10 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler
1185 1167
1186 } 1168 }
1187 1169
1188 - private void cancelObserveFromProfile(Registration registration, Set<String> paramAnallyzer) {  
1189 - LwM2mClient lwM2MClient = clientContext.getClientByEndpoint(registration.getEndpoint()); 1170 + private void cancelObserveFromProfile(LwM2mClient lwM2mClient, Set<String> paramAnallyzer) {
1190 paramAnallyzer.forEach(pathIdVer -> { 1171 paramAnallyzer.forEach(pathIdVer -> {
1191 - if (this.getResourceValueFromLwM2MClient(lwM2MClient, pathIdVer) != null) {  
1192 - lwM2mTransportRequest.sendAllRequest(registration, pathIdVer, OBSERVE_CANCEL, null,  
1193 - null, this.config.getTimeout(), null); 1172 + if (this.getResourceValueFromLwM2MClient(lwM2mClient, pathIdVer) != null) {
  1173 + lwM2mTransportRequest.sendAllRequest(lwM2mClient, pathIdVer, OBSERVE_CANCEL, null, this.config.getTimeout(), null);
1194 } 1174 }
1195 } 1175 }
1196 ); 1176 );
@@ -1198,9 +1178,7 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler @@ -1198,9 +1178,7 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler
1198 1178
1199 private void updateResourcesValueToClient(LwM2mClient lwM2MClient, Object valueOld, Object valueNew, String path) { 1179 private void updateResourcesValueToClient(LwM2mClient lwM2MClient, Object valueOld, Object valueNew, String path) {
1200 if (valueNew != null && (valueOld == null || !valueNew.toString().equals(valueOld.toString()))) { 1180 if (valueNew != null && (valueOld == null || !valueNew.toString().equals(valueOld.toString()))) {
1201 - lwM2mTransportRequest.sendAllRequest(lwM2MClient.getRegistration(), path, WRITE_REPLACE,  
1202 - ContentFormat.TLV.getName(), valueNew,  
1203 - this.config.getTimeout(), null); 1181 + lwM2mTransportRequest.sendAllRequest(lwM2MClient, path, WRITE_REPLACE, valueNew, this.config.getTimeout(), null);
1204 } else { 1182 } else {
1205 log.error("Failed update resource [{}] [{}]", path, valueNew); 1183 log.error("Failed update resource [{}] [{}]", path, valueNew);
1206 String logMsg = String.format("%s: Failed update resource path - %s value - %s. Value is not changed or bad", 1184 String logMsg = String.format("%s: Failed update resource path - %s value - %s. Value is not changed or bad",
@@ -87,7 +87,7 @@ public class LwM2mServerListener { @@ -87,7 +87,7 @@ public class LwM2mServerListener {
87 @Override 87 @Override
88 public void cancelled(Observation observation) { 88 public void cancelled(Observation observation) {
89 String msg = String.format("%s: Canceled Observation %s.", LOG_LW2M_INFO, observation.getPath()); 89 String msg = String.format("%s: Canceled Observation %s.", LOG_LW2M_INFO, observation.getPath());
90 - service.sendLogsToThingsboard2(observation.getRegistrationId(), msg); 90 + service.sendLogsToThingsboard(observation.getRegistrationId(), msg);
91 log.warn(msg); 91 log.warn(msg);
92 } 92 }
93 93
@@ -109,7 +109,7 @@ public class LwM2mServerListener { @@ -109,7 +109,7 @@ public class LwM2mServerListener {
109 String msg = String.format("%s: Successful start newObservation %s.", LOG_LW2M_INFO, 109 String msg = String.format("%s: Successful start newObservation %s.", LOG_LW2M_INFO,
110 observation.getPath()); 110 observation.getPath());
111 log.warn(msg); 111 log.warn(msg);
112 - service.sendLogsToThingsboard2(registration.getId(), msg); 112 + service.sendLogsToThingsboard(registration.getId(), msg);
113 } 113 }
114 }; 114 };
115 } 115 }
@@ -58,15 +58,13 @@ public interface LwM2mTransportMsgHandler { @@ -58,15 +58,13 @@ public interface LwM2mTransportMsgHandler {
58 58
59 void onToServerRpcResponse(TransportProtos.ToServerRpcResponseMsg toServerResponse); 59 void onToServerRpcResponse(TransportProtos.ToServerRpcResponseMsg toServerResponse);
60 60
61 - void doTrigger(Registration registration, String path);  
62 -  
63 void doDisconnect(TransportProtos.SessionInfoProto sessionInfo); 61 void doDisconnect(TransportProtos.SessionInfoProto sessionInfo);
64 62
65 void onAwakeDev(Registration registration); 63 void onAwakeDev(Registration registration);
66 64
67 void sendLogsToThingsboard(LwM2mClient client, String msg); 65 void sendLogsToThingsboard(LwM2mClient client, String msg);
68 66
69 - void sendLogsToThingsboard2(String registrationId, String msg); 67 + void sendLogsToThingsboard(String registrationId, String msg);
70 68
71 LwM2MTransportServerConfig getConfig(); 69 LwM2MTransportServerConfig getConfig();
72 } 70 }
@@ -116,21 +116,19 @@ public class LwM2mTransportRequest { @@ -116,21 +116,19 @@ public class LwM2mTransportRequest {
116 new NamedThreadFactory(String.format("LwM2M %s channel response after request", RESPONSE_REQUEST_CHANNEL))); 116 new NamedThreadFactory(String.format("LwM2M %s channel response after request", RESPONSE_REQUEST_CHANNEL)));
117 } 117 }
118 118
119 - /**  
120 - * Device management and service enablement, including Read, Write, Execute, Discover, Create, Delete and Write-Attributes  
121 - *  
122 - * @param registration -  
123 - * @param targetIdVer -  
124 - * @param typeOper -  
125 - * @param contentFormatName -  
126 - */ 119 + public void sendAllRequest(LwM2mClient lwM2MClient, String targetIdVer, LwM2mTypeOper typeOper, Object params, long timeoutInMs, Lwm2mClientRpcRequest lwm2mClientRpcRequest) {
  120 + sendAllRequest(lwM2MClient, targetIdVer, typeOper, lwM2MClient.getDefaultContentFormat(), params, timeoutInMs, lwm2mClientRpcRequest);
  121 + }
  122 +
127 123
128 - public void sendAllRequest(Registration registration, String targetIdVer, LwM2mTypeOper typeOper,  
129 - String contentFormatName, Object params, long timeoutInMs, Lwm2mClientRpcRequest lwm2mClientRpcRequest) {  
130 - LwM2mClient lwM2MClient = this.lwM2mClientContext.getClientByEndpoint(registration.getEndpoint()); 124 + public void sendAllRequest(LwM2mClient lwM2MClient, String targetIdVer, LwM2mTypeOper typeOper,
  125 + ContentFormat contentFormat, Object params, long timeoutInMs, Lwm2mClientRpcRequest lwm2mClientRpcRequest) {
  126 + Registration registration = lwM2MClient.getRegistration();
131 try { 127 try {
132 String target = convertPathFromIdVerToObjectId(targetIdVer); 128 String target = convertPathFromIdVerToObjectId(targetIdVer);
133 - ContentFormat contentFormat = contentFormatName != null ? ContentFormat.fromName(contentFormatName.toUpperCase()) : ContentFormat.DEFAULT; 129 + if(contentFormat == null){
  130 + contentFormat = ContentFormat.DEFAULT;
  131 + }
134 LwM2mPath resultIds = target != null ? new LwM2mPath(target) : null; 132 LwM2mPath resultIds = target != null ? new LwM2mPath(target) : null;
135 if (!OBSERVE_CANCEL.name().equals(typeOper.name()) && resultIds != null && registration != null && resultIds.getObjectId() >= 0 && lwM2MClient != null) { 133 if (!OBSERVE_CANCEL.name().equals(typeOper.name()) && resultIds != null && registration != null && resultIds.getObjectId() >= 0 && lwM2MClient != null) {
136 if (lwM2MClient.isValidObjectVersion(targetIdVer)) { 134 if (lwM2MClient.isValidObjectVersion(targetIdVer)) {
@@ -26,6 +26,7 @@ import org.eclipse.leshan.core.node.LwM2mObjectInstance; @@ -26,6 +26,7 @@ import org.eclipse.leshan.core.node.LwM2mObjectInstance;
26 import org.eclipse.leshan.core.node.LwM2mPath; 26 import org.eclipse.leshan.core.node.LwM2mPath;
27 import org.eclipse.leshan.core.node.LwM2mResource; 27 import org.eclipse.leshan.core.node.LwM2mResource;
28 import org.eclipse.leshan.core.node.LwM2mSingleResource; 28 import org.eclipse.leshan.core.node.LwM2mSingleResource;
  29 +import org.eclipse.leshan.core.request.ContentFormat;
29 import org.eclipse.leshan.server.model.LwM2mModelProvider; 30 import org.eclipse.leshan.server.model.LwM2mModelProvider;
30 import org.eclipse.leshan.server.registration.Registration; 31 import org.eclipse.leshan.server.registration.Registration;
31 import org.eclipse.leshan.server.security.SecurityInfo; 32 import org.eclipse.leshan.server.security.SecurityInfo;
@@ -69,7 +70,8 @@ public class LwM2mClient implements Cloneable { @@ -69,7 +70,8 @@ public class LwM2mClient implements Cloneable {
69 @Getter 70 @Getter
70 private final String endpoint; 71 private final String endpoint;
71 private final Lock lock; 72 private final Lock lock;
72 - @Getter @Setter 73 + @Getter
  74 + @Setter
73 private LwM2MClientState state; 75 private LwM2MClientState state;
74 @Getter 76 @Getter
75 private final Map<String, ResourceValue> resources; 77 private final Map<String, ResourceValue> resources;
@@ -385,5 +387,14 @@ public class LwM2mClient implements Cloneable { @@ -385,5 +387,14 @@ public class LwM2mClient implements Cloneable {
385 } 387 }
386 } 388 }
387 389
  390 + public ContentFormat getDefaultContentFormat() {
  391 + if (registration == null) {
  392 + return ContentFormat.DEFAULT;
  393 + } else if (registration.getLwM2mVersion().equals("1.0")) {
  394 + return ContentFormat.TLV;
  395 + } else {
  396 + return ContentFormat.TEXT;
  397 + }
  398 + }
388 } 399 }
389 400
@@ -40,15 +40,6 @@ public interface LwM2mClientContext { @@ -40,15 +40,6 @@ public interface LwM2mClientContext {
40 40
41 void unregister(LwM2mClient client, Registration registration) throws LwM2MClientStateException; 41 void unregister(LwM2mClient client, Registration registration) throws LwM2MClientStateException;
42 42
43 -  
44 -// LwM2mClient getOrRegister(Registration registration);  
45 -  
46 -// LwM2mClient registerOrUpdate(Registration registration);  
47 -  
48 -// LwM2mClient fetchClientByEndpoint(String endpoint);  
49 -  
50 -// Registration getRegistration(String registrationId);  
51 -  
52 Collection<LwM2mClient> getLwM2mClients(); 43 Collection<LwM2mClient> getLwM2mClients();
53 44
54 Map<UUID, LwM2mClientProfile> getProfiles(); 45 Map<UUID, LwM2mClientProfile> getProfiles();
@@ -61,7 +52,7 @@ public interface LwM2mClientContext { @@ -61,7 +52,7 @@ public interface LwM2mClientContext {
61 52
62 LwM2mClientProfile profileUpdate(DeviceProfile deviceProfile); 53 LwM2mClientProfile profileUpdate(DeviceProfile deviceProfile);
63 54
64 - Set<String> getSupportedIdVerInClient(Registration registration); 55 + Set<String> getSupportedIdVerInClient(LwM2mClient registration);
65 56
66 LwM2mClient getClientByDeviceId(UUID deviceId); 57 LwM2mClient getClientByDeviceId(UUID deviceId);
67 58
@@ -205,19 +205,13 @@ public class LwM2mClientContextImpl implements LwM2mClientContext { @@ -205,19 +205,13 @@ public class LwM2mClientContextImpl implements LwM2mClientContext {
205 } 205 }
206 } 206 }
207 207
208 - /**  
209 - * if isVer - ok or default ver=DEFAULT_LWM2M_VERSION  
210 - *  
211 - * @param registration -  
212 - * @return - all objectIdVer in client  
213 - */  
214 @Override 208 @Override
215 - public Set<String> getSupportedIdVerInClient(Registration registration) { 209 + public Set<String> getSupportedIdVerInClient(LwM2mClient client) {
216 Set<String> clientObjects = ConcurrentHashMap.newKeySet(); 210 Set<String> clientObjects = ConcurrentHashMap.newKeySet();
217 - Arrays.stream(registration.getObjectLinks()).forEach(url -> {  
218 - LwM2mPath pathIds = new LwM2mPath(url.getUrl()); 211 + Arrays.stream(client.getRegistration().getObjectLinks()).forEach(link -> {
  212 + LwM2mPath pathIds = new LwM2mPath(link.getUrl());
219 if (!pathIds.isRoot()) { 213 if (!pathIds.isRoot()) {
220 - clientObjects.add(convertPathFromObjectIdToIdVer(url.getUrl(), registration)); 214 + clientObjects.add(convertPathFromObjectIdToIdVer(link.getUrl(), client.getRegistration()));
221 } 215 }
222 }); 216 });
223 return (clientObjects.size() > 0) ? clientObjects : null; 217 return (clientObjects.size() > 0) ? clientObjects : null;
@@ -169,7 +169,7 @@ public class LwM2mFwSwUpdate { @@ -169,7 +169,7 @@ public class LwM2mFwSwUpdate {
169 LwM2mTransportUtil.LwM2mTypeOper.FW_UPDATE.name(), FW_PACKAGE_ID); 169 LwM2mTransportUtil.LwM2mTypeOper.FW_UPDATE.name(), FW_PACKAGE_ID);
170 handler.sendLogsToThingsboard(lwM2MClient, fwMsg); 170 handler.sendLogsToThingsboard(lwM2MClient, fwMsg);
171 log.warn("8) Start firmware Update. Send save to: [{}] ver: [{}] path: [{}]", this.lwM2MClient.getDeviceName(), this.currentVersion, targetIdVer); 171 log.warn("8) Start firmware Update. Send save to: [{}] ver: [{}] path: [{}]", this.lwM2MClient.getDeviceName(), this.currentVersion, targetIdVer);
172 - request.sendAllRequest(this.lwM2MClient.getRegistration(), targetIdVer, WRITE_REPLACE, ContentFormat.OPAQUE.getName(), 172 + request.sendAllRequest(this.lwM2MClient, targetIdVer, WRITE_REPLACE, ContentFormat.OPAQUE,
173 firmwareChunk, handler.config.getTimeout(), this.rpcRequest); 173 firmwareChunk, handler.config.getTimeout(), this.rpcRequest);
174 } 174 }
175 else { 175 else {
@@ -202,8 +202,7 @@ public class LwM2mFwSwUpdate { @@ -202,8 +202,7 @@ public class LwM2mFwSwUpdate {
202 public void executeFwSwWare(DefaultLwM2MTransportMsgHandler handler, LwM2mTransportRequest request) { 202 public void executeFwSwWare(DefaultLwM2MTransportMsgHandler handler, LwM2mTransportRequest request) {
203 this.setStateUpdate(UPDATING.name()); 203 this.setStateUpdate(UPDATING.name());
204 this.sendLogs(handler, EXECUTE.name(), LOG_LW2M_INFO, null); 204 this.sendLogs(handler, EXECUTE.name(), LOG_LW2M_INFO, null);
205 - request.sendAllRequest(this.lwM2MClient.getRegistration(), this.pathInstallId, EXECUTE, ContentFormat.TLV.getName(),  
206 - null, 0, this.rpcRequest); 205 + request.sendAllRequest(this.lwM2MClient, this.pathInstallId, EXECUTE, null, 0, this.rpcRequest);
207 } 206 }
208 207
209 /** 208 /**
@@ -334,10 +333,10 @@ public class LwM2mFwSwUpdate { @@ -334,10 +333,10 @@ public class LwM2mFwSwUpdate {
334 } 333 }
335 334
336 private void observeStateUpdate(DefaultLwM2MTransportMsgHandler handler, LwM2mTransportRequest request) { 335 private void observeStateUpdate(DefaultLwM2MTransportMsgHandler handler, LwM2mTransportRequest request) {
337 - request.sendAllRequest(lwM2MClient.getRegistration(), 336 + request.sendAllRequest(lwM2MClient,
338 convertPathFromObjectIdToIdVer(this.pathStateId, this.lwM2MClient.getRegistration()), OBSERVE, 337 convertPathFromObjectIdToIdVer(this.pathStateId, this.lwM2MClient.getRegistration()), OBSERVE,
339 null, null, 0, null); 338 null, null, 0, null);
340 - request.sendAllRequest(lwM2MClient.getRegistration(), 339 + request.sendAllRequest(lwM2MClient,
341 convertPathFromObjectIdToIdVer(this.pathResultId, this.lwM2MClient.getRegistration()), OBSERVE, 340 convertPathFromObjectIdToIdVer(this.pathResultId, this.lwM2MClient.getRegistration()), OBSERVE,
342 null, null, 0, null); 341 null, null, 0, null);
343 } 342 }
@@ -364,8 +363,7 @@ public class LwM2mFwSwUpdate { @@ -364,8 +363,7 @@ public class LwM2mFwSwUpdate {
364 this.pendingInfoRequestsStart.add(convertPathFromObjectIdToIdVer( 363 this.pendingInfoRequestsStart.add(convertPathFromObjectIdToIdVer(
365 this.pathResultId, this.lwM2MClient.getRegistration())); 364 this.pathResultId, this.lwM2MClient.getRegistration()));
366 this.pendingInfoRequestsStart.forEach(pathIdVer -> { 365 this.pendingInfoRequestsStart.forEach(pathIdVer -> {
367 - request.sendAllRequest(this.lwM2MClient.getRegistration(), pathIdVer, OBSERVE, ContentFormat.TLV.getName(),  
368 - null, 0, this.rpcRequest); 366 + request.sendAllRequest(this.lwM2MClient, pathIdVer, OBSERVE, null, 0, this.rpcRequest);
369 }); 367 });
370 368
371 } 369 }