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 31 import org.eclipse.leshan.core.node.LwM2mPath;
32 32 import org.eclipse.leshan.core.node.LwM2mResource;
33 33 import org.eclipse.leshan.core.observation.Observation;
34   -import org.eclipse.leshan.core.request.ContentFormat;
35 34 import org.eclipse.leshan.core.request.WriteRequest;
36 35 import org.eclipse.leshan.core.response.ReadResponse;
37 36 import org.eclipse.leshan.server.registration.Registration;
... ... @@ -100,6 +99,7 @@ import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.L
100 99 import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.LOG_LW2M_INFO;
101 100 import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.LOG_LW2M_TELEMETRY;
102 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 103 import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.LWM2M_STRATEGY_2;
104 104 import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.LwM2mTypeOper.DISCOVER;
105 105 import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.LwM2mTypeOper.EXECUTE;
... ... @@ -183,39 +183,38 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler
183 183 */
184 184 public void onRegistered(Registration registration, Collection<Observation> previousObservations) {
185 185 registrationExecutor.submit(() -> {
  186 + LwM2mClient lwM2MClient = this.clientContext.getClientByEndpoint(registration.getEndpoint());
186 187 try {
187 188 log.warn("[{}] [{{}] Client: create after Registration", registration.getEndpoint(), registration.getId());
188   - LwM2mClient lwM2MClient = this.clientContext.getClientByEndpoint(registration.getEndpoint());
189 189 if (lwM2MClient != null) {
190 190 this.clientContext.register(lwM2MClient, registration);
  191 + this.sendLogsToThingsboard(lwM2MClient, LOG_LW2M_INFO + ": Client registered with registration id: " + registration.getId());
191 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 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 207 } catch (LwM2MClientStateException stateException) {
212 208 if (LwM2MClientState.UNREGISTERED.equals(stateException.getState())) {
213 209 log.info("[{}] retry registration due to race condition: [{}].", registration.getEndpoint(), stateException.getState());
214 210 // Race condition detected and the client was in progress of unregistration while new registration arrived. Let's try again.
215 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 215 } catch (Throwable t) {
218 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 231 clientContext.updateRegistration(lwM2MClient, registration);
233 232 TransportProtos.SessionInfoProto sessionInfo = lwM2MClient.getSession();
234 233 this.reportActivityAndRegister(sessionInfo);
235   - if (registration.getQueueMode()) {
  234 + if (registration.usesQueueMode()) {
236 235 LwM2mQueuedRequest request;
237 236 while ((request = lwM2MClient.getQueuedRequests().poll()) != null) {
238 237 request.send();
... ... @@ -292,8 +291,11 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler
292 291 @Override
293 292 public void setCancelObservationsAll(Registration registration) {
294 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 461 this.rpcSubscriptions.put(requestUUID, toDeviceRpcRequestMsg.getExpirationTime());
460 462 Lwm2mClientRpcRequest lwm2mClientRpcRequest = null;
461 463 try {
462   - Registration registration = clientContext.getClientBySessionInfo(sessionInfo).getRegistration();
  464 + LwM2mClient client = clientContext.getClientBySessionInfo(sessionInfo);
  465 + Registration registration = client.getRegistration();
463 466 lwm2mClientRpcRequest = new Lwm2mClientRpcRequest(lwM2mTypeOper, bodyParams, toDeviceRpcRequestMsg.getRequestId(), sessionInfo, registration, this);
464 467 if (lwm2mClientRpcRequest.getErrorMsg() != null) {
465 468 lwm2mClientRpcRequest.setResponseCode(BAD_REQUEST.name());
466 469 this.onToDeviceRpcResponse(lwm2mClientRpcRequest.getDeviceRpcResponseResultMsg(), sessionInfo);
467 470 } else {
468   - lwM2mTransportRequest.sendAllRequest(registration, lwm2mClientRpcRequest.getTargetIdVer(), lwm2mClientRpcRequest.getTypeOper(),
  471 + lwM2mTransportRequest.sendAllRequest(client, lwm2mClientRpcRequest.getTargetIdVer(), lwm2mClientRpcRequest.getTypeOper(),
469 472 null,
470 473 lwm2mClientRpcRequest.getValue() == null ? lwm2mClientRpcRequest.getParams() : lwm2mClientRpcRequest.getValue(),
471 474 this.config.getTimeout(), lwm2mClientRpcRequest);
... ... @@ -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 526 * Deregister session in transport
535 527 *
536 528 * @param sessionInfo - lwm2m client
... ... @@ -572,7 +564,7 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler
572 564 * @param registrationId - Id of Registration LwM2M Client
573 565 */
574 566 @Override
575   - public void sendLogsToThingsboard2(String registrationId, String logMsg) {
  567 + public void sendLogsToThingsboard(String registrationId, String logMsg) {
576 568 sendLogsToThingsboard(clientContext.getClientByRegistrationId(registrationId), logMsg);
577 569 }
578 570
... ... @@ -595,24 +587,23 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler
595 587 * - Read Request to the client after registration to read all resource values for all objects
596 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 595 if (clientObjects != null && clientObjects.size() > 0) {
605 596 if (LWM2M_STRATEGY_2 == LwM2mTransportUtil.getClientOnlyObserveAfterConnect(lwM2MClientProfile)) {
606 597 // #2
607 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 600 null, this.config.getTimeout(), null));
610 601 }
611 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 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 744 LwM2mTypeOper typeOper, Set<String> clientObjects) {
760   - LwM2mClientProfile lwM2MClientProfile = clientContext.getProfile(registration);
  745 + LwM2mClientProfile lwM2MClientProfile = clientContext.getProfile(lwM2MClient.getProfileId());
761 746 Set<String> result = null;
762 747 ConcurrentHashMap<String, Object> params = null;
763 748 if (READ.equals(typeOper)) {
... ... @@ -789,7 +774,7 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler
789 774 lwM2MClient.getPendingReadRequests().addAll(pathSend);
790 775 ConcurrentHashMap<String, Object> finalParams = params;
791 776 pathSend.forEach(target -> {
792   - lwM2mTransportRequest.sendAllRequest(registration, target, typeOper, ContentFormat.TEXT.getName(),
  777 + lwM2mTransportRequest.sendAllRequest(lwM2MClient, target, typeOper,
793 778 finalParams != null ? finalParams.get(target) : null, this.config.getTimeout(), null);
794 779 });
795 780 if (OBSERVE.equals(typeOper)) {
... ... @@ -1023,7 +1008,7 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler
1023 1008 if (sendAttrToThingsboard.getPathPostParametersAdd().size() > 0) {
1024 1009 // update value in Resources
1025 1010 clients.forEach(client -> {
1026   - this.readObserveFromProfile(client.getRegistration(), sendAttrToThingsboard.getPathPostParametersAdd(), READ);
  1011 + this.readObserveFromProfile(client, sendAttrToThingsboard.getPathPostParametersAdd(), READ);
1027 1012 });
1028 1013 }
1029 1014 // #4.2 del
... ... @@ -1050,12 +1035,12 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler
1050 1035 clients.forEach(client -> {
1051 1036 Registration registration = client.getRegistration();
1052 1037 if (postObserveAnalyzer.getPathPostParametersAdd().size() > 0) {
1053   - this.readObserveFromProfile(registration, postObserveAnalyzer.getPathPostParametersAdd(), OBSERVE);
  1038 + this.readObserveFromProfile(client, postObserveAnalyzer.getPathPostParametersAdd(), OBSERVE);
1054 1039 }
1055 1040 // 5.3 del
1056 1041 // send Request cancel observe to Client
1057 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 1077 * Update Resource value after change RezAttrTelemetry in config Profile
1093 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 1083 targets.forEach(target -> {
1100 1084 LwM2mPath pathIds = new LwM2mPath(convertPathFromIdVerToObjectId(target));
1101 1085 if (pathIds.isResource()) {
1102 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 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 1137 // #6.2
1154 1138 if (analyzerParameters.getPathPostParametersAdd().size() > 0) {
1155 1139 clients.forEach(client -> {
1156   - Registration registration = client.getRegistration();
1157   - Set<String> clientObjects = clientContext.getSupportedIdVerInClient(registration);
  1140 + Set<String> clientObjects = clientContext.getSupportedIdVerInClient(client);
1158 1141 Set<String> pathSend = analyzerParameters.getPathPostParametersAdd().stream().filter(target -> clientObjects.contains("/" + target.split(LWM2M_SEPARATOR_PATH)[1]))
1159 1142 .collect(Collectors.toUnmodifiableSet());
1160 1143 if (!pathSend.isEmpty()) {
1161 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 1146 finalParams.get(target), this.config.getTimeout(), null));
1164 1147 }
1165 1148 });
... ... @@ -1168,7 +1151,7 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler
1168 1151 if (analyzerParameters.getPathPostParametersDel().size() > 0) {
1169 1152 clients.forEach(client -> {
1170 1153 Registration registration = client.getRegistration();
1171   - Set<String> clientObjects = clientContext.getSupportedIdVerInClient(registration);
  1154 + Set<String> clientObjects = clientContext.getSupportedIdVerInClient(client);
1172 1155 Set<String> pathSend = analyzerParameters.getPathPostParametersDel().stream().filter(target -> clientObjects.contains("/" + target.split(LWM2M_SEPARATOR_PATH)[1]))
1173 1156 .collect(Collectors.toUnmodifiableSet());
1174 1157 if (!pathSend.isEmpty()) {
... ... @@ -1176,8 +1159,7 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler
1176 1159 Map<String, Object> params = (Map<String, Object>) lwm2mAttributesOld.get(target);
1177 1160 params.clear();
1178 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 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 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 1178
1199 1179 private void updateResourcesValueToClient(LwM2mClient lwM2MClient, Object valueOld, Object valueNew, String path) {
1200 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 1182 } else {
1205 1183 log.error("Failed update resource [{}] [{}]", path, valueNew);
1206 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 87 @Override
88 88 public void cancelled(Observation observation) {
89 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 91 log.warn(msg);
92 92 }
93 93
... ... @@ -109,7 +109,7 @@ public class LwM2mServerListener {
109 109 String msg = String.format("%s: Successful start newObservation %s.", LOG_LW2M_INFO,
110 110 observation.getPath());
111 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 58
59 59 void onToServerRpcResponse(TransportProtos.ToServerRpcResponseMsg toServerResponse);
60 60
61   - void doTrigger(Registration registration, String path);
62   -
63 61 void doDisconnect(TransportProtos.SessionInfoProto sessionInfo);
64 62
65 63 void onAwakeDev(Registration registration);
66 64
67 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 69 LwM2MTransportServerConfig getConfig();
72 70 }
... ...
... ... @@ -116,21 +116,19 @@ public class LwM2mTransportRequest {
116 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 127 try {
132 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 132 LwM2mPath resultIds = target != null ? new LwM2mPath(target) : null;
135 133 if (!OBSERVE_CANCEL.name().equals(typeOper.name()) && resultIds != null && registration != null && resultIds.getObjectId() >= 0 && lwM2MClient != null) {
136 134 if (lwM2MClient.isValidObjectVersion(targetIdVer)) {
... ...
... ... @@ -26,6 +26,7 @@ import org.eclipse.leshan.core.node.LwM2mObjectInstance;
26 26 import org.eclipse.leshan.core.node.LwM2mPath;
27 27 import org.eclipse.leshan.core.node.LwM2mResource;
28 28 import org.eclipse.leshan.core.node.LwM2mSingleResource;
  29 +import org.eclipse.leshan.core.request.ContentFormat;
29 30 import org.eclipse.leshan.server.model.LwM2mModelProvider;
30 31 import org.eclipse.leshan.server.registration.Registration;
31 32 import org.eclipse.leshan.server.security.SecurityInfo;
... ... @@ -69,7 +70,8 @@ public class LwM2mClient implements Cloneable {
69 70 @Getter
70 71 private final String endpoint;
71 72 private final Lock lock;
72   - @Getter @Setter
  73 + @Getter
  74 + @Setter
73 75 private LwM2MClientState state;
74 76 @Getter
75 77 private final Map<String, ResourceValue> resources;
... ... @@ -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 40
41 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 43 Collection<LwM2mClient> getLwM2mClients();
53 44
54 45 Map<UUID, LwM2mClientProfile> getProfiles();
... ... @@ -61,7 +52,7 @@ public interface LwM2mClientContext {
61 52
62 53 LwM2mClientProfile profileUpdate(DeviceProfile deviceProfile);
63 54
64   - Set<String> getSupportedIdVerInClient(Registration registration);
  55 + Set<String> getSupportedIdVerInClient(LwM2mClient registration);
65 56
66 57 LwM2mClient getClientByDeviceId(UUID deviceId);
67 58
... ...
... ... @@ -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 208 @Override
215   - public Set<String> getSupportedIdVerInClient(Registration registration) {
  209 + public Set<String> getSupportedIdVerInClient(LwM2mClient client) {
216 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 213 if (!pathIds.isRoot()) {
220   - clientObjects.add(convertPathFromObjectIdToIdVer(url.getUrl(), registration));
  214 + clientObjects.add(convertPathFromObjectIdToIdVer(link.getUrl(), client.getRegistration()));
221 215 }
222 216 });
223 217 return (clientObjects.size() > 0) ? clientObjects : null;
... ...
... ... @@ -169,7 +169,7 @@ public class LwM2mFwSwUpdate {
169 169 LwM2mTransportUtil.LwM2mTypeOper.FW_UPDATE.name(), FW_PACKAGE_ID);
170 170 handler.sendLogsToThingsboard(lwM2MClient, fwMsg);
171 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 173 firmwareChunk, handler.config.getTimeout(), this.rpcRequest);
174 174 }
175 175 else {
... ... @@ -202,8 +202,7 @@ public class LwM2mFwSwUpdate {
202 202 public void executeFwSwWare(DefaultLwM2MTransportMsgHandler handler, LwM2mTransportRequest request) {
203 203 this.setStateUpdate(UPDATING.name());
204 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 333 }
335 334
336 335 private void observeStateUpdate(DefaultLwM2MTransportMsgHandler handler, LwM2mTransportRequest request) {
337   - request.sendAllRequest(lwM2MClient.getRegistration(),
  336 + request.sendAllRequest(lwM2MClient,
338 337 convertPathFromObjectIdToIdVer(this.pathStateId, this.lwM2MClient.getRegistration()), OBSERVE,
339 338 null, null, 0, null);
340   - request.sendAllRequest(lwM2MClient.getRegistration(),
  339 + request.sendAllRequest(lwM2MClient,
341 340 convertPathFromObjectIdToIdVer(this.pathResultId, this.lwM2MClient.getRegistration()), OBSERVE,
342 341 null, null, 0, null);
343 342 }
... ... @@ -364,8 +363,7 @@ public class LwM2mFwSwUpdate {
364 363 this.pendingInfoRequestsStart.add(convertPathFromObjectIdToIdVer(
365 364 this.pathResultId, this.lwM2MClient.getRegistration()));
366 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 }
... ...