Commit eb9b0f8433235f2ef675ab22e47d4563cc0d853c

Authored by Andrii Shvaika
1 parent 7ec69234

Implementation of software management

Showing 16 changed files with 480 additions and 186 deletions
... ... @@ -26,7 +26,6 @@
26 26 </appender>
27 27
28 28 <logger name="org.thingsboard.server" level="INFO" />
29   - <logger name="org.thingsboard.server.transport.snmp" level="DEBUG" />
30 29
31 30 <!-- <logger name="org.thingsboard.server.service.queue" level="TRACE" />-->
32 31 <!-- <logger name="org.thingsboard.server.service.transport" level="TRACE" />-->
... ...
... ... @@ -62,7 +62,7 @@ public class TbLwM2MAuthorizer implements Authorizer {
62 62 try {
63 63 expectedSecurityInfo = securityStore.getByEndpoint(registration.getEndpoint());
64 64 } catch (LwM2MAuthException e) {
65   - log.warn("Registration failed: FORBIDDEN, endpointId: [{}]", registration.getEndpoint());
  65 + log.info("Registration failed: FORBIDDEN, endpointId: [{}]", registration.getEndpoint());
66 66 return null;
67 67 }
68 68 }
... ...
... ... @@ -26,6 +26,7 @@ import org.eclipse.californium.core.server.resources.Resource;
26 26 import org.eclipse.californium.core.server.resources.ResourceObserver;
27 27 import org.thingsboard.server.cache.ota.OtaPackageDataCache;
28 28
  29 +import java.util.List;
29 30 import java.util.UUID;
30 31 import java.util.concurrent.ConcurrentHashMap;
31 32 import java.util.concurrent.ConcurrentMap;
... ... @@ -69,17 +70,18 @@ public class LwM2mTransportCoapResource extends AbstractLwM2mTransportResource {
69 70
70 71 @Override
71 72 protected void processHandleGet(CoapExchange exchange) {
72   - log.warn("90) processHandleGet [{}]", exchange);
73   - if (exchange.getRequestOptions().getUriPath().size() >= 2 &&
74   - (FIRMWARE_UPDATE_COAP_RESOURCE.equals(exchange.getRequestOptions().getUriPath().get(exchange.getRequestOptions().getUriPath().size() - 2)) ||
75   - SOFTWARE_UPDATE_COAP_RESOURCE.equals(exchange.getRequestOptions().getUriPath().get(exchange.getRequestOptions().getUriPath().size() - 2)))) {
  73 + log.debug("processHandleGet [{}]", exchange);
  74 + List<String> uriPath = exchange.getRequestOptions().getUriPath();
  75 + if (uriPath.size() >= 2 &&
  76 + (FIRMWARE_UPDATE_COAP_RESOURCE.equals(uriPath.get(uriPath.size() - 2)) ||
  77 + SOFTWARE_UPDATE_COAP_RESOURCE.equals(uriPath.get(uriPath.size() - 2)))) {
76 78 this.sendOtaData(exchange);
77 79 }
78 80 }
79 81
80 82 @Override
81 83 protected void processHandlePost(CoapExchange exchange) {
82   - log.warn("2) processHandleGet [{}]", exchange);
  84 + log.debug("processHandlePost [{}]", exchange);
83 85 }
84 86
85 87 /**
... ... @@ -136,16 +138,16 @@ public class LwM2mTransportCoapResource extends AbstractLwM2mTransportResource {
136 138 UUID currentId = UUID.fromString(idStr);
137 139 Response response = new Response(CoAP.ResponseCode.CONTENT);
138 140 byte[] fwData = this.getOtaData(currentId);
139   - log.warn("91) read softWare data (length): [{}]", fwData.length);
  141 + log.debug("Read softWare data (length): [{}]", fwData.length);
140 142 if (fwData != null && fwData.length > 0) {
141 143 response.setPayload(fwData);
142 144 if (exchange.getRequestOptions().getBlock2() != null) {
143 145 int chunkSize = exchange.getRequestOptions().getBlock2().getSzx();
144 146 boolean lastFlag = fwData.length <= chunkSize;
145 147 response.getOptions().setBlock2(chunkSize, lastFlag, 0);
146   - log.warn("92) with blokc2 Send currentId: [{}], length: [{}], chunkSize [{}], moreFlag [{}]", currentId.toString(), fwData.length, chunkSize, lastFlag);
  148 + log.trace("With block2 Send currentId: [{}], length: [{}], chunkSize [{}], moreFlag [{}]", currentId.toString(), fwData.length, chunkSize, lastFlag);
147 149 } else {
148   - log.warn("92) with block1 Send currentId: [{}], length: [{}], ", currentId.toString(), fwData.length);
  150 + log.trace("With block1 Send currentId: [{}], length: [{}], ", currentId.toString(), fwData.length);
149 151 }
150 152 exchange.respond(response);
151 153 }
... ...
... ... @@ -69,7 +69,7 @@ import static org.thingsboard.server.common.data.lwm2m.LwM2mConstants.LWM2M_SEPA
69 69 import static org.thingsboard.server.transport.lwm2m.server.ota.DefaultLwM2MOtaUpdateService.FW_RESULT_ID;
70 70 import static org.thingsboard.server.transport.lwm2m.server.ota.DefaultLwM2MOtaUpdateService.FW_STATE_ID;
71 71 import static org.thingsboard.server.transport.lwm2m.server.ota.DefaultLwM2MOtaUpdateService.SW_RESULT_ID;
72   -import static org.thingsboard.server.transport.lwm2m.server.ota.DefaultLwM2MOtaUpdateService.SW_UPDATE_STATE_ID;
  72 +import static org.thingsboard.server.transport.lwm2m.server.ota.DefaultLwM2MOtaUpdateService.SW_STATE_ID;
73 73
74 74 @Slf4j
75 75 public class LwM2mTransportUtil {
... ... @@ -143,7 +143,7 @@ public class LwM2mTransportUtil {
143 143 lwM2mOtaConvert.setCurrentType(STRING);
144 144 lwM2mOtaConvert.setValue(FirmwareUpdateResult.fromUpdateResultFwByCode(((Long) value).intValue()).getType());
145 145 return lwM2mOtaConvert;
146   - } else if (SW_UPDATE_STATE_ID.equals(path)) {
  146 + } else if (SW_STATE_ID.equals(path)) {
147 147 lwM2mOtaConvert.setCurrentType(STRING);
148 148 lwM2mOtaConvert.setValue(SoftwareUpdateState.fromUpdateStateSwByCode(((Long) value).intValue()).type);
149 149 return lwM2mOtaConvert;
... ... @@ -163,7 +163,7 @@ public class LwM2mTransportUtil {
163 163 if (transportConfiguration.getType().equals(DeviceTransportType.LWM2M)) {
164 164 return (Lwm2mDeviceProfileTransportConfiguration) transportConfiguration;
165 165 } else {
166   - log.warn("[{}] Received profile with invalid transport configuration: {}", deviceProfile.getId(), deviceProfile.getProfileData().getTransportConfiguration());
  166 + log.info("[{}] Received profile with invalid transport configuration: {}", deviceProfile.getId(), deviceProfile.getProfileData().getTransportConfiguration());
167 167 throw new IllegalArgumentException("Received profile with invalid transport configuration: " + transportConfiguration.getType());
168 168 }
169 169 }
... ... @@ -185,7 +185,7 @@ public class LwM2mTransportUtil {
185 185 return pathIdVer;
186 186 }
187 187 } catch (Exception e) {
188   - log.warn("Issue converting path with version [{}] to path without version: ", pathIdVer, e);
  188 + log.debug("Issue converting path with version [{}] to path without version: ", pathIdVer, e);
189 189 throw new RuntimeException(e);
190 190 }
191 191 }
... ...
... ... @@ -123,6 +123,7 @@ public class DefaultLwM2MAttributesService implements LwM2MAttributesService {
123 123 String newFirmwareUrl = null;
124 124 String newSoftwareTitle = null;
125 125 String newSoftwareVersion = null;
  126 + String newSoftwareUrl = null;
126 127 List<TransportProtos.TsKvProto> otherAttributes = new ArrayList<>();
127 128 for (TransportProtos.TsKvProto tsKvProto : msg.getSharedUpdatedList()) {
128 129 String attrName = tsKvProto.getKv().getKey();
... ... @@ -136,7 +137,9 @@ public class DefaultLwM2MAttributesService implements LwM2MAttributesService {
136 137 newSoftwareTitle = getStrValue(tsKvProto);
137 138 } else if (DefaultLwM2MOtaUpdateService.SOFTWARE_VERSION.equals(attrName)) {
138 139 newSoftwareVersion = getStrValue(tsKvProto);
139   - } else {
  140 + } else if (DefaultLwM2MOtaUpdateService.SOFTWARE_URL.equals(attrName)) {
  141 + newSoftwareUrl = getStrValue(tsKvProto);
  142 + }else {
140 143 otherAttributes.add(tsKvProto);
141 144 }
142 145 }
... ... @@ -144,7 +147,7 @@ public class DefaultLwM2MAttributesService implements LwM2MAttributesService {
144 147 otaUpdateService.onTargetFirmwareUpdate(lwM2MClient, newFirmwareTitle, newFirmwareVersion, Optional.ofNullable(newFirmwareUrl));
145 148 }
146 149 if (newSoftwareTitle != null || newSoftwareVersion != null) {
147   - otaUpdateService.onTargetSoftwareUpdate(lwM2MClient, newSoftwareTitle, newSoftwareVersion);
  150 + otaUpdateService.onTargetSoftwareUpdate(lwM2MClient, newSoftwareTitle, newSoftwareVersion, Optional.ofNullable(newSoftwareUrl));
148 151 }
149 152 if (!otherAttributes.isEmpty()) {
150 153 onAttributesUpdate(lwM2MClient, otherAttributes);
... ...
... ... @@ -45,10 +45,12 @@ import org.thingsboard.server.transport.lwm2m.server.downlink.TbLwM2MExecuteRequ
45 45 import org.thingsboard.server.transport.lwm2m.server.downlink.TbLwM2MWriteReplaceRequest;
46 46 import org.thingsboard.server.transport.lwm2m.server.downlink.TbLwM2MWriteResponseCallback;
47 47 import org.thingsboard.server.transport.lwm2m.server.log.LwM2MTelemetryLogService;
  48 +import org.thingsboard.server.transport.lwm2m.server.ota.firmware.LwM2MClientFwOtaInfo;
48 49 import org.thingsboard.server.transport.lwm2m.server.ota.firmware.LwM2MFirmwareUpdateStrategy;
49 50 import org.thingsboard.server.transport.lwm2m.server.ota.firmware.FirmwareDeliveryMethod;
50 51 import org.thingsboard.server.transport.lwm2m.server.ota.firmware.FirmwareUpdateResult;
51 52 import org.thingsboard.server.transport.lwm2m.server.ota.firmware.FirmwareUpdateState;
  53 +import org.thingsboard.server.transport.lwm2m.server.ota.software.LwM2MClientSwOtaInfo;
52 54 import org.thingsboard.server.transport.lwm2m.server.ota.software.LwM2MSoftwareUpdateStrategy;
53 55 import org.thingsboard.server.transport.lwm2m.server.ota.software.SoftwareUpdateResult;
54 56 import org.thingsboard.server.transport.lwm2m.server.ota.software.SoftwareUpdateState;
... ... @@ -91,12 +93,13 @@ public class DefaultLwM2MOtaUpdateService extends LwM2MExecutorAwareService impl
91 93 public static final String FIRMWARE_UPDATE_COAP_RESOURCE = "tbfw";
92 94 public static final String SOFTWARE_UPDATE_COAP_RESOURCE = "tbsw";
93 95 private static final String FW_PACKAGE_5_ID = "/5/0/0";
  96 + private static final String FW_PACKAGE_19_ID = "/19/0/0";
94 97 private static final String FW_URL_ID = "/5/0/1";
95 98 private static final String FW_EXECUTE_ID = "/5/0/2";
96 99 public static final String FW_STATE_ID = "/5/0/3";
97 100 public static final String FW_RESULT_ID = "/5/0/5";
98 101 public static final String FW_NAME_ID = "/5/0/6";
99   - public static final String FW_5_VER_ID = "/5/0/7";
  102 + public static final String FW_VER_ID = "/5/0/7";
100 103 /**
101 104 * Quectel@Hi15RM1-HLB_V1.0@BC68JAR01A10,V150R100C20B300SP7,V150R100C20B300SP7@8
102 105 * Revision:BC68JAR01A10
... ... @@ -104,17 +107,19 @@ public class DefaultLwM2MOtaUpdateService extends LwM2MExecutorAwareService impl
104 107 public static final String FW_3_VER_ID = "/3/0/3";
105 108 public static final String FW_DELIVERY_METHOD = "/5/0/9";
106 109
107   - private static final String SW_NAME_ID = "/9/0/0";
108   - private static final String SW_VER_ID = "/9/0/1";
  110 + public static final String SW_3_VER_ID = "/3/0/19";
  111 +
  112 + public static final String SW_NAME_ID = "/9/0/0";
  113 + public static final String SW_VER_ID = "/9/0/1";
109 114 public static final String SW_PACKAGE_ID = "/9/0/2";
110 115 public static final String SW_PACKAGE_URI_ID = "/9/0/3";
111 116 public static final String SW_INSTALL_ID = "/9/0/4";
112   - public static final String SW_UPDATE_STATE_ID = "/9/0/7";
  117 + public static final String SW_STATE_ID = "/9/0/7";
113 118 public static final String SW_RESULT_ID = "/9/0/9";
114 119 public static final String SW_UN_INSTALL_ID = "/9/0/6";
115 120
116   - private final Map<String, LwM2MClientOtaInfo> fwStates = new ConcurrentHashMap<>();
117   - private final Map<String, LwM2MClientOtaInfo> swStates = new ConcurrentHashMap<>();
  121 + private final Map<String, LwM2MClientFwOtaInfo> fwStates = new ConcurrentHashMap<>();
  122 + private final Map<String, LwM2MClientSwOtaInfo> swStates = new ConcurrentHashMap<>();
118 123
119 124 private final TransportService transportService;
120 125 private final LwM2mClientContext clientContext;
... ... @@ -155,27 +160,41 @@ public class DefaultLwM2MOtaUpdateService extends LwM2MExecutorAwareService impl
155 160 //TODO: add locks by client fwInfo.
156 161 //TODO: check that the client supports FW and SW by checking the supported objects in the model.
157 162 List<String> attributesToFetch = new ArrayList<>();
158   - LwM2MClientOtaInfo fwInfo = getOrInitFwInfo(client);
  163 + LwM2MClientFwOtaInfo fwInfo = getOrInitFwInfo(client);
159 164 if (fwInfo.isSupported()) {
160 165 attributesToFetch.add(FIRMWARE_TITLE);
161 166 attributesToFetch.add(FIRMWARE_VERSION);
162 167 attributesToFetch.add(FIRMWARE_URL);
163 168 }
164 169
  170 + LwM2MClientSwOtaInfo swInfo = getOrInitSwInfo(client);
  171 + if (swInfo.isSupported()) {
  172 + attributesToFetch.add(SOFTWARE_TITLE);
  173 + attributesToFetch.add(SOFTWARE_VERSION);
  174 + attributesToFetch.add(SOFTWARE_URL);
  175 + }
  176 +
165 177 if (!attributesToFetch.isEmpty()) {
166 178 var future = attributesService.getSharedAttributes(client, attributesToFetch);
167 179 DonAsynchron.withCallback(future, attrs -> {
168 180 if (fwInfo.isSupported()) {
169   - Optional<String> newFirmwareTitle = getAttributeValue(attrs, FIRMWARE_TITLE);
170   - Optional<String> newFirmwareVersion = getAttributeValue(attrs, FIRMWARE_VERSION);
171   - Optional<String> newFirmwareUrl = getAttributeValue(attrs, FIRMWARE_URL);
172   - if (newFirmwareTitle.isPresent() && newFirmwareVersion.isPresent()) {
173   - onTargetFirmwareUpdate(client, newFirmwareTitle.get(), newFirmwareVersion.get(), newFirmwareUrl);
  181 + Optional<String> newFwTitle = getAttributeValue(attrs, FIRMWARE_TITLE);
  182 + Optional<String> newFwVersion = getAttributeValue(attrs, FIRMWARE_VERSION);
  183 + Optional<String> newFwUrl = getAttributeValue(attrs, FIRMWARE_URL);
  184 + if (newFwTitle.isPresent() && newFwVersion.isPresent()) {
  185 + onTargetFirmwareUpdate(client, newFwTitle.get(), newFwVersion.get(), newFwUrl);
  186 + }
  187 + }
  188 + if (swInfo.isSupported()) {
  189 + Optional<String> newSwTitle = getAttributeValue(attrs, SOFTWARE_TITLE);
  190 + Optional<String> newSwVersion = getAttributeValue(attrs, SOFTWARE_VERSION);
  191 + Optional<String> newSwUrl = getAttributeValue(attrs, SOFTWARE_URL);
  192 + if (newSwTitle.isPresent() && newSwVersion.isPresent()) {
  193 + onTargetSoftwareUpdate(client, newSwTitle.get(), newSwVersion.get(), newSwUrl);
174 194 }
175 195 }
176 196 }, throwable -> {
177 197 if (fwInfo.isSupported()) {
178   - fwInfo.setTargetFetchFailure(true);
179 198 update(fwInfo);
180 199 }
181 200 }, executor);
... ... @@ -184,7 +203,7 @@ public class DefaultLwM2MOtaUpdateService extends LwM2MExecutorAwareService impl
184 203
185 204 @Override
186 205 public void forceFirmwareUpdate(LwM2mClient client) {
187   - LwM2MClientOtaInfo fwInfo = getOrInitFwInfo(client);
  206 + LwM2MClientFwOtaInfo fwInfo = getOrInitFwInfo(client);
188 207 fwInfo.setRetryAttempts(0);
189 208 fwInfo.setFailedPackageId(null);
190 209 startFirmwareUpdateIfNeeded(client, fwInfo);
... ... @@ -192,7 +211,7 @@ public class DefaultLwM2MOtaUpdateService extends LwM2MExecutorAwareService impl
192 211
193 212 @Override
194 213 public void onTargetFirmwareUpdate(LwM2mClient client, String newFirmwareTitle, String newFirmwareVersion, Optional<String> newFirmwareUrl) {
195   - LwM2MClientOtaInfo fwInfo = getOrInitFwInfo(client);
  214 + LwM2MClientFwOtaInfo fwInfo = getOrInitFwInfo(client);
196 215 fwInfo.updateTarget(newFirmwareTitle, newFirmwareVersion, newFirmwareUrl);
197 216 update(fwInfo);
198 217 startFirmwareUpdateIfNeeded(client, fwInfo);
... ... @@ -201,15 +220,20 @@ public class DefaultLwM2MOtaUpdateService extends LwM2MExecutorAwareService impl
201 220 @Override
202 221 public void onCurrentFirmwareNameUpdate(LwM2mClient client, String name) {
203 222 log.debug("[{}] Current fw name: {}", client.getEndpoint(), name);
204   - LwM2MClientOtaInfo fwInfo = getOrInitFwInfo(client);
205   - fwInfo.setCurrentName(name);
  223 + getOrInitFwInfo(client).setCurrentName(name);
  224 + }
  225 +
  226 + @Override
  227 + public void onCurrentSoftwareNameUpdate(LwM2mClient client, String name) {
  228 + log.debug("[{}] Current sw name: {}", client.getEndpoint(), name);
  229 + getOrInitSwInfo(client).setCurrentName(name);
206 230 }
207 231
208 232 @Override
209 233 public void onFirmwareStrategyUpdate(LwM2mClient client, OtherConfiguration configuration) {
210 234 log.debug("[{}] Current fw strategy: {}", client.getEndpoint(), configuration.getFwUpdateStrategy());
211   - LwM2MClientOtaInfo fwInfo = getOrInitFwInfo(client);
212   - fwInfo.setFwStrategy(LwM2MFirmwareUpdateStrategy.fromStrategyFwByCode(configuration.getFwUpdateStrategy()));
  235 + LwM2MClientFwOtaInfo fwInfo = getOrInitFwInfo(client);
  236 + fwInfo.setStrategy(LwM2MFirmwareUpdateStrategy.fromStrategyFwByCode(configuration.getFwUpdateStrategy()));
213 237 fwInfo.setBaseUrl(configuration.getFwUpdateResource());
214 238 startFirmwareUpdateIfNeeded(client, fwInfo);
215 239 }
... ... @@ -217,30 +241,30 @@ public class DefaultLwM2MOtaUpdateService extends LwM2MExecutorAwareService impl
217 241 @Override
218 242 public void onCurrentSoftwareStrategyUpdate(LwM2mClient client, OtherConfiguration configuration) {
219 243 log.debug("[{}] Current sw strategy: {}", client.getEndpoint(), configuration.getSwUpdateStrategy());
220   - LwM2MClientOtaInfo swInfo = getOrInitSwInfo(client);
221   - swInfo.setSwStrategy(LwM2MSoftwareUpdateStrategy.fromStrategySwByCode(configuration.getSwUpdateStrategy()));
  244 + LwM2MClientSwOtaInfo swInfo = getOrInitSwInfo(client);
  245 + swInfo.setStrategy(LwM2MSoftwareUpdateStrategy.fromStrategySwByCode(configuration.getSwUpdateStrategy()));
222 246 swInfo.setBaseUrl(configuration.getSwUpdateResource());
223 247 startSoftwareUpdateIfNeeded(client, swInfo);
224 248 }
225 249
226 250 @Override
227 251 public void onCurrentFirmwareVersion3Update(LwM2mClient client, String version) {
228   - log.debug("[{}] Current fw version: {}", client.getEndpoint(), version);
229   - LwM2MClientOtaInfo fwInfo = getOrInitFwInfo(client);
  252 + log.debug("[{}] Current fw version(3): {}", client.getEndpoint(), version);
  253 + LwM2MClientFwOtaInfo fwInfo = getOrInitFwInfo(client);
230 254 fwInfo.setCurrentVersion3(version);
231 255 }
232 256
233 257 @Override
234   - public void onCurrentFirmwareVersion5Update(LwM2mClient client, String version) {
235   - log.debug("[{}] Current fw version: {}", client.getEndpoint(), version);
236   - LwM2MClientOtaInfo fwInfo = getOrInitFwInfo(client);
237   - fwInfo.setCurrentVersion5(version);
  258 + public void onCurrentFirmwareVersionUpdate(LwM2mClient client, String version) {
  259 + log.debug("[{}] Current fw version(5): {}", client.getEndpoint(), version);
  260 + LwM2MClientFwOtaInfo fwInfo = getOrInitFwInfo(client);
  261 + fwInfo.setCurrentVersion(version);
238 262 }
239 263
240 264 @Override
241 265 public void onCurrentFirmwareStateUpdate(LwM2mClient client, Long stateCode) {
242 266 log.debug("[{}] Current fw state: {}", client.getEndpoint(), stateCode);
243   - LwM2MClientOtaInfo fwInfo = getOrInitFwInfo(client);
  267 + LwM2MClientFwOtaInfo fwInfo = getOrInitFwInfo(client);
244 268 FirmwareUpdateState state = FirmwareUpdateState.fromStateFwByCode(stateCode.intValue());
245 269 if (FirmwareUpdateState.DOWNLOADED.equals(state)) {
246 270 executeFwUpdate(client);
... ... @@ -255,7 +279,7 @@ public class DefaultLwM2MOtaUpdateService extends LwM2MExecutorAwareService impl
255 279 @Override
256 280 public void onCurrentFirmwareResultUpdate(LwM2mClient client, Long code) {
257 281 log.debug("[{}] Current fw result: {}", client.getEndpoint(), code);
258   - LwM2MClientOtaInfo fwInfo = getOrInitFwInfo(client);
  282 + LwM2MClientFwOtaInfo fwInfo = getOrInitFwInfo(client);
259 283 FirmwareUpdateResult result = FirmwareUpdateResult.fromUpdateResultFwByCode(code.intValue());
260 284 Optional<OtaPackageUpdateStatus> status = toOtaPackageUpdateStatus(result);
261 285 status.ifPresent(otaStatus -> sendStateUpdateToTelemetry(client, fwInfo,
... ... @@ -272,16 +296,66 @@ public class DefaultLwM2MOtaUpdateService extends LwM2MExecutorAwareService impl
272 296 @Override
273 297 public void onCurrentFirmwareDeliveryMethodUpdate(LwM2mClient client, Long value) {
274 298 log.debug("[{}] Current fw delivery method: {}", client.getEndpoint(), value);
275   - LwM2MClientOtaInfo fwInfo = getOrInitFwInfo(client);
  299 + LwM2MClientFwOtaInfo fwInfo = getOrInitFwInfo(client);
276 300 fwInfo.setDeliveryMethod(value.intValue());
277 301 }
278 302
279 303 @Override
280   - public void onTargetSoftwareUpdate(LwM2mClient client, String newSoftwareTitle, String newSoftwareVersion) {
  304 + public void onCurrentSoftwareVersion3Update(LwM2mClient client, String version) {
  305 + log.debug("[{}] Current sw version(3): {}", client.getEndpoint(), version);
  306 + getOrInitSwInfo(client).setCurrentVersion3(version);
  307 + }
  308 +
  309 + @Override
  310 + public void onCurrentSoftwareVersionUpdate(LwM2mClient client, String version) {
  311 + log.debug("[{}] Current sw version(9): {}", client.getEndpoint(), version);
  312 + getOrInitSwInfo(client).setCurrentVersion(version);
  313 + }
281 314
  315 + @Override
  316 + public void onCurrentSoftwareStateUpdate(LwM2mClient client, Long stateCode) {
  317 + log.debug("[{}] Current sw state: {}", client.getEndpoint(), stateCode);
  318 + LwM2MClientSwOtaInfo swInfo = getOrInitSwInfo(client);
  319 + SoftwareUpdateState state = SoftwareUpdateState.fromUpdateStateSwByCode(stateCode.intValue());
  320 + if (SoftwareUpdateState.INITIAL.equals(state)) {
  321 + startSoftwareUpdateIfNeeded(client, swInfo);
  322 + } else if (SoftwareUpdateState.DELIVERED.equals(state)) {
  323 + executeSwInstall(client);
  324 + }
  325 + swInfo.setUpdateState(state);
  326 + Optional<OtaPackageUpdateStatus> status = toOtaPackageUpdateStatus(state);
  327 + status.ifPresent(otaStatus -> sendStateUpdateToTelemetry(client, swInfo,
  328 + otaStatus, "Firmware Update State: " + state.name()));
  329 + update(swInfo);
282 330 }
283 331
284   - private void startFirmwareUpdateIfNeeded(LwM2mClient client, LwM2MClientOtaInfo fwInfo) {
  332 +
  333 + @Override
  334 + public void onCurrentSoftwareResultUpdate(LwM2mClient client, Long code) {
  335 + log.debug("[{}] Current sw result: {}", client.getEndpoint(), code);
  336 + LwM2MClientSwOtaInfo swInfo = getOrInitSwInfo(client);
  337 + SoftwareUpdateResult result = SoftwareUpdateResult.fromUpdateResultSwByCode(code.intValue());
  338 + Optional<OtaPackageUpdateStatus> status = toOtaPackageUpdateStatus(result);
  339 + status.ifPresent(otaStatus -> sendStateUpdateToTelemetry(client, swInfo,
  340 + otaStatus, "Firmware Update Result: " + result.name()));
  341 + if (result.isAgain() && swInfo.getRetryAttempts() <= 2) {
  342 + swInfo.setRetryAttempts(swInfo.getRetryAttempts() + 1);
  343 + startSoftwareUpdateIfNeeded(client, swInfo);
  344 + } else {
  345 + swInfo.update(result);
  346 + }
  347 + update(swInfo);
  348 + }
  349 +
  350 + @Override
  351 + public void onTargetSoftwareUpdate(LwM2mClient client, String newSoftwareTitle, String newSoftwareVersion, Optional<String> newFirmwareUrl) {
  352 + LwM2MClientSwOtaInfo fwInfo = getOrInitSwInfo(client);
  353 + fwInfo.updateTarget(newSoftwareTitle, newSoftwareVersion, newFirmwareUrl);
  354 + update(fwInfo);
  355 + startSoftwareUpdateIfNeeded(client, fwInfo);
  356 + }
  357 +
  358 + private void startFirmwareUpdateIfNeeded(LwM2mClient client, LwM2MClientFwOtaInfo fwInfo) {
285 359 try {
286 360 if (!fwInfo.isSupported()) {
287 361 log.debug("[{}] Fw update is not supported: {}", client.getEndpoint(), fwInfo);
... ... @@ -289,35 +363,70 @@ public class DefaultLwM2MOtaUpdateService extends LwM2MExecutorAwareService impl
289 363 } else if (fwInfo.isUpdateRequired()) {
290 364 if (StringUtils.isNotEmpty(fwInfo.getTargetUrl())) {
291 365 log.debug("[{}] Starting update to [{}{}] using URL: {}", client.getEndpoint(), fwInfo.getTargetName(), fwInfo.getTargetVersion(), fwInfo.getTargetUrl());
292   - startFirmwareUpdateUsingUrl(client, fwInfo.getTargetUrl());
  366 + startUpdateUsingUrl(client, FW_URL_ID, fwInfo.getTargetUrl());
293 367 } else {
294 368 log.debug("[{}] Starting update to [{}{}] using binary", client.getEndpoint(), fwInfo.getTargetName(), fwInfo.getTargetVersion());
295   - startFirmwareUpdateUsingBinary(client, fwInfo);
  369 + startUpdateUsingBinary(client, fwInfo);
296 370 }
297 371 }
298 372 } catch (Exception e) {
299   - log.warn("[{}] failed to update client: {}", client.getEndpoint(), fwInfo, e);
  373 + log.info("[{}] failed to update client: {}", client.getEndpoint(), fwInfo, e);
300 374 sendStateUpdateToTelemetry(client, fwInfo, OtaPackageUpdateStatus.FAILED, "Internal server error: " + e.getMessage());
301 375 }
302 376 }
303 377
304   - private void startSoftwareUpdateIfNeeded(LwM2mClient client, LwM2MClientOtaInfo swInfo) {
  378 + private void startSoftwareUpdateIfNeeded(LwM2mClient client, LwM2MClientSwOtaInfo swInfo) {
  379 + try {
  380 + if (!swInfo.isSupported()) {
  381 + log.debug("[{}] Sw update is not supported: {}", client.getEndpoint(), swInfo);
  382 + sendStateUpdateToTelemetry(client, swInfo, OtaPackageUpdateStatus.FAILED, "Client does not support software update or profile misconfiguration!");
  383 + } else if (swInfo.isUpdateRequired()) {
  384 + if (SoftwareUpdateState.INSTALLED.equals(swInfo.getUpdateState())) {
  385 + log.debug("[{}] Attempt to restore the update state: {}", client.getEndpoint(), swInfo.getUpdateState());
  386 + executeSwUninstallForUpdate(client);
  387 + } else {
  388 + if (StringUtils.isNotEmpty(swInfo.getTargetUrl())) {
  389 + log.debug("[{}] Starting update to [{}{}] using URL: {}", client.getEndpoint(), swInfo.getTargetName(), swInfo.getTargetVersion(), swInfo.getTargetUrl());
  390 + startUpdateUsingUrl(client, SW_PACKAGE_URI_ID, swInfo.getTargetUrl());
  391 + } else {
  392 + log.debug("[{}] Starting update to [{}{}] using binary", client.getEndpoint(), swInfo.getTargetName(), swInfo.getTargetVersion());
  393 + startUpdateUsingBinary(client, swInfo);
  394 + }
  395 + }
  396 + }
  397 + } catch (Exception e) {
  398 + log.info("[{}] failed to update client: {}", client.getEndpoint(), swInfo, e);
  399 + sendStateUpdateToTelemetry(client, swInfo, OtaPackageUpdateStatus.FAILED, "Internal server error: " + e.getMessage());
  400 + }
  401 + }
  402 +
  403 + public void startUpdateUsingBinary(LwM2mClient client, LwM2MClientSwOtaInfo swInfo) {
  404 + this.transportService.process(client.getSession(), createOtaPackageRequestMsg(client.getSession(), swInfo.getType().name()),
  405 + new TransportServiceCallback<>() {
  406 + @Override
  407 + public void onSuccess(TransportProtos.GetOtaPackageResponseMsg response) {
  408 + executor.submit(() -> doUpdateSoftwareUsingBinary(response, swInfo, client));
  409 + }
305 410
  411 + @Override
  412 + public void onError(Throwable e) {
  413 + logService.log(client, "Failed to process software update: " + e.getMessage());
  414 + }
  415 + });
306 416 }
307 417
308   - private void startFirmwareUpdateUsingUrl(LwM2mClient client, String url) {
309   - String targetIdVer = convertObjectIdToVersionedId(FW_URL_ID, client.getRegistration());
  418 + private void startUpdateUsingUrl(LwM2mClient client, String id, String url) {
  419 + String targetIdVer = convertObjectIdToVersionedId(id, client.getRegistration());
310 420 TbLwM2MWriteReplaceRequest request = TbLwM2MWriteReplaceRequest.builder().versionedId(targetIdVer).value(url).timeout(config.getTimeout()).build();
311 421 downlinkHandler.sendWriteReplaceRequest(client, request, new TbLwM2MWriteResponseCallback(uplinkHandler, logService, client, targetIdVer));
312 422 }
313 423
314   - public void startFirmwareUpdateUsingBinary(LwM2mClient client, LwM2MClientOtaInfo fwInfo) {
315   - String versionedId = convertObjectIdToVersionedId(FW_PACKAGE_5_ID, client.getRegistration());
316   - this.transportService.process(client.getSession(), createOtaPackageRequestMsg(client.getSession(), OtaPackageType.FIRMWARE.name()),
  424 + public void startUpdateUsingBinary(LwM2mClient client, LwM2MClientFwOtaInfo fwInfo) {
  425 + this.transportService.process(client.getSession(), createOtaPackageRequestMsg(client.getSession(), fwInfo.getType().name()),
317 426 new TransportServiceCallback<>() {
318 427 @Override
319 428 public void onSuccess(TransportProtos.GetOtaPackageResponseMsg response) {
320   - executor.submit(() -> doUpdateFirmwareUsingBinary(response, fwInfo, versionedId, client));
  429 + executor.submit(() -> doUpdateFirmwareUsingBinary(response, fwInfo, client));
321 430 }
322 431
323 432 @Override
... ... @@ -327,34 +436,60 @@ public class DefaultLwM2MOtaUpdateService extends LwM2MExecutorAwareService impl
327 436 });
328 437 }
329 438
330   - private void doUpdateFirmwareUsingBinary(TransportProtos.GetOtaPackageResponseMsg response, LwM2MClientOtaInfo fwInfo, String versionedId, LwM2mClient client) {
  439 + private void doUpdateFirmwareUsingBinary(TransportProtos.GetOtaPackageResponseMsg response, LwM2MClientFwOtaInfo info, LwM2mClient client) {
331 440 if (TransportProtos.ResponseStatus.SUCCESS.equals(response.getResponseStatus())) {
332 441 UUID otaPackageId = new UUID(response.getOtaPackageIdMSB(), response.getOtaPackageIdLSB());
333 442 LwM2MFirmwareUpdateStrategy strategy;
334   - if (fwInfo.getDeliveryMethod() == null || fwInfo.getDeliveryMethod() == FirmwareDeliveryMethod.BOTH.code) {
335   - strategy = fwInfo.getFwStrategy();
  443 + if (info.getDeliveryMethod() == null || info.getDeliveryMethod() == FirmwareDeliveryMethod.BOTH.code) {
  444 + strategy = info.getStrategy();
336 445 } else {
337   - strategy = fwInfo.getDeliveryMethod() == FirmwareDeliveryMethod.PULL.code ? LwM2MFirmwareUpdateStrategy.OBJ_5_TEMP_URL : LwM2MFirmwareUpdateStrategy.OBJ_5_BINARY;
  446 + strategy = info.getDeliveryMethod() == FirmwareDeliveryMethod.PULL.code ? LwM2MFirmwareUpdateStrategy.OBJ_5_TEMP_URL : LwM2MFirmwareUpdateStrategy.OBJ_5_BINARY;
338 447 }
339 448 switch (strategy) {
340 449 case OBJ_5_BINARY:
341   - byte[] firmwareChunk = otaPackageDataCache.get(otaPackageId.toString(), 0, 0);
342   - TbLwM2MWriteReplaceRequest writeRequest = TbLwM2MWriteReplaceRequest.builder().versionedId(versionedId)
343   - .value(firmwareChunk).contentFormat(ContentFormat.OPAQUE)
344   - .timeout(config.getTimeout()).build();
345   - downlinkHandler.sendWriteReplaceRequest(client, writeRequest, new TbLwM2MWriteResponseCallback(uplinkHandler, logService, client, versionedId));
  450 + startUpdateUsingBinary(client, convertObjectIdToVersionedId(FW_PACKAGE_5_ID, client.getRegistration()), otaPackageId);
  451 + break;
  452 + case OBJ_19_BINARY:
  453 + startUpdateUsingBinary(client, convertObjectIdToVersionedId(FW_PACKAGE_19_ID, client.getRegistration()), otaPackageId);
346 454 break;
347 455 case OBJ_5_TEMP_URL:
348   - startFirmwareUpdateUsingUrl(client, fwInfo.getBaseUrl() + "/" + FIRMWARE_UPDATE_COAP_RESOURCE + "/" + otaPackageId.toString());
  456 + startUpdateUsingUrl(client, FW_URL_ID, info.getBaseUrl() + "/" + FIRMWARE_UPDATE_COAP_RESOURCE + "/" + otaPackageId.toString());
  457 + break;
  458 + default:
  459 + sendStateUpdateToTelemetry(client, info, OtaPackageUpdateStatus.FAILED, "Unsupported strategy: " + strategy.name());
  460 + }
  461 + } else {
  462 + sendStateUpdateToTelemetry(client, info, OtaPackageUpdateStatus.FAILED, "Failed to fetch OTA package: " + response.getResponseStatus());
  463 + }
  464 + }
  465 +
  466 + private void doUpdateSoftwareUsingBinary(TransportProtos.GetOtaPackageResponseMsg response, LwM2MClientSwOtaInfo info, LwM2mClient client) {
  467 + if (TransportProtos.ResponseStatus.SUCCESS.equals(response.getResponseStatus())) {
  468 + UUID otaPackageId = new UUID(response.getOtaPackageIdMSB(), response.getOtaPackageIdLSB());
  469 + LwM2MSoftwareUpdateStrategy strategy = info.getStrategy();
  470 + switch (strategy) {
  471 + case BINARY:
  472 + startUpdateUsingBinary(client, convertObjectIdToVersionedId(SW_PACKAGE_ID, client.getRegistration()), otaPackageId);
  473 + break;
  474 + case TEMP_URL:
  475 + startUpdateUsingUrl(client, SW_PACKAGE_URI_ID, info.getBaseUrl() + "/" + FIRMWARE_UPDATE_COAP_RESOURCE + "/" + otaPackageId.toString());
349 476 break;
350 477 default:
351   - sendStateUpdateToTelemetry(client, fwInfo, OtaPackageUpdateStatus.FAILED, "Unsupported strategy: " + strategy.name());
  478 + sendStateUpdateToTelemetry(client, info, OtaPackageUpdateStatus.FAILED, "Unsupported strategy: " + strategy.name());
352 479 }
353 480 } else {
354   - sendStateUpdateToTelemetry(client, fwInfo, OtaPackageUpdateStatus.FAILED, "Failed to fetch OTA package: " + response.getResponseStatus());
  481 + sendStateUpdateToTelemetry(client, info, OtaPackageUpdateStatus.FAILED, "Failed to fetch OTA package: " + response.getResponseStatus());
355 482 }
356 483 }
357 484
  485 + private void startUpdateUsingBinary(LwM2mClient client, String versionedId, UUID otaPackageId) {
  486 + byte[] firmwareChunk = otaPackageDataCache.get(otaPackageId.toString(), 0, 0);
  487 + TbLwM2MWriteReplaceRequest writeRequest = TbLwM2MWriteReplaceRequest.builder().versionedId(versionedId)
  488 + .value(firmwareChunk).contentFormat(ContentFormat.OPAQUE)
  489 + .timeout(config.getTimeout()).build();
  490 + downlinkHandler.sendWriteReplaceRequest(client, writeRequest, new TbLwM2MWriteResponseCallback(uplinkHandler, logService, client, versionedId));
  491 + }
  492 +
358 493 private TransportProtos.GetOtaPackageRequestMsg createOtaPackageRequestMsg(TransportProtos.SessionInfoProto sessionInfo, String nameFwSW) {
359 494 return TransportProtos.GetOtaPackageRequestMsg.newBuilder()
360 495 .setDeviceIdMSB(sessionInfo.getDeviceIdMSB())
... ... @@ -370,6 +505,16 @@ public class DefaultLwM2MOtaUpdateService extends LwM2MExecutorAwareService impl
370 505 downlinkHandler.sendExecuteRequest(client, request, new TbLwM2MExecuteCallback(logService, client, FW_EXECUTE_ID));
371 506 }
372 507
  508 + private void executeSwInstall(LwM2mClient client) {
  509 + TbLwM2MExecuteRequest request = TbLwM2MExecuteRequest.builder().versionedId(SW_INSTALL_ID).timeout(config.getTimeout()).build();
  510 + downlinkHandler.sendExecuteRequest(client, request, new TbLwM2MExecuteCallback(logService, client, SW_INSTALL_ID));
  511 + }
  512 +
  513 + private void executeSwUninstallForUpdate(LwM2mClient client) {
  514 + TbLwM2MExecuteRequest request = TbLwM2MExecuteRequest.builder().versionedId(SW_UN_INSTALL_ID).params("1").timeout(config.getTimeout()).build();
  515 + downlinkHandler.sendExecuteRequest(client, request, new TbLwM2MExecuteCallback(logService, client, SW_INSTALL_ID));
  516 + }
  517 +
373 518 private Optional<String> getAttributeValue(List<TransportProtos.TsKvProto> attrs, String keyName) {
374 519 for (TransportProtos.TsKvProto attr : attrs) {
375 520 if (keyName.equals(attr.getKv().getKey())) {
... ... @@ -383,40 +528,41 @@ public class DefaultLwM2MOtaUpdateService extends LwM2MExecutorAwareService impl
383 528 return Optional.empty();
384 529 }
385 530
386   - public LwM2MClientOtaInfo getOrInitFwInfo(LwM2mClient client) {
  531 + private LwM2MClientFwOtaInfo getOrInitFwInfo(LwM2mClient client) {
387 532 return this.fwStates.computeIfAbsent(client.getEndpoint(), endpoint -> {
388   - LwM2MClientOtaInfo info = otaInfoStore.get(OtaPackageType.FIRMWARE, endpoint);
  533 + LwM2MClientFwOtaInfo info = otaInfoStore.getFw(endpoint);
389 534 if (info == null) {
390 535 var profile = clientContext.getProfile(client.getProfileId());
391   - info = new LwM2MClientOtaInfo(endpoint, OtaPackageType.FIRMWARE,
392   - LwM2MFirmwareUpdateStrategy.fromStrategyFwByCode(profile.getClientLwM2mSettings().getFwUpdateStrategy()),
393   - profile.getClientLwM2mSettings().getFwUpdateResource());
  536 + info = new LwM2MClientFwOtaInfo(endpoint, profile.getClientLwM2mSettings().getFwUpdateResource(),
  537 + LwM2MFirmwareUpdateStrategy.fromStrategyFwByCode(profile.getClientLwM2mSettings().getFwUpdateStrategy()));
394 538 update(info);
395 539 }
396 540 return info;
397 541 });
398 542 }
399 543
400   - private LwM2MClientOtaInfo getOrInitSwInfo(LwM2mClient client) {
401   - return this.fwStates.computeIfAbsent(client.getEndpoint(), endpoint -> {
402   - LwM2MClientOtaInfo info = otaInfoStore.get(OtaPackageType.SOFTWARE, endpoint);
  544 + private LwM2MClientSwOtaInfo getOrInitSwInfo(LwM2mClient client) {
  545 + return this.swStates.computeIfAbsent(client.getEndpoint(), endpoint -> {
  546 + LwM2MClientSwOtaInfo info = otaInfoStore.getSw(endpoint);
403 547 if (info == null) {
404 548 var profile = clientContext.getProfile(client.getProfileId());
405   - info = new LwM2MClientOtaInfo(endpoint, OtaPackageType.SOFTWARE,
406   - LwM2MSoftwareUpdateStrategy.fromStrategySwByCode(profile.getClientLwM2mSettings().getFwUpdateStrategy()),
407   - profile.getClientLwM2mSettings().getSwUpdateResource());
  549 + info = new LwM2MClientSwOtaInfo(endpoint, profile.getClientLwM2mSettings().getSwUpdateResource(),
  550 + LwM2MSoftwareUpdateStrategy.fromStrategySwByCode(profile.getClientLwM2mSettings().getFwUpdateStrategy()));
408 551 update(info);
409 552 }
410 553 return info;
411 554 });
  555 + }
412 556
  557 + private void update(LwM2MClientFwOtaInfo info) {
  558 + otaInfoStore.putFw(info);
413 559 }
414 560
415   - private void update(LwM2MClientOtaInfo info) {
416   - otaInfoStore.put(info);
  561 + private void update(LwM2MClientSwOtaInfo info) {
  562 + otaInfoStore.putSw(info);
417 563 }
418 564
419   - private void sendStateUpdateToTelemetry(LwM2mClient client, LwM2MClientOtaInfo fwInfo, OtaPackageUpdateStatus status, String log) {
  565 + private void sendStateUpdateToTelemetry(LwM2mClient client, LwM2MClientOtaInfo<?, ?, ?> fwInfo, OtaPackageUpdateStatus status, String log) {
420 566 List<TransportProtos.KeyValueProto> result = new ArrayList<>();
421 567 TransportProtos.KeyValueProto.Builder kvProto = TransportProtos.KeyValueProto.newBuilder().setKey(getAttributeKey(fwInfo.getType(), STATE));
422 568 kvProto.setType(TransportProtos.KeyValueType.STRING_V).setStringV(status.name());
... ... @@ -462,22 +608,31 @@ public class DefaultLwM2MOtaUpdateService extends LwM2MExecutorAwareService impl
462 608 }
463 609 }
464 610
  611 + private static Optional<OtaPackageUpdateStatus> toOtaPackageUpdateStatus(SoftwareUpdateState swUpdateState) {
  612 + switch (swUpdateState) {
  613 + case INITIAL:
  614 + return Optional.empty();
  615 + case DOWNLOAD_STARTED:
  616 + return Optional.of(DOWNLOADING);
  617 + case DOWNLOADED:
  618 + return Optional.of(DOWNLOADING);
  619 + case DELIVERED:
  620 + return Optional.of(DOWNLOADED);
  621 + case INSTALLED:
  622 + return Optional.empty();
  623 + default:
  624 + throw new CodecException("Invalid value stateSw %d for SoftwareUpdateState.", swUpdateState);
  625 + }
  626 + }
  627 +
465 628 /**
466 629 * FirmwareUpdateStatus {
467 630 * DOWNLOADING, DOWNLOADED, VERIFIED, UPDATING, UPDATED, FAILED
468 631 */
469   - public static Optional<OtaPackageUpdateStatus> toSwSateResultUpdateStatus(SoftwareUpdateState softwareUpdateState, SoftwareUpdateResult softwareUpdateResult) {
  632 + public static Optional<OtaPackageUpdateStatus> toOtaPackageUpdateStatus(SoftwareUpdateResult softwareUpdateResult) {
470 633 switch (softwareUpdateResult) {
471 634 case INITIAL:
472   - switch (softwareUpdateState) {
473   - case INITIAL:
474   - case DOWNLOAD_STARTED:
475   - return Optional.of(DOWNLOADING);
476   - case DOWNLOADED:
477   - return Optional.of(DOWNLOADED);
478   - case DELIVERED:
479   - return Optional.of(VERIFIED);
480   - }
  635 + return Optional.empty();
481 636 case DOWNLOADING:
482 637 return Optional.of(DOWNLOADING);
483 638 case SUCCESSFULLY_INSTALLED:
... ... @@ -495,7 +650,7 @@ public class DefaultLwM2MOtaUpdateService extends LwM2MExecutorAwareService impl
495 650 case UN_INSTALL_FAILURE:
496 651 return Optional.of(FAILED);
497 652 default:
498   - throw new CodecException("Invalid value stateFw %s %s for FirmwareUpdateStatus.", softwareUpdateState.name(), softwareUpdateResult.name());
  653 + throw new CodecException("Invalid value stateFw %s for FirmwareUpdateStatus.", softwareUpdateResult.name());
499 654 }
500 655 }
501 656
... ...
... ... @@ -20,60 +20,42 @@ import lombok.Data;
20 20 import lombok.NoArgsConstructor;
21 21 import org.thingsboard.server.common.data.StringUtils;
22 22 import org.thingsboard.server.common.data.ota.OtaPackageType;
23   -import org.thingsboard.server.transport.lwm2m.server.ota.firmware.LwM2MFirmwareUpdateStrategy;
24   -import org.thingsboard.server.transport.lwm2m.server.ota.firmware.FirmwareUpdateResult;
25   -import org.thingsboard.server.transport.lwm2m.server.ota.firmware.FirmwareUpdateState;
26   -import org.thingsboard.server.transport.lwm2m.server.ota.software.LwM2MSoftwareUpdateStrategy;
27 23
28 24 import java.util.Optional;
29 25
30 26 @Data
31 27 @NoArgsConstructor
32   -public class LwM2MClientOtaInfo {
  28 +public abstract class LwM2MClientOtaInfo<Strategy, State, Result> {
33 29
34 30 private String endpoint;
35   - private OtaPackageType type;
36   -
37 31 private String baseUrl;
38 32
39   - private boolean targetFetchFailure;
40   - private String targetName;
41   - private String targetVersion;
42   - private String targetUrl;
43   -
44   - private boolean currentFetchFailure;
45   - private String currentName;
46   - private String currentVersion3;
47   - private String currentVersion5;
48   - private Integer deliveryMethod;
  33 + protected String targetName;
  34 + protected String targetVersion;
  35 + protected String targetUrl;
49 36
50 37 //TODO: use value from device if applicable;
51   - private LwM2MFirmwareUpdateStrategy fwStrategy;
52   - private LwM2MSoftwareUpdateStrategy swStrategy;
53   - private FirmwareUpdateState updateState;
54   - private FirmwareUpdateResult updateResult;
  38 + protected Strategy strategy;
  39 + protected State updateState;
  40 + protected Result result;
55 41
56   - private String failedPackageId;
57   - private int retryAttempts;
  42 + protected String failedPackageId;
  43 + protected int retryAttempts;
58 44
59   - public LwM2MClientOtaInfo(String endpoint, OtaPackageType type, LwM2MFirmwareUpdateStrategy fwStrategy, String baseUrl) {
60   - this.endpoint = endpoint;
61   - this.type = type;
62   - this.fwStrategy = fwStrategy;
63   - this.baseUrl = baseUrl;
64   - }
  45 + protected String currentName;
  46 + protected String currentVersion3;
  47 + protected String currentVersion;
65 48
66   - public LwM2MClientOtaInfo(String endpoint, OtaPackageType type, LwM2MSoftwareUpdateStrategy swStrategy, String baseUrl) {
  49 + public LwM2MClientOtaInfo(String endpoint, String baseUrl, Strategy strategy) {
67 50 this.endpoint = endpoint;
68   - this.type = type;
69   - this.swStrategy = swStrategy;
70 51 this.baseUrl = baseUrl;
  52 + this.strategy = strategy;
71 53 }
72 54
73   - public void updateTarget(String targetName, String targetVersion, Optional<String> newFirmwareUrl) {
  55 + public void updateTarget(String targetName, String targetVersion, Optional<String> newTargetUrl) {
74 56 this.targetName = targetName;
75 57 this.targetVersion = targetVersion;
76   - this.targetUrl = newFirmwareUrl.orElse(null);
  58 + this.targetUrl = newTargetUrl.orElse(null);
77 59 }
78 60
79 61 @JsonIgnore
... ... @@ -82,7 +64,7 @@ public class LwM2MClientOtaInfo {
82 64 return false;
83 65 } else {
84 66 String targetPackageId = getPackageId(targetName, targetVersion);
85   - String currentPackageIdUsingObject5 = getPackageId(currentName, currentVersion5);
  67 + String currentPackageIdUsingObject5 = getPackageId(currentName, currentVersion);
86 68 if (StringUtils.isNotEmpty(failedPackageId) && failedPackageId.equals(targetPackageId)) {
87 69 return false;
88 70 } else {
... ... @@ -99,25 +81,15 @@ public class LwM2MClientOtaInfo {
99 81
100 82 @JsonIgnore
101 83 public boolean isSupported() {
102   - return StringUtils.isNotEmpty(currentName) || StringUtils.isNotEmpty(currentVersion5) || StringUtils.isNotEmpty(currentVersion3);
  84 + return StringUtils.isNotEmpty(currentName) || StringUtils.isNotEmpty(currentVersion) || StringUtils.isNotEmpty(currentVersion3);
103 85 }
104 86
105   - public void update(FirmwareUpdateResult updateResult) {
106   - this.updateResult = updateResult;
107   - switch (updateResult) {
108   - case INITIAL:
109   - break;
110   - case UPDATE_SUCCESSFULLY:
111   - retryAttempts = 0;
112   - break;
113   - default:
114   - failedPackageId = getPackageId(targetName, targetVersion);
115   - break;
116   - }
117   - }
  87 + public abstract void update(Result result);
118 88
119   - private static String getPackageId(String name, String version) {
  89 + protected static String getPackageId(String name, String version) {
120 90 return (StringUtils.isNotEmpty(name) ? name : "") + (StringUtils.isNotEmpty(version) ? version : "");
121 91 }
122 92
  93 + public abstract OtaPackageType getType();
  94 +
123 95 }
... ...
... ... @@ -26,9 +26,9 @@ public interface LwM2MOtaUpdateService {
26 26
27 27 void forceFirmwareUpdate(LwM2mClient client);
28 28
29   - void onTargetFirmwareUpdate(LwM2mClient client, String newFirmwareTitle, String newFirmwareVersion, Optional<String> newFirmwareUrl);
  29 + void onTargetFirmwareUpdate(LwM2mClient client, String newFwTitle, String newFwVersion, Optional<String> newFwUrl);
30 30
31   - void onTargetSoftwareUpdate(LwM2mClient client, String newSoftwareTitle, String newSoftwareVersion);
  31 + void onTargetSoftwareUpdate(LwM2mClient client, String newSwTitle, String newSwVersion, Optional<String> newSwUrl);
32 32
33 33 void onCurrentFirmwareNameUpdate(LwM2mClient client, String name);
34 34
... ... @@ -38,11 +38,21 @@ public interface LwM2MOtaUpdateService {
38 38
39 39 void onCurrentFirmwareVersion3Update(LwM2mClient client, String version);
40 40
41   - void onCurrentFirmwareVersion5Update(LwM2mClient client, String version);
  41 + void onCurrentFirmwareVersionUpdate(LwM2mClient client, String version);
42 42
43 43 void onCurrentFirmwareStateUpdate(LwM2mClient client, Long state);
44 44
45 45 void onCurrentFirmwareResultUpdate(LwM2mClient client, Long result);
46 46
47 47 void onCurrentFirmwareDeliveryMethodUpdate(LwM2mClient lwM2MClient, Long value);
  48 +
  49 + void onCurrentSoftwareNameUpdate(LwM2mClient lwM2MClient, String name);
  50 +
  51 + void onCurrentSoftwareVersion3Update(LwM2mClient lwM2MClient, String version);
  52 +
  53 + void onCurrentSoftwareVersionUpdate(LwM2mClient client, String version);
  54 +
  55 + void onCurrentSoftwareStateUpdate(LwM2mClient lwM2MClient, Long value);
  56 +
  57 + void onCurrentSoftwareResultUpdate(LwM2mClient client, Long result);
48 58 }
... ...
  1 +/**
  2 + * Copyright © 2016-2021 The Thingsboard Authors
  3 + *
  4 + * Licensed under the Apache License, Version 2.0 (the "License");
  5 + * you may not use this file except in compliance with the License.
  6 + * You may obtain a copy of the License at
  7 + *
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + *
  10 + * Unless required by applicable law or agreed to in writing, software
  11 + * distributed under the License is distributed on an "AS IS" BASIS,
  12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 + * See the License for the specific language governing permissions and
  14 + * limitations under the License.
  15 + */
  16 +package org.thingsboard.server.transport.lwm2m.server.ota.firmware;
  17 +
  18 +import com.fasterxml.jackson.annotation.JsonIgnore;
  19 +import lombok.Data;
  20 +import lombok.EqualsAndHashCode;
  21 +import lombok.NoArgsConstructor;
  22 +import org.thingsboard.server.common.data.ota.OtaPackageType;
  23 +import org.thingsboard.server.transport.lwm2m.server.ota.LwM2MClientOtaInfo;
  24 +
  25 +@Data
  26 +@EqualsAndHashCode(callSuper = true)
  27 +@NoArgsConstructor
  28 +public class LwM2MClientFwOtaInfo extends LwM2MClientOtaInfo<LwM2MFirmwareUpdateStrategy, FirmwareUpdateState, FirmwareUpdateResult> {
  29 +
  30 + private Integer deliveryMethod;
  31 +
  32 + public LwM2MClientFwOtaInfo(String endpoint, String baseUrl, LwM2MFirmwareUpdateStrategy strategy) {
  33 + super(endpoint, baseUrl, strategy);
  34 + }
  35 +
  36 + @JsonIgnore
  37 + @Override
  38 + public OtaPackageType getType() {
  39 + return OtaPackageType.FIRMWARE;
  40 + }
  41 +
  42 + public void update(FirmwareUpdateResult result) {
  43 + this.result = result;
  44 + switch (result) {
  45 + case INITIAL:
  46 + break;
  47 + case UPDATE_SUCCESSFULLY:
  48 + retryAttempts = 0;
  49 + break;
  50 + default:
  51 + failedPackageId = getPackageId(targetName, targetVersion);
  52 + break;
  53 + }
  54 + }
  55 +
  56 +}
... ...
  1 +/**
  2 + * Copyright © 2016-2021 The Thingsboard Authors
  3 + *
  4 + * Licensed under the Apache License, Version 2.0 (the "License");
  5 + * you may not use this file except in compliance with the License.
  6 + * You may obtain a copy of the License at
  7 + *
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + *
  10 + * Unless required by applicable law or agreed to in writing, software
  11 + * distributed under the License is distributed on an "AS IS" BASIS,
  12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 + * See the License for the specific language governing permissions and
  14 + * limitations under the License.
  15 + */
  16 +package org.thingsboard.server.transport.lwm2m.server.ota.software;
  17 +
  18 +import com.fasterxml.jackson.annotation.JsonIgnore;
  19 +import lombok.Data;
  20 +import lombok.EqualsAndHashCode;
  21 +import lombok.NoArgsConstructor;
  22 +import org.thingsboard.server.common.data.StringUtils;
  23 +import org.thingsboard.server.common.data.ota.OtaPackageType;
  24 +import org.thingsboard.server.transport.lwm2m.server.ota.LwM2MClientOtaInfo;
  25 +import org.thingsboard.server.transport.lwm2m.server.ota.firmware.FirmwareUpdateResult;
  26 +import org.thingsboard.server.transport.lwm2m.server.ota.firmware.FirmwareUpdateState;
  27 +import org.thingsboard.server.transport.lwm2m.server.ota.firmware.LwM2MFirmwareUpdateStrategy;
  28 +
  29 +@Data
  30 +@EqualsAndHashCode(callSuper = true)
  31 +@NoArgsConstructor
  32 +public class LwM2MClientSwOtaInfo extends LwM2MClientOtaInfo<LwM2MSoftwareUpdateStrategy, SoftwareUpdateState, SoftwareUpdateResult> {
  33 +
  34 + public LwM2MClientSwOtaInfo(String endpoint, String baseUrl, LwM2MSoftwareUpdateStrategy strategy) {
  35 + super(endpoint, baseUrl, strategy);
  36 + }
  37 +
  38 + @JsonIgnore
  39 + @Override
  40 + public OtaPackageType getType() {
  41 + return OtaPackageType.SOFTWARE;
  42 + }
  43 +
  44 +
  45 + public void update(SoftwareUpdateResult result) {
  46 + this.result = result;
  47 + switch (result) {
  48 + case INITIAL:
  49 + break;
  50 + //TODO: implement
  51 + default:
  52 + failedPackageId = getPackageId(targetName, targetVersion);
  53 + break;
  54 + }
  55 + }
  56 +
  57 +}
... ...
... ... @@ -15,6 +15,8 @@
15 15 */
16 16 package org.thingsboard.server.transport.lwm2m.server.ota.software;
17 17
  18 +import lombok.Getter;
  19 +
18 20 /**
19 21 * SW Update Result
20 22 * Contains the result of downloading or installing/uninstalling the software
... ... @@ -56,6 +58,7 @@ public enum SoftwareUpdateResult {
56 58
57 59 public int code;
58 60 public String type;
  61 + @Getter
59 62 public boolean isAgain;
60 63
61 64 SoftwareUpdateResult(int code, String type, boolean isAgain) {
... ...
... ... @@ -82,7 +82,7 @@ public class DefaultLwM2MRpcRequestHandler implements LwM2MRpcRequestHandler {
82 82 public void onToDeviceRpcRequest(TransportProtos.ToDeviceRpcRequestMsg rpcRequst, TransportProtos.SessionInfoProto sessionInfo) {
83 83 this.cleanupOldSessions();
84 84 UUID requestUUID = new UUID(rpcRequst.getRequestIdMSB(), rpcRequst.getRequestIdLSB());
85   - log.warn("Received params: {}", rpcRequst.getParams());
  85 + log.debug("Received params: {}", rpcRequst.getParams());
86 86 // We use this map to protect from browser issue that the same command is sent twice.
87 87 // TODO: This is probably not the best place and should be moved to DeviceActor
88 88 if (!this.rpcSubscriptions.containsKey(requestUUID)) {
... ... @@ -308,20 +308,19 @@ public class DefaultLwM2MRpcRequestHandler implements LwM2MRpcRequestHandler {
308 308 }
309 309
310 310 private void cleanupOldSessions() {
311   - log.warn("4.1) before rpcSubscriptions.size(): [{}]", rpcSubscriptions.size());
  311 + log.debug("Before rpcSubscriptions.size(): [{}]", rpcSubscriptions.size());
312 312 if (rpcSubscriptions.size() > 0) {
313 313 long currentTime = System.currentTimeMillis();
314 314 Set<UUID> rpcSubscriptionsToRemove = rpcSubscriptions.entrySet().stream().filter(kv -> currentTime > kv.getValue()).map(Map.Entry::getKey).collect(Collectors.toSet());
315   - log.warn("4.2) System.currentTimeMillis(): [{}]", System.currentTimeMillis());
316   - log.warn("4.3) rpcSubscriptionsToRemove: [{}]", rpcSubscriptionsToRemove);
  315 + log.debug("RpcSubscriptionsToRemove: [{}]", rpcSubscriptionsToRemove);
317 316 rpcSubscriptionsToRemove.forEach(rpcSubscriptions::remove);
318 317 }
319   - log.warn("4.4) after rpcSubscriptions.size(): [{}]", rpcSubscriptions.size());
  318 + log.debug("After rpcSubscriptions.size(): [{}]", rpcSubscriptions.size());
320 319 }
321 320
322 321 @Override
323 322 public void onToDeviceRpcResponse(TransportProtos.ToDeviceRpcResponseMsg toDeviceResponse, TransportProtos.SessionInfoProto sessionInfo) {
324   - log.warn("5) onToDeviceRpcResponse: [{}], sessionUUID: [{}]", toDeviceResponse, new UUID(sessionInfo.getSessionIdMSB(), sessionInfo.getSessionIdLSB()));
  323 + log.debug("OnToDeviceRpcResponse: [{}], sessionUUID: [{}]", toDeviceResponse, new UUID(sessionInfo.getSessionIdMSB(), sessionInfo.getSessionIdLSB()));
325 324 transportService.process(sessionInfo, toDeviceResponse, null);
326 325 }
327 326
... ...
... ... @@ -15,18 +15,28 @@
15 15 */
16 16 package org.thingsboard.server.transport.lwm2m.server.store;
17 17
18   -import org.thingsboard.server.common.data.ota.OtaPackageType;
19   -import org.thingsboard.server.transport.lwm2m.server.ota.LwM2MClientOtaInfo;
  18 +import org.thingsboard.server.transport.lwm2m.server.ota.firmware.LwM2MClientFwOtaInfo;
  19 +import org.thingsboard.server.transport.lwm2m.server.ota.software.LwM2MClientSwOtaInfo;
20 20
21 21 public class TbDummyLwM2MClientOtaInfoStore implements TbLwM2MClientOtaInfoStore {
22 22
23 23 @Override
24   - public LwM2MClientOtaInfo get(OtaPackageType type, String endpoint) {
  24 + public LwM2MClientFwOtaInfo getFw(String endpoint) {
25 25 return null;
26 26 }
27 27
28 28 @Override
29   - public void put(LwM2MClientOtaInfo info) {
  29 + public LwM2MClientSwOtaInfo getSw(String endpoint) {
  30 + return null;
  31 + }
  32 +
  33 + @Override
  34 + public void putFw(LwM2MClientFwOtaInfo info) {
  35 +
  36 + }
  37 +
  38 + @Override
  39 + public void putSw(LwM2MClientSwOtaInfo info) {
30 40
31 41 }
32 42 }
... ...
... ... @@ -17,10 +17,16 @@ package org.thingsboard.server.transport.lwm2m.server.store;
17 17
18 18 import org.thingsboard.server.common.data.ota.OtaPackageType;
19 19 import org.thingsboard.server.transport.lwm2m.server.ota.LwM2MClientOtaInfo;
  20 +import org.thingsboard.server.transport.lwm2m.server.ota.firmware.LwM2MClientFwOtaInfo;
  21 +import org.thingsboard.server.transport.lwm2m.server.ota.software.LwM2MClientSwOtaInfo;
20 22
21 23 public interface TbLwM2MClientOtaInfoStore {
22 24
23   - LwM2MClientOtaInfo get(OtaPackageType type, String endpoint);
  25 + LwM2MClientFwOtaInfo getFw(String endpoint);
24 26
25   - void put(LwM2MClientOtaInfo info);
  27 + LwM2MClientSwOtaInfo getSw(String endpoint);
  28 +
  29 + void putFw(LwM2MClientFwOtaInfo info);
  30 +
  31 + void putSw(LwM2MClientSwOtaInfo info);
26 32 }
... ...
... ... @@ -17,6 +17,7 @@ package org.thingsboard.server.transport.lwm2m.server.store;
17 17
18 18 import org.eclipse.leshan.server.security.NonUniqueSecurityInfoException;
19 19 import org.eclipse.leshan.server.security.SecurityInfo;
  20 +import org.jetbrains.annotations.Nullable;
20 21 import org.nustaq.serialization.FSTConfiguration;
21 22 import org.springframework.data.redis.connection.RedisConnectionFactory;
22 23 import org.springframework.integration.redis.util.RedisLockRegistry;
... ... @@ -24,6 +25,8 @@ import org.thingsboard.common.util.JacksonUtil;
24 25 import org.thingsboard.server.common.data.ota.OtaPackageType;
25 26 import org.thingsboard.server.transport.lwm2m.secure.TbLwM2MSecurityInfo;
26 27 import org.thingsboard.server.transport.lwm2m.server.ota.LwM2MClientOtaInfo;
  28 +import org.thingsboard.server.transport.lwm2m.server.ota.firmware.LwM2MClientFwOtaInfo;
  29 +import org.thingsboard.server.transport.lwm2m.server.ota.software.LwM2MClientSwOtaInfo;
27 30
28 31 import java.util.concurrent.locks.Lock;
29 32
... ... @@ -36,19 +39,36 @@ public class TbLwM2mRedisClientOtaInfoStore implements TbLwM2MClientOtaInfoStore
36 39 this.connectionFactory = connectionFactory;
37 40 }
38 41
39   - @Override
40   - public LwM2MClientOtaInfo get(OtaPackageType type, String endpoint) {
  42 + private void put(OtaPackageType type, LwM2MClientOtaInfo<?, ?, ?> info) {
41 43 try (var connection = connectionFactory.getConnection()) {
42   - byte[] data = connection.get((OTA_EP + type + endpoint).getBytes());
43   - return JacksonUtil.fromBytes(data, LwM2MClientOtaInfo.class);
  44 + connection.set((OTA_EP + type + info.getEndpoint()).getBytes(), JacksonUtil.toString(info).getBytes());
44 45 }
45 46 }
46 47
47 48 @Override
48   - public void put(LwM2MClientOtaInfo info) {
  49 + public LwM2MClientFwOtaInfo getFw(String endpoint) {
  50 + return getLwM2MClientOtaInfo(OtaPackageType.FIRMWARE, endpoint, LwM2MClientFwOtaInfo.class);
  51 + }
  52 +
  53 + @Override
  54 + public void putFw(LwM2MClientFwOtaInfo info) {
  55 + put(OtaPackageType.FIRMWARE, info);
  56 + }
  57 +
  58 + @Override
  59 + public LwM2MClientSwOtaInfo getSw(String endpoint) {
  60 + return getLwM2MClientOtaInfo(OtaPackageType.SOFTWARE, endpoint, LwM2MClientSwOtaInfo.class);
  61 + }
  62 +
  63 + @Override
  64 + public void putSw(LwM2MClientSwOtaInfo info) {
  65 + put(OtaPackageType.SOFTWARE, info);
  66 + }
  67 +
  68 + private <T extends LwM2MClientOtaInfo<?, ?, ?>> T getLwM2MClientOtaInfo(OtaPackageType type, String endpoint, Class<T> clazz) {
49 69 try (var connection = connectionFactory.getConnection()) {
50   - connection.set((OTA_EP + info.getType() + info.getEndpoint()).getBytes(), JacksonUtil.toString(info).getBytes());
  70 + byte[] data = connection.get((OTA_EP + type + endpoint).getBytes());
  71 + return JacksonUtil.fromBytes(data, clazz);
51 72 }
52 73 }
53   -
54 74 }
... ...
... ... @@ -90,7 +90,6 @@ import javax.annotation.PreDestroy;
90 90 import java.util.ArrayList;
91 91 import java.util.Collection;
92 92 import java.util.Collections;
93   -import java.util.HashMap;
94 93 import java.util.HashSet;
95 94 import java.util.List;
96 95 import java.util.Map;
... ... @@ -111,11 +110,16 @@ import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.c
111 110 import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.convertOtaUpdateValueToString;
112 111 import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.fromVersionedIdToObjectId;
113 112 import static org.thingsboard.server.transport.lwm2m.server.ota.DefaultLwM2MOtaUpdateService.FW_3_VER_ID;
114   -import static org.thingsboard.server.transport.lwm2m.server.ota.DefaultLwM2MOtaUpdateService.FW_5_VER_ID;
  113 +import static org.thingsboard.server.transport.lwm2m.server.ota.DefaultLwM2MOtaUpdateService.FW_VER_ID;
115 114 import static org.thingsboard.server.transport.lwm2m.server.ota.DefaultLwM2MOtaUpdateService.FW_DELIVERY_METHOD;
116 115 import static org.thingsboard.server.transport.lwm2m.server.ota.DefaultLwM2MOtaUpdateService.FW_NAME_ID;
117 116 import static org.thingsboard.server.transport.lwm2m.server.ota.DefaultLwM2MOtaUpdateService.FW_RESULT_ID;
118 117 import static org.thingsboard.server.transport.lwm2m.server.ota.DefaultLwM2MOtaUpdateService.FW_STATE_ID;
  118 +import static org.thingsboard.server.transport.lwm2m.server.ota.DefaultLwM2MOtaUpdateService.SW_3_VER_ID;
  119 +import static org.thingsboard.server.transport.lwm2m.server.ota.DefaultLwM2MOtaUpdateService.SW_NAME_ID;
  120 +import static org.thingsboard.server.transport.lwm2m.server.ota.DefaultLwM2MOtaUpdateService.SW_RESULT_ID;
  121 +import static org.thingsboard.server.transport.lwm2m.server.ota.DefaultLwM2MOtaUpdateService.SW_STATE_ID;
  122 +import static org.thingsboard.server.transport.lwm2m.server.ota.DefaultLwM2MOtaUpdateService.SW_VER_ID;
119 123
120 124
121 125 @Slf4j
... ... @@ -238,7 +242,7 @@ public class DefaultLwM2MUplinkMsgHandler extends LwM2MExecutorAwareService impl
238 242 executor.submit(() -> {
239 243 LwM2mClient lwM2MClient = clientContext.getClientByEndpoint(registration.getEndpoint());
240 244 try {
241   - log.warn("[{}] [{{}] Client: update after Registration", registration.getEndpoint(), registration.getId());
  245 + log.info("[{}] [{{}] Client: update after Registration", registration.getEndpoint(), registration.getId());
242 246 logService.log(lwM2MClient, String.format("[%s][%s] Updated registration.", registration.getId(), registration.getSocketAddress()));
243 247 clientContext.updateRegistration(lwM2MClient, registration);
244 248 this.reportActivityAndRegister(lwM2MClient.getSession());
... ... @@ -318,7 +322,7 @@ public class DefaultLwM2MUplinkMsgHandler extends LwM2MExecutorAwareService impl
318 322 }
319 323
320 324 public void onUpdateValueAfterReadCompositeResponse(Registration registration, ReadCompositeResponse response) {
321   - log.warn("201) ReadCompositeResponse: [{}]", response);
  325 + log.trace("ReadCompositeResponse: [{}]", response);
322 326 if (response.getContent() != null) {
323 327 LwM2mClient lwM2MClient = clientContext.getClientByEndpoint(registration.getEndpoint());
324 328 response.getContent().forEach((k, v) -> {
... ... @@ -407,19 +411,7 @@ public class DefaultLwM2MUplinkMsgHandler extends LwM2MExecutorAwareService impl
407 411 Lwm2mDeviceProfileTransportConfiguration profile = clientContext.getProfile(lwM2MClient.getProfileId());
408 412 Set<String> supportedObjects = clientContext.getSupportedIdVerInClient(lwM2MClient);
409 413 if (supportedObjects != null && supportedObjects.size() > 0) {
410   - // #1
411 414 this.sendReadRequests(lwM2MClient, profile, supportedObjects);
412   - // test composite
413   - String[] paths = new String[]{"/3/0", "/1/0", "/5/0"};
414   -// String [] paths = new String[] {"/5"};
415   -// String [] paths = new String[] {"/"};
416   -// String [] paths = new String[] {"/9"};
417   -// defaultLwM2MDownlinkMsgHandler.sendReadCompositeRequest(lwM2MClient, paths, this);
418   - Map<String, Object> nodes = new HashMap<>();
419   - nodes.put("/3/0/14", "+02");
420   - nodes.put("/1/0/2", 100);
421   - nodes.put("/5/0/1", "coap://localhost:5685");
422   -// defaultLwM2MDownlinkMsgHandler.sendWriteCompositeRequest(lwM2MClient, nodes, this);
423 415 this.sendObserveRequests(lwM2MClient, profile, supportedObjects);
424 416 this.sendWriteAttributeRequests(lwM2MClient, profile, supportedObjects);
425 417 // Removed. Used only for debug.
... ... @@ -531,14 +523,24 @@ public class DefaultLwM2MUplinkMsgHandler extends LwM2MExecutorAwareService impl
531 523 otaService.onCurrentFirmwareNameUpdate(lwM2MClient, (String) lwM2mResource.getValue());
532 524 } else if (path.equals(convertObjectIdToVersionedId(FW_3_VER_ID, registration))) {
533 525 otaService.onCurrentFirmwareVersion3Update(lwM2MClient, (String) lwM2mResource.getValue());
534   - } else if (path.equals(convertObjectIdToVersionedId(FW_5_VER_ID, registration))) {
535   - otaService.onCurrentFirmwareVersion5Update(lwM2MClient, (String) lwM2mResource.getValue());
  526 + } else if (path.equals(convertObjectIdToVersionedId(FW_VER_ID, registration))) {
  527 + otaService.onCurrentFirmwareVersionUpdate(lwM2MClient, (String) lwM2mResource.getValue());
536 528 } else if (path.equals(convertObjectIdToVersionedId(FW_STATE_ID, registration))) {
537 529 otaService.onCurrentFirmwareStateUpdate(lwM2MClient, (Long) lwM2mResource.getValue());
538 530 } else if (path.equals(convertObjectIdToVersionedId(FW_RESULT_ID, registration))) {
539 531 otaService.onCurrentFirmwareResultUpdate(lwM2MClient, (Long) lwM2mResource.getValue());
540 532 } else if (path.equals(convertObjectIdToVersionedId(FW_DELIVERY_METHOD, registration))) {
541 533 otaService.onCurrentFirmwareDeliveryMethodUpdate(lwM2MClient, (Long) lwM2mResource.getValue());
  534 + } else if (path.equals(convertObjectIdToVersionedId(SW_NAME_ID, registration))) {
  535 + otaService.onCurrentSoftwareNameUpdate(lwM2MClient, (String) lwM2mResource.getValue());
  536 + } else if (path.equals(convertObjectIdToVersionedId(SW_VER_ID, registration))) {
  537 + otaService.onCurrentSoftwareVersionUpdate(lwM2MClient, (String) lwM2mResource.getValue());
  538 + } else if (path.equals(convertObjectIdToVersionedId(SW_3_VER_ID, registration))) {
  539 + otaService.onCurrentSoftwareVersion3Update(lwM2MClient, (String) lwM2mResource.getValue());
  540 + } else if (path.equals(convertObjectIdToVersionedId(SW_STATE_ID, registration))) {
  541 + otaService.onCurrentSoftwareStateUpdate(lwM2MClient, (Long) lwM2mResource.getValue());
  542 + } else if (path.equals(convertObjectIdToVersionedId(SW_RESULT_ID, registration))) {
  543 + otaService.onCurrentSoftwareResultUpdate(lwM2MClient, (Long) lwM2mResource.getValue());
542 544 }
543 545 this.updateAttrTelemetry(registration, Collections.singleton(path));
544 546 } else {
... ... @@ -698,7 +700,7 @@ public class DefaultLwM2MUplinkMsgHandler extends LwM2MExecutorAwareService impl
698 700
699 701 @Override
700 702 public void onWriteCompositeResponseOk(LwM2mClient client, WriteCompositeRequest request) {
701   - log.warn("202) ReadCompositeResponse: [{}]", request.getNodes());
  703 + log.trace("ReadCompositeResponse: [{}]", request.getNodes());
702 704 request.getNodes().forEach((k, v) -> {
703 705 this.updateResourcesValue(client, (LwM2mResource) v, k.toString());
704 706 });
... ...