Commit b0f5ff7c639a8ed5e39aeb420d25d5b810778281

Authored by nickAS21
1 parent dfa4433c

LWM2M: add RPC FirmwareUpdate

@@ -196,8 +196,8 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler @@ -196,8 +196,8 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler
196 .setSubscribeToRPC(TransportProtos.SubscribeToRPCMsg.newBuilder().build()) 196 .setSubscribeToRPC(TransportProtos.SubscribeToRPCMsg.newBuilder().build())
197 .build(); 197 .build();
198 transportService.process(msg, null); 198 transportService.process(msg, null);
199 - this.getInfoFirmwareUpdate(lwM2MClient);  
200 - this.getInfoSoftwareUpdate(lwM2MClient); 199 + this.getInfoFirmwareUpdate(lwM2MClient, null);
  200 + this.getInfoSoftwareUpdate(lwM2MClient, null);
201 this.initLwM2mFromClientValue(registration, lwM2MClient); 201 this.initLwM2mFromClientValue(registration, lwM2MClient);
202 this.sendLogsToThingsboard(LOG_LW2M_INFO + ": Client create after Registration", registration.getId()); 202 this.sendLogsToThingsboard(LOG_LW2M_INFO + ": Client create after Registration", registration.getId());
203 } else { 203 } else {
@@ -286,7 +286,7 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler @@ -286,7 +286,7 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler
286 @Override 286 @Override
287 public void setCancelObservationsAll(Registration registration) { 287 public void setCancelObservationsAll(Registration registration) {
288 if (registration != null) { 288 if (registration != null) {
289 - lwM2mTransportRequest.sendAllRequest(registration, null, OBSERVE_CANCEL_ALL, 289 + this.lwM2mTransportRequest.sendAllRequest(registration, null, OBSERVE_CANCEL_ALL,
290 null, null, this.config.getTimeout(), null); 290 null, null, this.config.getTimeout(), null);
291 } 291 }
292 } 292 }
@@ -335,7 +335,7 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler @@ -335,7 +335,7 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler
335 READ, pathIdVer, value); 335 READ, pathIdVer, value);
336 this.sendLogsToThingsboard(msg, registration.getId()); 336 this.sendLogsToThingsboard(msg, registration.getId());
337 rpcRequest.setValueMsg(String.format("%s", value)); 337 rpcRequest.setValueMsg(String.format("%s", value));
338 - this.sentRpcRequest(rpcRequest, response.getCode().getName(), (String) value, LOG_LW2M_VALUE); 338 + this.sentRpcResponse(rpcRequest, response.getCode().getName(), (String) value, LOG_LW2M_VALUE);
339 } 339 }
340 340
341 /** 341 /**
@@ -362,12 +362,12 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler @@ -362,12 +362,12 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler
362 && (!valueNew.equals(lwM2MClient.getFwUpdate().getCurrentVersion()))) 362 && (!valueNew.equals(lwM2MClient.getFwUpdate().getCurrentVersion())))
363 || (FirmwareUtil.getAttributeKey(FirmwareType.FIRMWARE, FirmwareKey.TITLE).equals(pathName) 363 || (FirmwareUtil.getAttributeKey(FirmwareType.FIRMWARE, FirmwareKey.TITLE).equals(pathName)
364 && (!valueNew.equals(lwM2MClient.getFwUpdate().getCurrentTitle())))) { 364 && (!valueNew.equals(lwM2MClient.getFwUpdate().getCurrentTitle())))) {
365 - this.getInfoFirmwareUpdate(lwM2MClient); 365 + this.getInfoFirmwareUpdate(lwM2MClient, null);
366 } else if ((FirmwareUtil.getAttributeKey(FirmwareType.SOFTWARE, FirmwareKey.VERSION).equals(pathName) 366 } else if ((FirmwareUtil.getAttributeKey(FirmwareType.SOFTWARE, FirmwareKey.VERSION).equals(pathName)
367 && (!valueNew.equals(lwM2MClient.getSwUpdate().getCurrentVersion()))) 367 && (!valueNew.equals(lwM2MClient.getSwUpdate().getCurrentVersion())))
368 || (FirmwareUtil.getAttributeKey(FirmwareType.SOFTWARE, FirmwareKey.TITLE).equals(pathName) 368 || (FirmwareUtil.getAttributeKey(FirmwareType.SOFTWARE, FirmwareKey.TITLE).equals(pathName)
369 && (!valueNew.equals(lwM2MClient.getSwUpdate().getCurrentTitle())))) { 369 && (!valueNew.equals(lwM2MClient.getSwUpdate().getCurrentTitle())))) {
370 - this.getInfoSoftwareUpdate(lwM2MClient); 370 + this.getInfoSoftwareUpdate(lwM2MClient, null);
371 } 371 }
372 if (pathIdVer != null) { 372 if (pathIdVer != null) {
373 ResourceModel resourceModel = lwM2MClient.getResourceModel(pathIdVer, this.config 373 ResourceModel resourceModel = lwM2MClient.getResourceModel(pathIdVer, this.config
@@ -484,7 +484,7 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler @@ -484,7 +484,7 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler
484 rpcSubscriptionsToRemove.forEach(rpcSubscriptions::remove); 484 rpcSubscriptionsToRemove.forEach(rpcSubscriptions::remove);
485 } 485 }
486 486
487 - public void sentRpcRequest(Lwm2mClientRpcRequest rpcRequest, String requestCode, String msg, String typeMsg) { 487 + public void sentRpcResponse(Lwm2mClientRpcRequest rpcRequest, String requestCode, String msg, String typeMsg) {
488 rpcRequest.setResponseCode(requestCode); 488 rpcRequest.setResponseCode(requestCode);
489 if (LOG_LW2M_ERROR.equals(typeMsg)) { 489 if (LOG_LW2M_ERROR.equals(typeMsg)) {
490 rpcRequest.setInfoMsg(null); 490 rpcRequest.setInfoMsg(null);
@@ -507,7 +507,7 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler @@ -507,7 +507,7 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler
507 507
508 @Override 508 @Override
509 public void onToDeviceRpcResponse(TransportProtos.ToDeviceRpcResponseMsg toDeviceResponse, SessionInfoProto sessionInfo) { 509 public void onToDeviceRpcResponse(TransportProtos.ToDeviceRpcResponseMsg toDeviceResponse, SessionInfoProto sessionInfo) {
510 - log.warn ("5) nToDeviceRpcResponse: [{}], sessionUUID: [{}]", toDeviceResponse, new UUID(sessionInfo.getSessionIdMSB(), sessionInfo.getSessionIdLSB())); 510 + log.warn ("5) onToDeviceRpcResponse: [{}], sessionUUID: [{}]", toDeviceResponse, new UUID(sessionInfo.getSessionIdMSB(), sessionInfo.getSessionIdLSB()));
511 transportService.process(sessionInfo, toDeviceResponse, null); 511 transportService.process(sessionInfo, toDeviceResponse, null);
512 } 512 }
513 513
@@ -1358,21 +1358,28 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler @@ -1358,21 +1358,28 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler
1358 } 1358 }
1359 } 1359 }
1360 1360
1361 - public void getInfoFirmwareUpdate(LwM2mClient lwM2MClient) { 1361 + public void getInfoFirmwareUpdate(LwM2mClient lwM2MClient, Lwm2mClientRpcRequest rpcRequest) {
1362 if (lwM2MClient.getRegistration().getSupportedVersion(FW_ID) != null) { 1362 if (lwM2MClient.getRegistration().getSupportedVersion(FW_ID) != null) {
1363 SessionInfoProto sessionInfo = this.getSessionInfoOrCloseSession(lwM2MClient); 1363 SessionInfoProto sessionInfo = this.getSessionInfoOrCloseSession(lwM2MClient);
1364 if (sessionInfo != null) { 1364 if (sessionInfo != null) {
1365 - transportService.process(sessionInfo, createFirmwareRequestMsg(sessionInfo, FirmwareType.FIRMWARE.name()), 1365 + DefaultLwM2MTransportMsgHandler handler = this;
  1366 + this.transportService.process(sessionInfo, createFirmwareRequestMsg(sessionInfo, FirmwareType.FIRMWARE.name()),
1366 new TransportServiceCallback<>() { 1367 new TransportServiceCallback<>() {
1367 @Override 1368 @Override
1368 public void onSuccess(TransportProtos.GetFirmwareResponseMsg response) { 1369 public void onSuccess(TransportProtos.GetFirmwareResponseMsg response) {
1369 if (TransportProtos.ResponseStatus.SUCCESS.equals(response.getResponseStatus()) 1370 if (TransportProtos.ResponseStatus.SUCCESS.equals(response.getResponseStatus())
1370 && response.getType().equals(FirmwareType.FIRMWARE.name())) { 1371 && response.getType().equals(FirmwareType.FIRMWARE.name())) {
1371 - log.warn ("7) firmware start with ver: [{}]",response.getVersion()); 1372 + log.warn ("7) firmware start with ver: [{}]", response.getVersion());
  1373 + lwM2MClient.getFwUpdate().setRpcRequest(rpcRequest);
1372 lwM2MClient.getFwUpdate().setCurrentVersion(response.getVersion()); 1374 lwM2MClient.getFwUpdate().setCurrentVersion(response.getVersion());
1373 lwM2MClient.getFwUpdate().setCurrentTitle(response.getTitle()); 1375 lwM2MClient.getFwUpdate().setCurrentTitle(response.getTitle());
1374 lwM2MClient.getFwUpdate().setCurrentId(new FirmwareId(new UUID(response.getFirmwareIdMSB(), response.getFirmwareIdLSB())).getId()); 1376 lwM2MClient.getFwUpdate().setCurrentId(new FirmwareId(new UUID(response.getFirmwareIdMSB(), response.getFirmwareIdLSB())).getId());
1375 - lwM2MClient.getFwUpdate().sendReadObserveInfo(lwM2mTransportRequest); 1377 + if (rpcRequest == null) {
  1378 + lwM2MClient.getFwUpdate().sendReadObserveInfo(lwM2mTransportRequest);
  1379 + }
  1380 + else {
  1381 + lwM2MClient.getFwUpdate().writeFwSwWare(handler, lwM2mTransportRequest);
  1382 + }
1376 } else { 1383 } else {
1377 log.trace("Firmware [{}] [{}]", lwM2MClient.getDeviceName(), response.getResponseStatus().toString()); 1384 log.trace("Firmware [{}] [{}]", lwM2MClient.getDeviceName(), response.getResponseStatus().toString());
1378 } 1385 }
@@ -1387,21 +1394,28 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler @@ -1387,21 +1394,28 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler
1387 } 1394 }
1388 } 1395 }
1389 1396
1390 - public void getInfoSoftwareUpdate(LwM2mClient lwM2MClient) { 1397 + public void getInfoSoftwareUpdate(LwM2mClient lwM2MClient, Lwm2mClientRpcRequest rpcRequest) {
1391 if (lwM2MClient.getRegistration().getSupportedVersion(SW_ID) != null) { 1398 if (lwM2MClient.getRegistration().getSupportedVersion(SW_ID) != null) {
1392 SessionInfoProto sessionInfo = this.getSessionInfoOrCloseSession(lwM2MClient); 1399 SessionInfoProto sessionInfo = this.getSessionInfoOrCloseSession(lwM2MClient);
1393 if (sessionInfo != null) { 1400 if (sessionInfo != null) {
1394 - DefaultLwM2MTransportMsgHandler serviceImpl = this; 1401 + DefaultLwM2MTransportMsgHandler handler = this;
1395 transportService.process(sessionInfo, createFirmwareRequestMsg(sessionInfo, FirmwareType.SOFTWARE.name()), 1402 transportService.process(sessionInfo, createFirmwareRequestMsg(sessionInfo, FirmwareType.SOFTWARE.name()),
1396 new TransportServiceCallback<>() { 1403 new TransportServiceCallback<>() {
1397 @Override 1404 @Override
1398 public void onSuccess(TransportProtos.GetFirmwareResponseMsg response) { 1405 public void onSuccess(TransportProtos.GetFirmwareResponseMsg response) {
1399 if (TransportProtos.ResponseStatus.SUCCESS.equals(response.getResponseStatus()) 1406 if (TransportProtos.ResponseStatus.SUCCESS.equals(response.getResponseStatus())
1400 && response.getType().equals(FirmwareType.SOFTWARE.name())) { 1407 && response.getType().equals(FirmwareType.SOFTWARE.name())) {
  1408 + lwM2MClient.getSwUpdate().setRpcRequest(rpcRequest);
1401 lwM2MClient.getSwUpdate().setCurrentVersion(response.getVersion()); 1409 lwM2MClient.getSwUpdate().setCurrentVersion(response.getVersion());
1402 lwM2MClient.getSwUpdate().setCurrentTitle(response.getTitle()); 1410 lwM2MClient.getSwUpdate().setCurrentTitle(response.getTitle());
1403 lwM2MClient.getSwUpdate().setCurrentId(new FirmwareId(new UUID(response.getFirmwareIdMSB(), response.getFirmwareIdLSB())).getId()); 1411 lwM2MClient.getSwUpdate().setCurrentId(new FirmwareId(new UUID(response.getFirmwareIdMSB(), response.getFirmwareIdLSB())).getId());
1404 lwM2MClient.getSwUpdate().sendReadObserveInfo(lwM2mTransportRequest); 1412 lwM2MClient.getSwUpdate().sendReadObserveInfo(lwM2mTransportRequest);
  1413 + if (rpcRequest == null) {
  1414 + lwM2MClient.getSwUpdate().sendReadObserveInfo(lwM2mTransportRequest);
  1415 + }
  1416 + else {
  1417 + lwM2MClient.getSwUpdate().writeFwSwWare(handler, lwM2mTransportRequest);
  1418 + }
1405 } else { 1419 } else {
1406 log.trace("Software [{}] [{}]", lwM2MClient.getDeviceName(), response.getResponseStatus().toString()); 1420 log.trace("Software [{}] [{}]", lwM2MClient.getDeviceName(), response.getResponseStatus().toString());
1407 } 1421 }
@@ -82,10 +82,8 @@ import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.L @@ -82,10 +82,8 @@ import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.L
82 import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.LOG_LW2M_VALUE; 82 import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.LOG_LW2M_VALUE;
83 import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.LwM2mTypeOper; 83 import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.LwM2mTypeOper;
84 import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.LwM2mTypeOper.DISCOVER; 84 import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.LwM2mTypeOper.DISCOVER;
85 -import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.LwM2mTypeOper.DISCOVER_ALL;  
86 import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.LwM2mTypeOper.EXECUTE; 85 import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.LwM2mTypeOper.EXECUTE;
87 import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.LwM2mTypeOper.OBSERVE_CANCEL; 86 import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.LwM2mTypeOper.OBSERVE_CANCEL;
88 -import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.LwM2mTypeOper.OBSERVE_CANCEL_ALL;  
89 import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.LwM2mTypeOper.OBSERVE_READ_ALL; 87 import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.LwM2mTypeOper.OBSERVE_READ_ALL;
90 import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.LwM2mTypeOper.WRITE_ATTRIBUTES; 88 import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.LwM2mTypeOper.WRITE_ATTRIBUTES;
91 import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.LwM2mTypeOper.WRITE_REPLACE; 89 import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.LwM2mTypeOper.WRITE_REPLACE;
@@ -134,7 +132,7 @@ public class LwM2mTransportRequest { @@ -134,7 +132,7 @@ public class LwM2mTransportRequest {
134 ContentFormat contentFormat = contentFormatName != null ? ContentFormat.fromName(contentFormatName.toUpperCase()) : ContentFormat.DEFAULT; 132 ContentFormat contentFormat = contentFormatName != null ? ContentFormat.fromName(contentFormatName.toUpperCase()) : ContentFormat.DEFAULT;
135 LwM2mClient lwM2MClient = this.lwM2mClientContext.getOrRegister(registration); 133 LwM2mClient lwM2MClient = this.lwM2mClientContext.getOrRegister(registration);
136 LwM2mPath resultIds = target != null ? new LwM2mPath(target) : null; 134 LwM2mPath resultIds = target != null ? new LwM2mPath(target) : null;
137 - if (!OBSERVE_READ_ALL.name().equals(typeOper.name()) && resultIds != null && registration != null && resultIds.getObjectId() >= 0 && lwM2MClient != null) { 135 + if (!OBSERVE_CANCEL.name().equals(typeOper.name()) && resultIds != null && registration != null && resultIds.getObjectId() >= 0 && lwM2MClient != null) {
138 if (lwM2MClient.isValidObjectVersion(targetIdVer)) { 136 if (lwM2MClient.isValidObjectVersion(targetIdVer)) {
139 timeoutInMs = timeoutInMs > 0 ? timeoutInMs : DEFAULT_TIMEOUT; 137 timeoutInMs = timeoutInMs > 0 ? timeoutInMs : DEFAULT_TIMEOUT;
140 DownlinkRequest request = createRequest(registration, lwM2MClient, typeOper, contentFormat, target, 138 DownlinkRequest request = createRequest(registration, lwM2MClient, typeOper, contentFormat, target,
@@ -153,47 +151,66 @@ public class LwM2mTransportRequest { @@ -153,47 +151,66 @@ public class LwM2mTransportRequest {
153 } else if (WRITE_UPDATE.name().equals(typeOper.name())) { 151 } else if (WRITE_UPDATE.name().equals(typeOper.name())) {
154 if (lwm2mClientRpcRequest != null) { 152 if (lwm2mClientRpcRequest != null) {
155 String errorMsg = String.format("Path %s params is not valid", targetIdVer); 153 String errorMsg = String.format("Path %s params is not valid", targetIdVer);
156 - handler.sentRpcRequest(lwm2mClientRpcRequest, BAD_REQUEST.getName(), errorMsg, LOG_LW2M_ERROR); 154 + handler.sentRpcResponse(lwm2mClientRpcRequest, BAD_REQUEST.getName(), errorMsg, LOG_LW2M_ERROR);
157 } 155 }
158 } else if (WRITE_REPLACE.name().equals(typeOper.name()) || EXECUTE.name().equals(typeOper.name())) { 156 } else if (WRITE_REPLACE.name().equals(typeOper.name()) || EXECUTE.name().equals(typeOper.name())) {
159 if (lwm2mClientRpcRequest != null) { 157 if (lwm2mClientRpcRequest != null) {
160 String errorMsg = String.format("Path %s object model is absent", targetIdVer); 158 String errorMsg = String.format("Path %s object model is absent", targetIdVer);
161 - handler.sentRpcRequest(lwm2mClientRpcRequest, BAD_REQUEST.getName(), errorMsg, LOG_LW2M_ERROR); 159 + handler.sentRpcResponse(lwm2mClientRpcRequest, BAD_REQUEST.getName(), errorMsg, LOG_LW2M_ERROR);
162 } 160 }
163 } else if (!OBSERVE_CANCEL.name().equals(typeOper.name())) { 161 } else if (!OBSERVE_CANCEL.name().equals(typeOper.name())) {
164 log.error("[{}], [{}] - [{}] error SendRequest", registration.getEndpoint(), typeOper.name(), targetIdVer); 162 log.error("[{}], [{}] - [{}] error SendRequest", registration.getEndpoint(), typeOper.name(), targetIdVer);
165 if (lwm2mClientRpcRequest != null) { 163 if (lwm2mClientRpcRequest != null) {
166 ResourceModel resourceModel = lwM2MClient.getResourceModel(targetIdVer, this.config.getModelProvider()); 164 ResourceModel resourceModel = lwM2MClient.getResourceModel(targetIdVer, this.config.getModelProvider());
167 String errorMsg = resourceModel == null ? String.format("Path %s not found in object version", targetIdVer) : "SendRequest - null"; 165 String errorMsg = resourceModel == null ? String.format("Path %s not found in object version", targetIdVer) : "SendRequest - null";
168 - this.handler.sentRpcRequest(lwm2mClientRpcRequest, NOT_FOUND.getName(), errorMsg, LOG_LW2M_ERROR); 166 + this.handler.sentRpcResponse(lwm2mClientRpcRequest, NOT_FOUND.getName(), errorMsg, LOG_LW2M_ERROR);
169 } 167 }
170 } 168 }
171 } else if (lwm2mClientRpcRequest != null) { 169 } else if (lwm2mClientRpcRequest != null) {
172 String errorMsg = String.format("Path %s not found in object version", targetIdVer); 170 String errorMsg = String.format("Path %s not found in object version", targetIdVer);
173 - this.handler.sentRpcRequest(lwm2mClientRpcRequest, NOT_FOUND.getName(), errorMsg, LOG_LW2M_ERROR); 171 + this.handler.sentRpcResponse(lwm2mClientRpcRequest, NOT_FOUND.getName(), errorMsg, LOG_LW2M_ERROR);
174 } 172 }
175 - } else if (OBSERVE_READ_ALL.name().equals(typeOper.name()) || DISCOVER_ALL.name().equals(typeOper.name())) {  
176 - Set<String> paths;  
177 - if (OBSERVE_READ_ALL.name().equals(typeOper.name())) {  
178 - Set<Observation> observations = context.getServer().getObservationService().getObservations(registration);  
179 - paths = observations.stream().map(observation -> observation.getPath().toString()).collect(Collectors.toUnmodifiableSet());  
180 - } else {  
181 - assert registration != null;  
182 - Link[] objectLinks = registration.getSortedObjectLinks();  
183 - paths = Arrays.stream(objectLinks).map(Link::toString).collect(Collectors.toUnmodifiableSet());  
184 - }  
185 - String msg = String.format("%s: type operation %s paths - %s", LOG_LW2M_INFO,  
186 - typeOper.name(), paths);  
187 - this.handler.sendLogsToThingsboard(msg, registration.getId());  
188 - if (lwm2mClientRpcRequest != null) {  
189 - String valueMsg = String.format("Paths - %s", paths);  
190 - this.handler.sentRpcRequest(lwm2mClientRpcRequest, CONTENT.name(), valueMsg, LOG_LW2M_VALUE); 173 + } else {
  174 + switch (typeOper) {
  175 + case OBSERVE_READ_ALL:
  176 + case DISCOVER_ALL:
  177 + Set<String> paths;
  178 + if (OBSERVE_READ_ALL.name().equals(typeOper.name())) {
  179 + Set<Observation> observations = context.getServer().getObservationService().getObservations(registration);
  180 + paths = observations.stream().map(observation -> observation.getPath().toString()).collect(Collectors.toUnmodifiableSet());
  181 + } else {
  182 + assert registration != null;
  183 + Link[] objectLinks = registration.getSortedObjectLinks();
  184 + paths = Arrays.stream(objectLinks).map(Link::toString).collect(Collectors.toUnmodifiableSet());
  185 + }
  186 + String msg = String.format("%s: type operation %s paths - %s", LOG_LW2M_INFO,
  187 + typeOper.name(), paths);
  188 + this.handler.sendLogsToThingsboard(msg, registration.getId());
  189 + if (lwm2mClientRpcRequest != null) {
  190 + String valueMsg = String.format("Paths - %s", paths);
  191 + this.handler.sentRpcResponse(lwm2mClientRpcRequest, CONTENT.name(), valueMsg, LOG_LW2M_VALUE);
  192 + }
  193 + break;
  194 + case OBSERVE_CANCEL:
  195 + case OBSERVE_CANCEL_ALL:
  196 + int observeCancelCnt = 0;
  197 + String observeCancelMsg = null;
  198 + if (OBSERVE_CANCEL.name().equals(typeOper)) {
  199 + observeCancelCnt = context.getServer().getObservationService().cancelObservations(registration, target);
  200 + observeCancelMsg = String.format("%s: type operation %s paths: %s count: %d", LOG_LW2M_INFO,
  201 + OBSERVE_CANCEL.name(), target, observeCancelCnt);
  202 + } else {
  203 + observeCancelCnt = context.getServer().getObservationService().cancelObservations(registration);
  204 + observeCancelMsg = String.format("%s: type operation %s paths: All count: %d", LOG_LW2M_INFO,
  205 + OBSERVE_CANCEL.name(), observeCancelCnt);
  206 + }
  207 + this.afterObserveCancel(registration, observeCancelCnt, observeCancelMsg, lwm2mClientRpcRequest);
  208 + break;
  209 + // lwm2mClientRpcRequest != null
  210 + case FW_UPDATE:
  211 + this.handler.getInfoFirmwareUpdate(lwM2MClient, lwm2mClientRpcRequest);
  212 + break;
191 } 213 }
192 - } else if (OBSERVE_CANCEL_ALL.name().equals(typeOper.name())) {  
193 - int observeCancelCnt = context.getServer().getObservationService().cancelObservations(registration);  
194 - String observeCancelMsgAll = String.format("%s: type operation %s paths: All count: %d", LOG_LW2M_INFO,  
195 - OBSERVE_CANCEL.name(), observeCancelCnt);  
196 - this.afterObserveCancel(registration, observeCancelCnt, observeCancelMsgAll, lwm2mClientRpcRequest);  
197 } 214 }
198 } catch (Exception e) { 215 } catch (Exception e) {
199 String msg = String.format("%s: type operation %s %s", LOG_LW2M_ERROR, 216 String msg = String.format("%s: type operation %s %s", LOG_LW2M_ERROR,
@@ -201,7 +218,7 @@ public class LwM2mTransportRequest { @@ -201,7 +218,7 @@ public class LwM2mTransportRequest {
201 handler.sendLogsToThingsboard(msg, registration.getId()); 218 handler.sendLogsToThingsboard(msg, registration.getId());
202 if (lwm2mClientRpcRequest != null) { 219 if (lwm2mClientRpcRequest != null) {
203 String errorMsg = String.format("Path %s type operation %s %s", targetIdVer, typeOper.name(), e.getMessage()); 220 String errorMsg = String.format("Path %s type operation %s %s", targetIdVer, typeOper.name(), e.getMessage());
204 - handler.sentRpcRequest(lwm2mClientRpcRequest, NOT_FOUND.getName(), errorMsg, LOG_LW2M_ERROR); 221 + handler.sentRpcResponse(lwm2mClientRpcRequest, NOT_FOUND.getName(), errorMsg, LOG_LW2M_ERROR);
205 } 222 }
206 } 223 }
207 } 224 }
@@ -234,17 +251,6 @@ public class LwM2mTransportRequest { @@ -234,17 +251,6 @@ public class LwM2mTransportRequest {
234 request = new ObserveRequest(contentFormat, resultIds.getObjectId()); 251 request = new ObserveRequest(contentFormat, resultIds.getObjectId());
235 } 252 }
236 break; 253 break;
237 - case OBSERVE_CANCEL:  
238 - /*  
239 - lwM2MTransportRequest.sendAllRequest(lwServer, registration, path, POST_TYPE_OPER_OBSERVE_CANCEL, null, null, null, null, context.getTimeout());  
240 - At server side this will not remove the observation from the observation store, to do it you need to use  
241 - {@code ObservationService#cancelObservation()}  
242 - */  
243 - int observeCancelCnt = context.getServer().getObservationService().cancelObservations(registration, target);  
244 - String observeCancelMsg = String.format("%s: type operation %s paths: %s count: %d", LOG_LW2M_INFO,  
245 - OBSERVE_CANCEL.name(), target, observeCancelCnt);  
246 - this.afterObserveCancel(registration, observeCancelCnt, observeCancelMsg, rpcRequest);  
247 - break;  
248 case EXECUTE: 254 case EXECUTE:
249 ResourceModel resourceModelExecute = lwM2MClient.getResourceModel(targetIdVer, this.config.getModelProvider()); 255 ResourceModel resourceModelExecute = lwM2MClient.getResourceModel(targetIdVer, this.config.getModelProvider());
250 if (resourceModelExecute != null) { 256 if (resourceModelExecute != null) {
@@ -343,7 +349,7 @@ public class LwM2mTransportRequest { @@ -343,7 +349,7 @@ public class LwM2mTransportRequest {
343 } 349 }
344 /** Not Found */ 350 /** Not Found */
345 if (rpcRequest != null) { 351 if (rpcRequest != null) {
346 - handler.sentRpcRequest(rpcRequest, response.getCode().getName(), response.getErrorMessage(), LOG_LW2M_ERROR); 352 + handler.sentRpcResponse(rpcRequest, response.getCode().getName(), response.getErrorMessage(), LOG_LW2M_ERROR);
347 } 353 }
348 /** Not Found 354 /** Not Found
349 set setClient_fw_info... = empty 355 set setClient_fw_info... = empty
@@ -385,7 +391,7 @@ public class LwM2mTransportRequest { @@ -385,7 +391,7 @@ public class LwM2mTransportRequest {
385 handler.sendLogsToThingsboard(msg, registration.getId()); 391 handler.sendLogsToThingsboard(msg, registration.getId());
386 log.error("[{}] [{}] - [{}] error SendRequest", request.getClass().getName().toString(), request.getPath().toString(), e.toString()); 392 log.error("[{}] [{}] - [{}] error SendRequest", request.getClass().getName().toString(), request.getPath().toString(), e.toString());
387 if (rpcRequest != null) { 393 if (rpcRequest != null) {
388 - handler.sentRpcRequest(rpcRequest, CoAP.CodeClass.ERROR_RESPONSE.name(), e.getMessage(), LOG_LW2M_ERROR); 394 + handler.sentRpcResponse(rpcRequest, CoAP.CodeClass.ERROR_RESPONSE.name(), e.getMessage(), LOG_LW2M_ERROR);
389 } 395 }
390 }); 396 });
391 } 397 }
@@ -431,7 +437,7 @@ public class LwM2mTransportRequest { @@ -431,7 +437,7 @@ public class LwM2mTransportRequest {
431 log.error("Path: [{}] type: [{}] value: [{}] errorMsg: [{}]]", patn, type, value, e.toString()); 437 log.error("Path: [{}] type: [{}] value: [{}] errorMsg: [{}]]", patn, type, value, e.toString());
432 if (rpcRequest != null) { 438 if (rpcRequest != null) {
433 String errorMsg = String.format("NumberFormatException: Resource path - %s type - %s value - %s", patn, type, value); 439 String errorMsg = String.format("NumberFormatException: Resource path - %s type - %s value - %s", patn, type, value);
434 - handler.sentRpcRequest(rpcRequest, BAD_REQUEST.getName(), errorMsg, LOG_LW2M_ERROR); 440 + handler.sentRpcResponse(rpcRequest, BAD_REQUEST.getName(), errorMsg, LOG_LW2M_ERROR);
435 } 441 }
436 return null; 442 return null;
437 } 443 }
@@ -462,44 +468,48 @@ public class LwM2mTransportRequest { @@ -462,44 +468,48 @@ public class LwM2mTransportRequest {
462 if (response instanceof ReadResponse) { 468 if (response instanceof ReadResponse) {
463 handler.onUpdateValueAfterReadResponse(registration, pathIdVer, (ReadResponse) response, rpcRequest); 469 handler.onUpdateValueAfterReadResponse(registration, pathIdVer, (ReadResponse) response, rpcRequest);
464 } else if (response instanceof DeleteResponse) { 470 } else if (response instanceof DeleteResponse) {
465 - log.warn("[{}] Path [{}] DeleteResponse 5_Send", pathIdVer, response); 471 + log.warn("11) [{}] Path [{}] DeleteResponse", pathIdVer, response);
  472 + if (rpcRequest != null) {
  473 + rpcRequest.setInfoMsg(null);
  474 + handler.sentRpcResponse(rpcRequest, response.getCode().getName(), null, null);
  475 + }
466 } else if (response instanceof DiscoverResponse) { 476 } else if (response instanceof DiscoverResponse) {
467 - String discoverValue = Link.serialize(((DiscoverResponse)response).getObjectLinks()); 477 + String discoverValue = Link.serialize(((DiscoverResponse) response).getObjectLinks());
468 msgLog = String.format("%s: type operation: %s path: %s value: %s", 478 msgLog = String.format("%s: type operation: %s path: %s value: %s",
469 LOG_LW2M_INFO, DISCOVER.name(), request.getPath().toString(), discoverValue); 479 LOG_LW2M_INFO, DISCOVER.name(), request.getPath().toString(), discoverValue);
470 handler.sendLogsToThingsboard(msgLog, registration.getId()); 480 handler.sendLogsToThingsboard(msgLog, registration.getId());
471 log.warn("DiscoverResponse: [{}]", (DiscoverResponse) response); 481 log.warn("DiscoverResponse: [{}]", (DiscoverResponse) response);
472 if (rpcRequest != null) { 482 if (rpcRequest != null) {
473 - handler.sentRpcRequest(rpcRequest, response.getCode().getName(), discoverValue, LOG_LW2M_VALUE); 483 + handler.sentRpcResponse(rpcRequest, response.getCode().getName(), discoverValue, LOG_LW2M_VALUE);
474 } 484 }
475 } else if (response instanceof ExecuteResponse) { 485 } else if (response instanceof ExecuteResponse) {
476 - log.warn("[{}] Path [{}] ExecuteResponse 7_Send", pathIdVer, response); 486 + msgLog = String.format("%s: type operation: %s path: %s",
  487 + LOG_LW2M_INFO, EXECUTE.name(), request.getPath().toString());
  488 + log.warn("9) [{}] ", msgLog);
  489 + handler.sendLogsToThingsboard(msgLog, registration.getId());
  490 + if (rpcRequest != null) {
  491 + msgLog = String.format("Start %s path: %S. Preparation finished: %s", EXECUTE.name(), path, rpcRequest.getInfoMsg());
  492 + rpcRequest.setInfoMsg(msgLog);
  493 + handler.sentRpcResponse(rpcRequest, response.getCode().getName(), path, LOG_LW2M_INFO);
  494 + }
  495 +
477 } else if (response instanceof WriteAttributesResponse) { 496 } else if (response instanceof WriteAttributesResponse) {
478 msgLog = String.format("%s: type operation: %s path: %s value: %s", 497 msgLog = String.format("%s: type operation: %s path: %s value: %s",
479 LOG_LW2M_INFO, WRITE_ATTRIBUTES.name(), request.getPath().toString(), ((WriteAttributesRequest) request).getAttributes().toString()); 498 LOG_LW2M_INFO, WRITE_ATTRIBUTES.name(), request.getPath().toString(), ((WriteAttributesRequest) request).getAttributes().toString());
480 handler.sendLogsToThingsboard(msgLog, registration.getId()); 499 handler.sendLogsToThingsboard(msgLog, registration.getId());
481 - log.warn("[{}] Path [{}] WriteAttributesResponse 8_Send", pathIdVer, response); 500 + log.warn("12) [{}] Path [{}] WriteAttributesResponse", pathIdVer, response);
482 if (rpcRequest != null) { 501 if (rpcRequest != null) {
483 - handler.sentRpcRequest(rpcRequest, response.getCode().getName(), response.toString(), LOG_LW2M_VALUE); 502 + handler.sentRpcResponse(rpcRequest, response.getCode().getName(), response.toString(), LOG_LW2M_VALUE);
484 } 503 }
485 } else if (response instanceof WriteResponse) { 504 } else if (response instanceof WriteResponse) {
486 - log.warn("[{}] Path [{}] WriteResponse 9_Send", pathIdVer, response);  
487 - this.infoWriteResponse(registration, response, request); 505 + msgLog = String.format("Type operation: Write path: %s", pathIdVer);
  506 + log.warn("10) [{}] response: [{}]", msgLog, response);
  507 + this.infoWriteResponse(registration, response, request, rpcRequest);
488 handler.onWriteResponseOk(registration, pathIdVer, (WriteRequest) request); 508 handler.onWriteResponseOk(registration, pathIdVer, (WriteRequest) request);
489 } 509 }
490 - if (rpcRequest != null) {  
491 - if (response instanceof ExecuteResponse  
492 - || response instanceof WriteAttributesResponse  
493 - || response instanceof DeleteResponse) {  
494 - rpcRequest.setInfoMsg(null);  
495 - handler.sentRpcRequest(rpcRequest, response.getCode().getName(), null, null);  
496 - } else if (response instanceof WriteResponse) {  
497 - handler.sentRpcRequest(rpcRequest, response.getCode().getName(), null, LOG_LW2M_INFO);  
498 - }  
499 - }  
500 } 510 }
501 511
502 - private void infoWriteResponse(Registration registration, LwM2mResponse response, DownlinkRequest request) { 512 + private void infoWriteResponse(Registration registration, LwM2mResponse response, DownlinkRequest request, Lwm2mClientRpcRequest rpcRequest) {
503 try { 513 try {
504 LwM2mNode node = ((WriteRequest) request).getNode(); 514 LwM2mNode node = ((WriteRequest) request).getNode();
505 String msg = null; 515 String msg = null;
@@ -517,12 +527,12 @@ public class LwM2mTransportRequest { @@ -517,12 +527,12 @@ public class LwM2mTransportRequest {
517 if (singleResource.getType() == ResourceModel.Type.STRING) { 527 if (singleResource.getType() == ResourceModel.Type.STRING) {
518 valueLength = ((String) singleResource.getValue()).length(); 528 valueLength = ((String) singleResource.getValue()).length();
519 value = ((String) singleResource.getValue()) 529 value = ((String) singleResource.getValue())
520 - .substring(Math.min(valueLength, config.getLogMaxLength())); 530 + .substring(Math.min(valueLength, config.getLogMaxLength())).trim();
521 531
522 } else { 532 } else {
523 valueLength = ((byte[]) singleResource.getValue()).length; 533 valueLength = ((byte[]) singleResource.getValue()).length;
524 value = new String(Arrays.copyOf(((byte[]) singleResource.getValue()), 534 value = new String(Arrays.copyOf(((byte[]) singleResource.getValue()),
525 - Math.min(valueLength, config.getLogMaxLength()))); 535 + Math.min(valueLength, config.getLogMaxLength()))).trim();
526 } 536 }
527 value = valueLength > config.getLogMaxLength() ? value + "..." : value; 537 value = valueLength > config.getLogMaxLength() ? value + "..." : value;
528 msg = String.format("%s: Update finished successfully: Lwm2m code - %d Resource path: %s length: %s value: %s", 538 msg = String.format("%s: Update finished successfully: Lwm2m code - %d Resource path: %s length: %s value: %s",
@@ -538,6 +548,12 @@ public class LwM2mTransportRequest { @@ -538,6 +548,12 @@ public class LwM2mTransportRequest {
538 handler.sendLogsToThingsboard(msg, registration.getId()); 548 handler.sendLogsToThingsboard(msg, registration.getId());
539 if (request.getPath().toString().equals(FW_PACKAGE_ID) || request.getPath().toString().equals(SW_PACKAGE_ID)) { 549 if (request.getPath().toString().equals(FW_PACKAGE_ID) || request.getPath().toString().equals(SW_PACKAGE_ID)) {
540 this.afterWriteSuccessFwSwUpdate(registration, request); 550 this.afterWriteSuccessFwSwUpdate(registration, request);
  551 + if (rpcRequest != null) {
  552 + rpcRequest.setInfoMsg(msg);
  553 + }
  554 + }
  555 + else if (rpcRequest != null) {
  556 + handler.sentRpcResponse(rpcRequest, response.getCode().getName(), msg, LOG_LW2M_INFO);
541 } 557 }
542 } 558 }
543 } catch (Exception e) { 559 } catch (Exception e) {
@@ -558,7 +574,7 @@ public class LwM2mTransportRequest { @@ -558,7 +574,7 @@ public class LwM2mTransportRequest {
558 } 574 }
559 if (request.getPath().toString().equals(SW_PACKAGE_ID) && lwM2MClient.getSwUpdate() != null) { 575 if (request.getPath().toString().equals(SW_PACKAGE_ID) && lwM2MClient.getSwUpdate() != null) {
560 lwM2MClient.getSwUpdate().setStateUpdate(DOWNLOADED.name()); 576 lwM2MClient.getSwUpdate().setStateUpdate(DOWNLOADED.name());
561 - lwM2MClient.getSwUpdate().sendLogs(this.handler,WRITE_REPLACE.name(), LOG_LW2M_INFO, null); 577 + lwM2MClient.getSwUpdate().sendLogs(this.handler, WRITE_REPLACE.name(), LOG_LW2M_INFO, null);
562 } 578 }
563 } 579 }
564 580
@@ -592,7 +608,7 @@ public class LwM2mTransportRequest { @@ -592,7 +608,7 @@ public class LwM2mTransportRequest {
592 log.warn("[{}]", observeCancelMsg); 608 log.warn("[{}]", observeCancelMsg);
593 if (rpcRequest != null) { 609 if (rpcRequest != null) {
594 rpcRequest.setInfoMsg(String.format("Count: %d", observeCancelCnt)); 610 rpcRequest.setInfoMsg(String.format("Count: %d", observeCancelCnt));
595 - handler.sentRpcRequest(rpcRequest, CONTENT.name(), null, LOG_LW2M_INFO); 611 + handler.sentRpcResponse(rpcRequest, CONTENT.name(), null, LOG_LW2M_INFO);
596 } 612 }
597 } 613 }
598 } 614 }
@@ -229,11 +229,12 @@ public class LwM2mTransportUtil { @@ -229,11 +229,12 @@ public class LwM2mTransportUtil {
229 */ 229 */
230 WRITE_UPDATE(9, "WriteUpdate"), 230 WRITE_UPDATE(9, "WriteUpdate"),
231 WRITE_ATTRIBUTES(10, "WriteAttributes"), 231 WRITE_ATTRIBUTES(10, "WriteAttributes"),
232 - DELETE(11, "Delete"); 232 + DELETE(11, "Delete"),
233 233
234 // only for RPC 234 // only for RPC
  235 + FW_UPDATE(12,"FirmwareUpdate");
235 // FW_READ_INFO(12, "FirmwareReadInfo"), 236 // FW_READ_INFO(12, "FirmwareReadInfo"),
236 -// FW_UPDATE(13, "FirmwareUpdate"), 237 +
237 // SW_READ_INFO(15, "SoftwareReadInfo"), 238 // SW_READ_INFO(15, "SoftwareReadInfo"),
238 // SW_UPDATE(16, "SoftwareUpdate"), 239 // SW_UPDATE(16, "SoftwareUpdate"),
239 // SW_UNINSTALL(18, "SoftwareUninstall"); 240 // SW_UNINSTALL(18, "SoftwareUninstall");
@@ -32,6 +32,7 @@ import java.util.List; @@ -32,6 +32,7 @@ import java.util.List;
32 import java.util.UUID; 32 import java.util.UUID;
33 import java.util.concurrent.CopyOnWriteArrayList; 33 import java.util.concurrent.CopyOnWriteArrayList;
34 34
  35 +import static org.eclipse.californium.core.coap.CoAP.ResponseCode.CONTENT;
35 import static org.thingsboard.server.common.data.firmware.FirmwareKey.STATE; 36 import static org.thingsboard.server.common.data.firmware.FirmwareKey.STATE;
36 import static org.thingsboard.server.common.data.firmware.FirmwareType.FIRMWARE; 37 import static org.thingsboard.server.common.data.firmware.FirmwareType.FIRMWARE;
37 import static org.thingsboard.server.common.data.firmware.FirmwareType.SOFTWARE; 38 import static org.thingsboard.server.common.data.firmware.FirmwareType.SOFTWARE;
@@ -103,6 +104,9 @@ public class LwM2mFwSwUpdate { @@ -103,6 +104,9 @@ public class LwM2mFwSwUpdate {
103 @Getter 104 @Getter
104 @Setter 105 @Setter
105 private final List<String> pendingInfoRequestsStart; 106 private final List<String> pendingInfoRequestsStart;
  107 + @Getter
  108 + @Setter
  109 + private volatile Lwm2mClientRpcRequest rpcRequest;
106 110
107 public LwM2mFwSwUpdate(LwM2mClient lwM2MClient, FirmwareType type) { 111 public LwM2mFwSwUpdate(LwM2mClient lwM2MClient, FirmwareType type) {
108 this.lwM2MClient = lwM2MClient; 112 this.lwM2MClient = lwM2MClient;
@@ -153,17 +157,30 @@ public class LwM2mFwSwUpdate { @@ -153,17 +157,30 @@ public class LwM2mFwSwUpdate {
153 * Send FsSw to Lwm2mClient: 157 * Send FsSw to Lwm2mClient:
154 * before operation Write: fw_state = DOWNLOADING 158 * before operation Write: fw_state = DOWNLOADING
155 */ 159 */
156 - private void writeFwSwWare(DefaultLwM2MTransportMsgHandler handler, LwM2mTransportRequest request) {  
157 - this.stateUpdate = FirmwareUpdateStatus.DOWNLOADING.name();  
158 -  
159 - this.sendLogs(handler, WRITE_REPLACE.name(), LOG_LW2M_INFO, null);  
160 - int chunkSize = 0;  
161 - int chunk = 0;  
162 - byte[] firmwareChunk = handler.firmwareDataCache.get(this.currentId.toString(), chunkSize, chunk);  
163 - String targetIdVer = convertPathFromObjectIdToIdVer(this.pathPackageId, this.lwM2MClient.getRegistration());  
164 - log.warn ("8) firmware send save to : [{}]", targetIdVer);  
165 - request.sendAllRequest(lwM2MClient.getRegistration(), targetIdVer, WRITE_REPLACE, ContentFormat.OPAQUE.getName(),  
166 - firmwareChunk, handler.config.getTimeout(), null); 160 + public void writeFwSwWare(DefaultLwM2MTransportMsgHandler handler, LwM2mTransportRequest request) {
  161 + if (this.currentId != null) {
  162 + this.stateUpdate = FirmwareUpdateStatus.DOWNLOADING.name();
  163 + this.sendLogs(handler, WRITE_REPLACE.name(), LOG_LW2M_INFO, null);
  164 + int chunkSize = 0;
  165 + int chunk = 0;
  166 + byte[] firmwareChunk = handler.firmwareDataCache.get(this.currentId.toString(), chunkSize, chunk);
  167 + String targetIdVer = convertPathFromObjectIdToIdVer(this.pathPackageId, this.lwM2MClient.getRegistration());
  168 + String fwMsg = String.format("%s: Start type operation %s paths: %s", LOG_LW2M_INFO,
  169 + LwM2mTransportUtil.LwM2mTypeOper.FW_UPDATE.name(), FW_PACKAGE_ID);
  170 + handler.sendLogsToThingsboard(fwMsg, lwM2MClient.getRegistration().getId());
  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(),
  173 + firmwareChunk, handler.config.getTimeout(), this.rpcRequest);
  174 + }
  175 + else {
  176 + String msgError = "FirmWareId is null.";
  177 + log.warn("6) [{}]", msgError);
  178 + if (this.rpcRequest != null) {
  179 + handler.sentRpcResponse(this.rpcRequest, CONTENT.name(), msgError, LOG_LW2M_ERROR);
  180 + }
  181 + log.error (msgError);
  182 + this.sendLogs(handler, WRITE_REPLACE.name(), LOG_LW2M_ERROR, msgError);
  183 + }
167 } 184 }
168 185
169 public void sendLogs(DefaultLwM2MTransportMsgHandler handler, String typeOper, String typeInfo, String msgError) { 186 public void sendLogs(DefaultLwM2MTransportMsgHandler handler, String typeOper, String typeInfo, String msgError) {
@@ -186,7 +203,7 @@ public class LwM2mFwSwUpdate { @@ -186,7 +203,7 @@ public class LwM2mFwSwUpdate {
186 this.setStateUpdate(UPDATING.name()); 203 this.setStateUpdate(UPDATING.name());
187 this.sendLogs(handler, EXECUTE.name(), LOG_LW2M_INFO, null); 204 this.sendLogs(handler, EXECUTE.name(), LOG_LW2M_INFO, null);
188 request.sendAllRequest(this.lwM2MClient.getRegistration(), this.pathInstallId, EXECUTE, ContentFormat.TLV.getName(), 205 request.sendAllRequest(this.lwM2MClient.getRegistration(), this.pathInstallId, EXECUTE, ContentFormat.TLV.getName(),
189 - null, 0, null); 206 + null, 0, this.rpcRequest);
190 } 207 }
191 208
192 /** 209 /**
@@ -348,7 +365,7 @@ public class LwM2mFwSwUpdate { @@ -348,7 +365,7 @@ public class LwM2mFwSwUpdate {
348 this.pathResultId, this.lwM2MClient.getRegistration())); 365 this.pathResultId, this.lwM2MClient.getRegistration()));
349 this.pendingInfoRequestsStart.forEach(pathIdVer -> { 366 this.pendingInfoRequestsStart.forEach(pathIdVer -> {
350 request.sendAllRequest(this.lwM2MClient.getRegistration(), pathIdVer, OBSERVE, ContentFormat.TLV.getName(), 367 request.sendAllRequest(this.lwM2MClient.getRegistration(), pathIdVer, OBSERVE, ContentFormat.TLV.getName(),
351 - null, 0, null); 368 + null, 0, this.rpcRequest);
352 }); 369 });
353 370
354 } 371 }
@@ -39,6 +39,7 @@ import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.K @@ -39,6 +39,7 @@ import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.K
39 import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.LwM2mTypeOper; 39 import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.LwM2mTypeOper;
40 import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.LwM2mTypeOper.DISCOVER_ALL; 40 import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.LwM2mTypeOper.DISCOVER_ALL;
41 import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.LwM2mTypeOper.EXECUTE; 41 import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.LwM2mTypeOper.EXECUTE;
  42 +import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.LwM2mTypeOper.FW_UPDATE;
42 import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.LwM2mTypeOper.OBSERVE_CANCEL; 43 import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.LwM2mTypeOper.OBSERVE_CANCEL;
43 import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.LwM2mTypeOper.OBSERVE_READ_ALL; 44 import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.LwM2mTypeOper.OBSERVE_READ_ALL;
44 import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.LwM2mTypeOper.WRITE_ATTRIBUTES; 45 import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.LwM2mTypeOper.WRITE_ATTRIBUTES;
@@ -140,7 +141,8 @@ public class Lwm2mClientRpcRequest { @@ -140,7 +141,8 @@ public class Lwm2mClientRpcRequest {
140 if (this.getTargetIdVer() == null 141 if (this.getTargetIdVer() == null
141 && !(OBSERVE_READ_ALL == this.getTypeOper() 142 && !(OBSERVE_READ_ALL == this.getTypeOper()
142 || DISCOVER_ALL == this.getTypeOper() 143 || DISCOVER_ALL == this.getTypeOper()
143 - || OBSERVE_CANCEL == this.getTypeOper())) { 144 + || OBSERVE_CANCEL == this.getTypeOper()
  145 + || FW_UPDATE == this.getTypeOper())) {
144 this.setErrorMsg(TARGET_ID_VER_KEY + " and " + 146 this.setErrorMsg(TARGET_ID_VER_KEY + " and " +
145 KEY_NAME_KEY + " is null or bad format"); 147 KEY_NAME_KEY + " is null or bad format");
146 } 148 }