Browse Source

LWM2M: front add coap resource URI

pull/4724/head
nickAS21 5 years ago
committed by Andrew Shvayka
parent
commit
308650a308
  1. 21
      common/transport/coap/src/main/java/org/thingsboard/server/transport/coap/CoapTransportResource.java
  2. 8
      common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/DefaultLwM2MTransportMsgHandler.java
  3. 38
      common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/LwM2mTransportCoapResource.java
  4. 16
      common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/client/LwM2mClientContextImpl.java
  5. 11
      common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/client/LwM2mFwSwUpdate.java
  6. 128
      ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-device-profile-transport-configuration.component.html
  7. 80
      ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-device-profile-transport-configuration.component.ts
  8. 15
      ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-profile-config.models.ts
  9. 5
      ui-ngx/src/assets/locale/locale.constant-en_US.json

21
common/transport/coap/src/main/java/org/thingsboard/server/transport/coap/CoapTransportResource.java

@ -398,7 +398,7 @@ public class CoapTransportResource extends AbstractCoapTransportResource {
private Optional<DeviceTokenCredentials> decodeCredentials(Request request) { private Optional<DeviceTokenCredentials> decodeCredentials(Request request) {
List<String> uriPath = request.getOptions().getUriPath(); List<String> uriPath = request.getOptions().getUriPath();
if (uriPath.size() > ACCESS_TOKEN_POSITION) { if (uriPath.size() >= ACCESS_TOKEN_POSITION) {
return Optional.of(new DeviceTokenCredentials(uriPath.get(ACCESS_TOKEN_POSITION - 1))); return Optional.of(new DeviceTokenCredentials(uriPath.get(ACCESS_TOKEN_POSITION - 1)));
} else { } else {
return Optional.empty(); return Optional.empty();
@ -482,13 +482,16 @@ public class CoapTransportResource extends AbstractCoapTransportResource {
String title = exchange.getQueryParameter("title"); String title = exchange.getQueryParameter("title");
String version = exchange.getQueryParameter("version"); String version = exchange.getQueryParameter("version");
if (msg.getResponseStatus().equals(TransportProtos.ResponseStatus.SUCCESS)) { if (msg.getResponseStatus().equals(TransportProtos.ResponseStatus.SUCCESS)) {
String firmwareId = new UUID(msg.getOtaPackageIdMSB(), msg.getOtaPackageIdLSB()).toString();
if (msg.getTitle().equals(title) && msg.getVersion().equals(version)) { if (msg.getTitle().equals(title) && msg.getVersion().equals(version)) {
String firmwareId = new UUID(msg.getOtaPackageIdMSB(), msg.getOtaPackageIdLSB()).toString();
String strChunkSize = exchange.getQueryParameter("size"); String strChunkSize = exchange.getQueryParameter("size");
String strChunk = exchange.getQueryParameter("chunk"); String strChunk = exchange.getQueryParameter("chunk");
int chunkSize = StringUtils.isEmpty(strChunkSize) ? 0 : Integer.parseInt(strChunkSize); int chunkSize = StringUtils.isEmpty(strChunkSize) ? 0 : Integer.parseInt(strChunkSize);
int chunk = StringUtils.isEmpty(strChunk) ? 0 : Integer.parseInt(strChunk); int chunk = StringUtils.isEmpty(strChunk) ? 0 : Integer.parseInt(strChunk);
exchange.respond(CoAP.ResponseCode.CONTENT, transportContext.getOtaPackageDataCache().get(firmwareId, chunkSize, chunk)); exchange.respond(CoAP.ResponseCode.CONTENT, transportContext.getOtaPackageDataCache().get(firmwareId, chunkSize, chunk));
}
else if (firmwareId != null) {
sendOtaData(exchange, firmwareId);
} else { } else {
exchange.respond(CoAP.ResponseCode.BAD_REQUEST); exchange.respond(CoAP.ResponseCode.BAD_REQUEST);
} }
@ -504,6 +507,20 @@ public class CoapTransportResource extends AbstractCoapTransportResource {
} }
} }
private void sendOtaData(CoapExchange exchange, String firmwareId) {
Response response = new Response(CoAP.ResponseCode.CONTENT);
byte[] fwData = transportContext.getOtaPackageDataCache().get(firmwareId);
if (fwData != null && fwData.length > 0) {
response.setPayload(fwData);
if (exchange.getRequestOptions().getBlock2() != null) {
int chunkSize = exchange.getRequestOptions().getBlock2().getSzx();
boolean moreFlag = fwData.length > chunkSize;
response.getOptions().setBlock2(chunkSize, moreFlag, 0);
}
exchange.respond(response);
}
}
private static class CoapSessionListener implements SessionMsgListener { private static class CoapSessionListener implements SessionMsgListener {
private final CoapTransportResource coapTransportResource; private final CoapTransportResource coapTransportResource;

8
common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/DefaultLwM2MTransportMsgHandler.java

@ -41,10 +41,10 @@ import org.thingsboard.common.util.ThingsBoardExecutors;
import org.thingsboard.server.cache.ota.OtaPackageDataCache; import org.thingsboard.server.cache.ota.OtaPackageDataCache;
import org.thingsboard.server.common.data.Device; import org.thingsboard.server.common.data.Device;
import org.thingsboard.server.common.data.DeviceProfile; import org.thingsboard.server.common.data.DeviceProfile;
import org.thingsboard.server.common.data.id.OtaPackageId;
import org.thingsboard.server.common.data.ota.OtaPackageKey; import org.thingsboard.server.common.data.ota.OtaPackageKey;
import org.thingsboard.server.common.data.ota.OtaPackageType; import org.thingsboard.server.common.data.ota.OtaPackageType;
import org.thingsboard.server.common.data.ota.OtaPackageUtil; import org.thingsboard.server.common.data.ota.OtaPackageUtil;
import org.thingsboard.server.common.data.id.OtaPackageId;
import org.thingsboard.server.common.transport.TransportService; import org.thingsboard.server.common.transport.TransportService;
import org.thingsboard.server.common.transport.TransportServiceCallback; import org.thingsboard.server.common.transport.TransportServiceCallback;
import org.thingsboard.server.common.transport.adaptor.AdaptorException; import org.thingsboard.server.common.transport.adaptor.AdaptorException;
@ -89,11 +89,9 @@ import java.util.stream.Collectors;
import static org.eclipse.californium.core.coap.CoAP.ResponseCode.BAD_REQUEST; import static org.eclipse.californium.core.coap.CoAP.ResponseCode.BAD_REQUEST;
import static org.eclipse.leshan.core.attributes.Attribute.OBJECT_VERSION; import static org.eclipse.leshan.core.attributes.Attribute.OBJECT_VERSION;
import static org.thingsboard.server.common.data.ota.OtaPackageUpdateStatus.DOWNLOADED; import static org.thingsboard.server.common.data.lwm2m.LwM2mConstants.LWM2M_SEPARATOR_PATH;
import static org.thingsboard.server.common.data.ota.OtaPackageUpdateStatus.FAILED; import static org.thingsboard.server.common.data.ota.OtaPackageUpdateStatus.FAILED;
import static org.thingsboard.server.common.data.ota.OtaPackageUpdateStatus.INITIATED; import static org.thingsboard.server.common.data.ota.OtaPackageUpdateStatus.INITIATED;
import static org.thingsboard.server.common.data.ota.OtaPackageUpdateStatus.UPDATING;
import static org.thingsboard.server.common.data.lwm2m.LwM2mConstants.LWM2M_SEPARATOR_PATH;
import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportServerHelper.getValueFromKvProto; import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportServerHelper.getValueFromKvProto;
import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.DEVICE_ATTRIBUTES_REQUEST; import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.DEVICE_ATTRIBUTES_REQUEST;
import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.FW_5_ID; import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.FW_5_ID;
@ -267,8 +265,8 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler
clientContext.unregister(client, registration); clientContext.unregister(client, registration);
SessionInfoProto sessionInfo = client.getSession(); SessionInfoProto sessionInfo = client.getSession();
if (sessionInfo != null) { if (sessionInfo != null) {
transportService.deregisterSession(sessionInfo);
this.doCloseSession(sessionInfo); this.doCloseSession(sessionInfo);
transportService.deregisterSession(sessionInfo);
sessionStore.remove(registration.getEndpoint()); sessionStore.remove(registration.getEndpoint());
log.info("Client close session: [{}] unReg [{}] name [{}] profile ", registration.getId(), registration.getEndpoint(), sessionInfo.getDeviceType()); log.info("Client close session: [{}] unReg [{}] name [{}] profile ", registration.getId(), registration.getEndpoint(), sessionInfo.getDeviceType());
} else { } else {

38
common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/LwM2mTransportCoapResource.java

@ -69,10 +69,10 @@ public class LwM2mTransportCoapResource extends AbstractLwM2mTransportResource {
@Override @Override
protected void processHandleGet(CoapExchange exchange) { protected void processHandleGet(CoapExchange exchange) {
log.warn("90) processHandleGet [{}]", exchange); log.warn("90) processHandleGet [{}]", exchange);
if (exchange.getRequestOptions().getUriPath().size() == 2 && if (exchange.getRequestOptions().getUriPath().size() >= 2 &&
(FIRMWARE_UPDATE_COAP_RECOURSE.equals(exchange.getRequestOptions().getUriPath().get(0)) || (FIRMWARE_UPDATE_COAP_RECOURSE.equals(exchange.getRequestOptions().getUriPath().get(exchange.getRequestOptions().getUriPath().size()-2)) ||
SOFTWARE_UPDATE_COAP_RECOURSE.equals(exchange.getRequestOptions().getUriPath().get(0)))) { SOFTWARE_UPDATE_COAP_RECOURSE.equals(exchange.getRequestOptions().getUriPath().get(exchange.getRequestOptions().getUriPath().size()-2)))) {
this.sentOtaData(exchange); this.sendOtaData(exchange);
} }
} }
@ -129,23 +129,25 @@ public class LwM2mTransportCoapResource extends AbstractLwM2mTransportResource {
} }
} }
private void sentOtaData(CoapExchange exchange) { private void sendOtaData(CoapExchange exchange) {
String idStr = exchange.getRequestOptions().getUriPath().get(1); String idStr = exchange.getRequestOptions().getUriPath().get(exchange.getRequestOptions().getUriPath().size()-1
);
UUID currentId = UUID.fromString(idStr); UUID currentId = UUID.fromString(idStr);
if (exchange.getRequestOptions().getBlock2() != null) { Response response = new Response(CoAP.ResponseCode.CONTENT);
int chunkSize = exchange.getRequestOptions().getBlock2().getSzx(); byte[] fwData = this.getOtaData(currentId);
int chunk = 0; log.warn("91) read softWare data (length): [{}]", fwData.length);
Response response = new Response(CoAP.ResponseCode.CONTENT); if (fwData != null && fwData.length > 0) {
byte[] fwData = this.getOtaData(currentId); response.setPayload(fwData);
log.warn("91) read softWare data (length): [{}]", fwData.length); if (exchange.getRequestOptions().getBlock2() != null) {
if (fwData != null && fwData.length > 0) { int chunkSize = exchange.getRequestOptions().getBlock2().getSzx();
response.setPayload(fwData);
boolean moreFlag = fwData.length > chunkSize; boolean moreFlag = fwData.length > chunkSize;
response.getOptions().setBlock2(chunkSize, moreFlag, chunk); response.getOptions().setBlock2(chunkSize, moreFlag, 0);
log.warn("92) Send currentId: [{}], length: [{}], chunkSize [{}], moreFlag [{}]", currentId.toString(), fwData.length, chunkSize, moreFlag); log.warn("92) with blokc2 Send currentId: [{}], length: [{}], chunkSize [{}], moreFlag [{}]", currentId.toString(), fwData.length, chunkSize, moreFlag);
exchange.respond(response);
} }
else {
log.warn("92) with block1 Send currentId: [{}], length: [{}], ", currentId.toString(), fwData.length);
}
exchange.respond(response);
} }
} }

16
common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/client/LwM2mClientContextImpl.java

@ -36,6 +36,7 @@ import java.util.Optional;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Predicate;
import static org.eclipse.leshan.core.SecurityMode.NO_SEC; import static org.eclipse.leshan.core.SecurityMode.NO_SEC;
import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.convertPathFromObjectIdToIdVer; import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.convertPathFromObjectIdToIdVer;
@ -137,14 +138,19 @@ public class LwM2mClientContextImpl implements LwM2mClientContext {
@Override @Override
public LwM2mClient getClientBySessionInfo(TransportProtos.SessionInfoProto sessionInfo) { public LwM2mClient getClientBySessionInfo(TransportProtos.SessionInfoProto sessionInfo) {
LwM2mClient lwM2mClient = lwM2mClientsByEndpoint.values().stream().filter(c -> LwM2mClient lwM2mClient = null;
Predicate<LwM2mClient> isClientFilter = c ->
(new UUID(sessionInfo.getSessionIdMSB(), sessionInfo.getSessionIdLSB())) (new UUID(sessionInfo.getSessionIdMSB(), sessionInfo.getSessionIdLSB()))
.equals((new UUID(c.getSession().getSessionIdMSB(), c.getSession().getSessionIdLSB()))) .equals((new UUID(c.getSession().getSessionIdMSB(), c.getSession().getSessionIdLSB())));
if (this.lwM2mClientsByEndpoint.size() > 0) {
).findAny().orElse(null); lwM2mClient = this.lwM2mClientsByEndpoint.values().stream().filter(isClientFilter).findAny().orElse(null);
}
if (lwM2mClient == null && this.lwM2mClientsByRegistrationId.size() > 0) {
lwM2mClient = this.lwM2mClientsByRegistrationId.values().stream().filter(isClientFilter).findAny().orElse(null);
}
if (lwM2mClient == null) { if (lwM2mClient == null) {
log.warn("Device TimeOut? lwM2mClient is null."); log.warn("Device TimeOut? lwM2mClient is null.");
log.warn("SessionInfo input [{}], lwM2mClientsByEndpoint size: [{}]", sessionInfo, lwM2mClientsByEndpoint.values().size()); log.warn("SessionInfo input [{}], lwM2mClientsByEndpoint size: [{}] lwM2mClientsByRegistrationId: [{}]", sessionInfo, lwM2mClientsByEndpoint.values(), lwM2mClientsByRegistrationId.values());
log.error("", new RuntimeException()); log.error("", new RuntimeException());
} }
return lwM2mClient; return lwM2mClient;

11
common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/client/LwM2mFwSwUpdate.java

@ -61,6 +61,7 @@ import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.L
import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.LwM2MFirmwareUpdateStrategy.OBJ_5_TEMP_URL; import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.LwM2MFirmwareUpdateStrategy.OBJ_5_TEMP_URL;
import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.LwM2mTypeOper.EXECUTE; import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.LwM2mTypeOper.EXECUTE;
import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.LwM2mTypeOper.OBSERVE; import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.LwM2mTypeOper.OBSERVE;
import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.LwM2mTypeOper.READ;
import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.LwM2mTypeOper.WRITE_REPLACE; import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.LwM2mTypeOper.WRITE_REPLACE;
import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.SW_INSTALL_ID; import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.SW_INSTALL_ID;
import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.SW_NAME_ID; import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.SW_NAME_ID;
@ -194,11 +195,17 @@ public class LwM2mFwSwUpdate {
} else if (LwM2mTransportUtil.LwM2MFirmwareUpdateStrategy.OBJ_5_TEMP_URL.code == this.updateStrategy) { } else if (LwM2mTransportUtil.LwM2MFirmwareUpdateStrategy.OBJ_5_TEMP_URL.code == this.updateStrategy) {
Registration registration = this.getLwM2MClient().getRegistration(); Registration registration = this.getLwM2MClient().getRegistration();
// String api = handler.config.getHostRequests(); // String api = handler.config.getHostRequests();
String api = "0.0.0.0"; String api = "176.36.143.9";
int port = registration.getIdentity().isSecure() ? handler.config.getSecurePort() : handler.config.getPort(); int port = registration.getIdentity().isSecure() ? handler.config.getSecurePort() : handler.config.getPort();
// String uri = "coap://" + api + ":" + Integer.valueOf(port) + "/" + "api/v1/test_url" + "/" + this.currentId.toString();
String uri = "coap://" + api + ":" + Integer.valueOf(port) + "/" + FIRMWARE_UPDATE_COAP_RECOURSE + "/" + this.currentId.toString(); String uri = "coap://" + api + ":" + Integer.valueOf(port) + "/" + FIRMWARE_UPDATE_COAP_RECOURSE + "/" + this.currentId.toString();
// home
// String uri = "coap://176.100.5.79:5683/api/v1/test_url/firmware";
// office
// String uri = "coap://176.36.143.9:5683/api/v1/test_url/firmware";
log.warn("89) coapUri: [{}]", uri); log.warn("89) coapUri: [{}]", uri);
request.sendAllRequest(this.lwM2MClient, targetIdVer, WRITE_REPLACE, null, // request.sendAllRequest(this.lwM2MClient, targetIdVer, WRITE_REPLACE, null,
request.sendAllRequest(this.lwM2MClient, targetIdVer, READ, null,
uri, handler.config.getTimeout(), this.rpcRequest); uri, handler.config.getTimeout(), this.rpcRequest);
} else if (LwM2mTransportUtil.LwM2MFirmwareUpdateStrategy.OBJ_19_BINARY.code == this.updateStrategy) { } else if (LwM2mTransportUtil.LwM2MFirmwareUpdateStrategy.OBJ_19_BINARY.code == this.updateStrategy) {

128
ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-device-profile-transport-configuration.component.html

@ -142,42 +142,98 @@
<mat-tab label="{{ 'device-profile.lwm2m.others-tab' | translate }}"> <mat-tab label="{{ 'device-profile.lwm2m.others-tab' | translate }}">
<ng-template matTabContent> <ng-template matTabContent>
<section [formGroup]="lwm2mDeviceProfileFormGroup"> <section [formGroup]="lwm2mDeviceProfileFormGroup">
<div *ngIf="false" class="mat-padding" style="padding-bottom: 0px"> <mat-accordion multi="true" class="mat-body-1">
<mat-form-field class="mat-block"> <div *ngIf="false">
<mat-label>{{ 'device-profile.lwm2m.client-strategy-label' | translate }}</mat-label> <mat-expansion-panel>
<mat-select formControlName="clientStrategy" <mat-expansion-panel-header>
matTooltip="{{ 'device-profile.lwm2m.client-strategy-tip' | translate: <mat-panel-title>
{ count: +lwm2mDeviceProfileFormGroup.get('clientStrategy').value } }}" <div
matTooltipPosition="above"> class="tb-panel-title">{{ 'device-profile.lwm2m.client-strategy' | translate | uppercase }}</div>
<mat-option value=1>{{ 'device-profile.lwm2m.client-strategy' | translate: </mat-panel-title>
{count: 1} }}</mat-option> </mat-expansion-panel-header>
<mat-option value=2>{{ 'device-profile.lwm2m.client-strategy' | translate: <ng-template matExpansionPanelContent>
{count: 2} }}</mat-option> <div fxLayout="column">
</mat-select> <mat-form-field class="mat-block">
</mat-form-field> <mat-label>{{ 'device-profile.lwm2m.client-strategy-label' | translate }}</mat-label>
</div> <mat-select formControlName="clientStrategy"
<div class="mat-padding" style="padding-bottom: 0px"> matTooltip="{{ 'device-profile.lwm2m.client-strategy-tip' | translate:
<mat-form-field class="mat-block"> { count: +lwm2mDeviceProfileFormGroup.get('clientStrategy').value } }}"
<mat-label>{{ 'device-profile.lwm2m.fw-update-strategy-label' | translate }}</mat-label> matTooltipPosition="above">
<mat-select formControlName="fwUpdateStrategy"> <mat-option value=1>{{ 'device-profile.lwm2m.client-strategy-connect' | translate:
<mat-option value=1>{{ 'device-profile.lwm2m.fw-update-strategy' | translate: {count: 1} }}</mat-option>
{count: 1} }}</mat-option> <mat-option value=2>{{ 'device-profile.lwm2m.client-strategy-connect' | translate:
<mat-option value=2>{{ 'device-profile.lwm2m.fw-update-strategy' | translate: {count: 2} }}</mat-option>
{count: 2} }}</mat-option> </mat-select>
<mat-option value=2>{{ 'device-profile.lwm2m.fw-update-strategy' | translate: </mat-form-field>
{count: 3} }}</mat-option> </div>
</mat-select> </ng-template>
</mat-form-field> </mat-expansion-panel>
<mat-form-field class="mat-block"> </div>
<mat-label>{{ 'device-profile.lwm2m.sw-update-strategy-label' | translate }}</mat-label> <mat-expansion-panel>
<mat-select formControlName="swUpdateStrategy"> <mat-expansion-panel-header>
<mat-option value=1>{{ 'device-profile.lwm2m.sw-update-strategy' | translate: <mat-panel-title>
{count: 1} }}</mat-option> <div
<mat-option value=2>{{ 'device-profile.lwm2m.sw-update-strategy' | translate: class="tb-panel-title">{{ 'device-profile.lwm2m.ota-update-strategy' | translate | uppercase }}</div>
{count: 2} }}</mat-option> </mat-panel-title>
</mat-select> </mat-expansion-panel-header>
</mat-form-field> <ng-template matExpansionPanelContent>
</div> <div fxLayout="column">
<mat-form-field class="mat-block" fxFlex>
<mat-label>{{ 'device-profile.lwm2m.fw-update-strategy-label' | translate }}</mat-label>
<mat-select formControlName="fwUpdateStrategy" (selectionChange)="changeFwUpdateStrategy($event)">
<mat-option value=1>{{ 'device-profile.lwm2m.fw-update-strategy' | translate:
{count: 1} }}</mat-option>
<mat-option value=2>{{ 'device-profile.lwm2m.fw-update-strategy' | translate:
{count: 2} }}</mat-option>
<mat-option value=3>{{ 'device-profile.lwm2m.fw-update-strategy' | translate:
{count: 3} }}</mat-option>
</mat-select>
</mat-form-field>
<mat-form-field class="mat-block" fxFlex>
<mat-label>{{ 'device-profile.lwm2m.sw-update-strategy-label' | translate }}</mat-label>
<mat-select formControlName="swUpdateStrategy" (selectionChange)="changeSwUpdateStrategy($event)">
<mat-option value=1>{{ 'device-profile.lwm2m.sw-update-strategy' | translate:
{count: 1} }}</mat-option>
<mat-option value=2>{{ 'device-profile.lwm2m.sw-update-strategy' | translate:
{count: 2} }}</mat-option>
</mat-select>
</mat-form-field>
</div>
</ng-template>
</mat-expansion-panel>
<mat-expansion-panel *ngIf="isFwUpdateStrategy || isSwUpdateStrategy">
<mat-expansion-panel-header>
<mat-panel-title>
<div
class="tb-panel-title">{{ 'device-profile.lwm2m.ota-update-recourse' | translate | uppercase }}</div>
</mat-panel-title>
</mat-expansion-panel-header>
<ng-template matExpansionPanelContent>
<div fxLayout="column">
<div *ngIf="isFwUpdateStrategy">
<mat-form-field class="mat-block" fxFlex>
<mat-label>{{ 'device-profile.lwm2m.fw-update-recourse' | translate }}</mat-label>
<input matInput formControlName="fwUpdateRecourse" required>
<mat-error *ngIf="lwm2mDeviceProfileFormGroup.get('fwUpdateRecourse').hasError('required')">
{{ 'device-profile.lwm2m.fw-update-recourse' | translate }}
<strong>{{ 'device-profile.lwm2m.required' | translate }}</strong>
</mat-error>
</mat-form-field>
</div>
<div *ngIf="isSwUpdateStrategy">
<mat-form-field class="mat-block" fxFlex>
<mat-label>{{ 'device-profile.lwm2m.sw-update-recourse' | translate }}</mat-label>
<input matInput formControlName="swUpdateRecourse" required>
<mat-error *ngIf="lwm2mDeviceProfileFormGroup.get('swUpdateRecourse').hasError('required')">
{{ 'device-profile.lwm2m.sw-update-recourse' | translate }}
<strong>{{ 'device-profile.lwm2m.required' | translate }}</strong>
</mat-error>
</mat-form-field>
</div>
</div>
</ng-template>
</mat-expansion-panel>
</mat-accordion>
</section> </section>
</ng-template> </ng-template>
</mat-tab> </mat-tab>

80
ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-device-profile-transport-configuration.component.ts

@ -22,6 +22,8 @@ import {
ATTRIBUTE, ATTRIBUTE,
BINDING_MODE, BINDING_MODE,
BINDING_MODE_NAMES, BINDING_MODE_NAMES,
DEFAULT_FW_UPDATE_RESOURCE,
DEFAULT_SW_UPDATE_RESOURCE,
getDefaultProfileConfig, getDefaultProfileConfig,
Instance, Instance,
INSTANCES, INSTANCES,
@ -41,6 +43,7 @@ import { Direction } from '@shared/models/page/sort-order';
import _ from 'lodash'; import _ from 'lodash';
import { Subject } from 'rxjs'; import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators'; import { takeUntil } from 'rxjs/operators';
import { MatSelectChange } from '@angular/material/select';
@Component({ @Component({
selector: 'tb-profile-lwm2m-device-transport-configuration', selector: 'tb-profile-lwm2m-device-transport-configuration',
@ -67,6 +70,8 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro
bootstrapServer: string; bootstrapServer: string;
lwm2mServer: string; lwm2mServer: string;
sortFunction: (key: string, value: object) => object; sortFunction: (key: string, value: object) => object;
isFwUpdateStrategy: boolean;
isSwUpdateStrategy: boolean;
get required(): boolean { get required(): boolean {
return this.requiredValue; return this.requiredValue;
@ -95,6 +100,8 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro
clientStrategy: [1, []], clientStrategy: [1, []],
fwUpdateStrategy: [1, []], fwUpdateStrategy: [1, []],
swUpdateStrategy: [1, []], swUpdateStrategy: [1, []],
fwUpdateRecourse: ['', []],
swUpdateRecourse: ['', []]
}); });
this.lwm2mDeviceConfigFormGroup = this.fb.group({ this.lwm2mDeviceConfigFormGroup = this.fb.group({
configurationJson: [null, Validators.required] configurationJson: [null, Validators.required]
@ -169,6 +176,13 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro
} }
private updateWriteValue = (value: ModelValue): void => { private updateWriteValue = (value: ModelValue): void => {
debugger
let fwResource = this.configurationValue.clientLwM2mSettings.fwUpdateStrategy === '2' &&
isDefinedAndNotNull(this.configurationValue.clientLwM2mSettings.fwUpdateRecourse) ?
this.configurationValue.clientLwM2mSettings.fwUpdateRecourse : '';
let swResource = this.configurationValue.clientLwM2mSettings.swUpdateStrategy === '2' &&
isDefinedAndNotNull(this.configurationValue.clientLwM2mSettings.fwUpdateRecourse) ?
this.configurationValue.clientLwM2mSettings.swUpdateRecourse : '';
this.lwm2mDeviceProfileFormGroup.patchValue({ this.lwm2mDeviceProfileFormGroup.patchValue({
objectIds: value, objectIds: value,
observeAttrTelemetry: this.getObserveAttrTelemetryObjects(value.objectsList), observeAttrTelemetry: this.getObserveAttrTelemetryObjects(value.objectsList),
@ -181,9 +195,17 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro
lwm2mServer: this.configurationValue.bootstrap.lwm2mServer, lwm2mServer: this.configurationValue.bootstrap.lwm2mServer,
clientStrategy: this.configurationValue.clientLwM2mSettings.clientStrategy, clientStrategy: this.configurationValue.clientLwM2mSettings.clientStrategy,
fwUpdateStrategy: this.configurationValue.clientLwM2mSettings.fwUpdateStrategy, fwUpdateStrategy: this.configurationValue.clientLwM2mSettings.fwUpdateStrategy,
swUpdateStrategy: this.configurationValue.clientLwM2mSettings.swUpdateStrategy swUpdateStrategy: this.configurationValue.clientLwM2mSettings.swUpdateStrategy,
fwUpdateRecourse: fwResource,
swUpdateRecourse: swResource
}, },
{emitEvent: false}); {emitEvent: false});
this.configurationValue.clientLwM2mSettings.fwUpdateRecourse = fwResource;
this.configurationValue.clientLwM2mSettings.swUpdateRecourse = swResource;
this.isFwUpdateStrategy = this.configurationValue.clientLwM2mSettings.fwUpdateStrategy === '2';
this.isSwUpdateStrategy = this.configurationValue.clientLwM2mSettings.swUpdateStrategy === '2';
this.otaUpdateSwStrategyValidate();
this.otaUpdateFwStrategyValidate();
} }
private updateModel = (): void => { private updateModel = (): void => {
@ -215,6 +237,8 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro
this.configurationValue.clientLwM2mSettings.clientStrategy = config.clientStrategy; this.configurationValue.clientLwM2mSettings.clientStrategy = config.clientStrategy;
this.configurationValue.clientLwM2mSettings.fwUpdateStrategy = config.fwUpdateStrategy; this.configurationValue.clientLwM2mSettings.fwUpdateStrategy = config.fwUpdateStrategy;
this.configurationValue.clientLwM2mSettings.swUpdateStrategy = config.swUpdateStrategy; this.configurationValue.clientLwM2mSettings.swUpdateStrategy = config.swUpdateStrategy;
this.configurationValue.clientLwM2mSettings.fwUpdateRecourse = config.fwUpdateRecourse;
this.configurationValue.clientLwM2mSettings.swUpdateRecourse = config.swUpdateRecourse;
this.upDateJsonAllConfig(); this.upDateJsonAllConfig();
this.updateModel(); this.updateModel();
} }
@ -264,7 +288,7 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro
const pathParameter = Array.from(path.split('/'), String); const pathParameter = Array.from(path.split('/'), String);
const objectLwM2M = clientObserveAttrTelemetry.find(x => x.keyId === pathParameter[0]); const objectLwM2M = clientObserveAttrTelemetry.find(x => x.keyId === pathParameter[0]);
if (objectLwM2M) { if (objectLwM2M) {
const instance = this.updateInInstanceKeyName (objectLwM2M.instances[0], +pathParameter[1]); const instance = this.updateInInstanceKeyName(objectLwM2M.instances[0], +pathParameter[1]);
objectLwM2M.instances.push(instance); objectLwM2M.instances.push(instance);
} }
}); });
@ -489,4 +513,56 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro
} }
}); });
} }
changeFwUpdateStrategy($event: MatSelectChange) {
debugger
if ($event.value === '2') {
this.isFwUpdateStrategy = true;
if (isEmpty(this.lwm2mDeviceProfileFormGroup.get('fwUpdateRecourse').value)) {
this.lwm2mDeviceProfileFormGroup.patchValue({
fwUpdateRecourse: DEFAULT_FW_UPDATE_RESOURCE
},
{emitEvent: false});
}
} else {
this.isFwUpdateStrategy = false;
}
this.otaUpdateFwStrategyValidate();
}
changeSwUpdateStrategy($event: MatSelectChange) {
debugger
if ($event.value === '2') {
this.isSwUpdateStrategy = true;
if (isEmpty(this.lwm2mDeviceProfileFormGroup.get('swUpdateRecourse').value)) {
this.lwm2mDeviceProfileFormGroup.patchValue({
swUpdateRecourse: DEFAULT_SW_UPDATE_RESOURCE
},
{emitEvent: false});
}
} else {
this.isSwUpdateStrategy = false;
}
this.otaUpdateSwStrategyValidate();
}
private otaUpdateFwStrategyValidate(): void {
if (this.isFwUpdateStrategy) {
this.lwm2mDeviceProfileFormGroup.get('fwUpdateRecourse').setValidators([Validators.required]);
} else {
this.lwm2mDeviceProfileFormGroup.get('fwUpdateRecourse').clearValidators();
}
this.lwm2mDeviceProfileFormGroup.get('fwUpdateRecourse').updateValueAndValidity();
}
private otaUpdateSwStrategyValidate(): void {
if (this.isSwUpdateStrategy) {
this.lwm2mDeviceProfileFormGroup.get('swUpdateRecourse').setValidators([Validators.required]);
} else {
this.lwm2mDeviceProfileFormGroup.get('swUpdateRecourse').clearValidators();
}
this.lwm2mDeviceProfileFormGroup.get('swUpdateRecourse').updateValueAndValidity();
}
} }

15
ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-profile-config.models.ts

@ -28,7 +28,7 @@ export const TELEMETRY = 'telemetry';
export const KEY_NAME = 'keyName'; export const KEY_NAME = 'keyName';
export const DEFAULT_ID_SERVER = 123; export const DEFAULT_ID_SERVER = 123;
export const DEFAULT_ID_BOOTSTRAP = 111; export const DEFAULT_ID_BOOTSTRAP = 111;
export const DEFAULT_HOST_NAME = 'localhost'; export const DEFAULT_LOCAL_HOST_NAME = 'localhost';
export const DEFAULT_PORT_SERVER_NO_SEC = 5685; export const DEFAULT_PORT_SERVER_NO_SEC = 5685;
export const DEFAULT_PORT_BOOTSTRAP_NO_SEC = 5687; export const DEFAULT_PORT_BOOTSTRAP_NO_SEC = 5687;
export const DEFAULT_CLIENT_HOLD_OFF_TIME = 1; export const DEFAULT_CLIENT_HOLD_OFF_TIME = 1;
@ -43,6 +43,11 @@ export const KEY_REGEXP_HEX_DEC = /^[-+]?[0-9A-Fa-f]+\.?[0-9A-Fa-f]*?$/;
export const KEY_REGEXP_NUMBER = /^(\-?|\+?)\d*$/; export const KEY_REGEXP_NUMBER = /^(\-?|\+?)\d*$/;
export const INSTANCES_ID_VALUE_MIN = 0; export const INSTANCES_ID_VALUE_MIN = 0;
export const INSTANCES_ID_VALUE_MAX = 65535; export const INSTANCES_ID_VALUE_MAX = 65535;
export const DEFAULT_OTA_UPDATE_PROTOCOL = "coap://";
export const DEFAULT_FIRMWARE_UPDATE_COAP_RECOURSE = "firmwareUpdateCoapRecourse";
export const DEFAULT_SOFTWARE_UPDATE_COAP_RECOURSE = "softwareUpdateCoapRecourse";
export const DEFAULT_FW_UPDATE_RESOURCE = DEFAULT_OTA_UPDATE_PROTOCOL + DEFAULT_LOCAL_HOST_NAME + ":"+ DEFAULT_PORT_SERVER_NO_SEC + "/" + DEFAULT_FIRMWARE_UPDATE_COAP_RECOURSE;
export const DEFAULT_SW_UPDATE_RESOURCE = DEFAULT_OTA_UPDATE_PROTOCOL + DEFAULT_LOCAL_HOST_NAME + ":"+ DEFAULT_PORT_SERVER_NO_SEC + "/" + DEFAULT_SOFTWARE_UPDATE_COAP_RECOURSE;
export enum BINDING_MODE { export enum BINDING_MODE {
@ -168,6 +173,8 @@ export interface ClientLwM2mSettings {
clientStrategy: string; clientStrategy: string;
fwUpdateStrategy: string; fwUpdateStrategy: string;
swUpdateStrategy: string; swUpdateStrategy: string;
fwUpdateRecourse: string;
swUpdateRecourse: string;
} }
export interface ObservableAttributes { export interface ObservableAttributes {
@ -231,7 +238,7 @@ export function getDefaultProfileConfig(hostname?: any): Lwm2mProfileConfigModel
return { return {
clientLwM2mSettings: getDefaultProfileClientLwM2mSettingsConfig(), clientLwM2mSettings: getDefaultProfileClientLwM2mSettingsConfig(),
observeAttr: getDefaultProfileObserveAttrConfig(), observeAttr: getDefaultProfileObserveAttrConfig(),
bootstrap: getDefaultProfileBootstrapSecurityConfig((hostname) ? hostname : DEFAULT_HOST_NAME) bootstrap: getDefaultProfileBootstrapSecurityConfig((hostname) ? hostname : DEFAULT_LOCAL_HOST_NAME)
}; };
} }
@ -239,7 +246,9 @@ function getDefaultProfileClientLwM2mSettingsConfig(): ClientLwM2mSettings {
return { return {
clientStrategy: "1", clientStrategy: "1",
fwUpdateStrategy: "1", fwUpdateStrategy: "1",
swUpdateStrategy: "1" swUpdateStrategy: "1",
fwUpdateRecourse: DEFAULT_FW_UPDATE_RESOURCE,
swUpdateRecourse: DEFAULT_SW_UPDATE_RESOURCE
}; };
} }

5
ui-ngx/src/assets/locale/locale.constant-en_US.json

@ -1262,6 +1262,7 @@
"bootstrap-server-account-timeout": "Account after the timeout", "bootstrap-server-account-timeout": "Account after the timeout",
"bootstrap-server-account-timeout-tip": "Bootstrap-Server Account after the timeout value given by this resource.", "bootstrap-server-account-timeout-tip": "Bootstrap-Server Account after the timeout value given by this resource.",
"others-tab": "Other settings...", "others-tab": "Other settings...",
"client-strategy": "Client strategy when connecting",
"client-strategy-label": "Strategy", "client-strategy-label": "Strategy",
"client-strategy-connect": "{ count, plural, 1 {1: Only Observe Request to the client after the initial connection} other {2: Read All Resources & Observe Request to the client after registration} }", "client-strategy-connect": "{ count, plural, 1 {1: Only Observe Request to the client after the initial connection} other {2: Read All Resources & Observe Request to the client after registration} }",
"client-strategy-tip": "{ count, plural, 1 {Strategy 1: After the initial connection of the LWM2M Client, the server sends Observe resources Request to the client, those resources that are marked as observation in the Device profile and which exist on the LWM2M client.} other {Strategy 2: After the registration, request the client to read all the resource values for all objects that the LWM2M client has,\n then execute: the server sends Observe resources Request to the client, those resources that are marked as observation in the Device profile and which exist on the LWM2M client.} }", "client-strategy-tip": "{ count, plural, 1 {Strategy 1: After the initial connection of the LWM2M Client, the server sends Observe resources Request to the client, those resources that are marked as observation in the Device profile and which exist on the LWM2M client.} other {Strategy 2: After the registration, request the client to read all the resource values for all objects that the LWM2M client has,\n then execute: the server sends Observe resources Request to the client, those resources that are marked as observation in the Device profile and which exist on the LWM2M client.} }",
@ -1270,9 +1271,7 @@
"fw-update-strategy": "{ count, plural, 1 {Push firmware update as binary file using Object 5 and Resource 0 (Package).} 2 {Auto-generate unique CoAP URL to download the package and push firmware update as Object 5 and Resource 1 (Package URI).} other {Push firmware update as binary file using Object 19 and Resource 0 (Data).} }", "fw-update-strategy": "{ count, plural, 1 {Push firmware update as binary file using Object 5 and Resource 0 (Package).} 2 {Auto-generate unique CoAP URL to download the package and push firmware update as Object 5 and Resource 1 (Package URI).} other {Push firmware update as binary file using Object 19 and Resource 0 (Data).} }",
"sw-update-strategy-label": "Software update strategy", "sw-update-strategy-label": "Software update strategy",
"sw-update-strategy": "{ count, plural, 1 {Push binary file using Object 9 and Resource 2 (Package).} other {Auto-generate unique CoAP URL to download the package and push software update using Object 9 and Resource 3 (Package URI).} }", "sw-update-strategy": "{ count, plural, 1 {Push binary file using Object 9 and Resource 2 (Package).} other {Auto-generate unique CoAP URL to download the package and push software update using Object 9 and Resource 3 (Package URI).} }",
"blockwise-settings": "Blockwise settings", "ota-update-recourse": "Ota update Coap recourse",
"blockwise-enabled": "Enable blockwise",
"blockwise-status-lifetime": "Blockwise Status Lifetime",
"fw-update-recourse": "Firmware update Coap recourse", "fw-update-recourse": "Firmware update Coap recourse",
"sw-update-recourse": "Software update Coap recourse", "sw-update-recourse": "Software update Coap recourse",
"config-json-tab": "Json Config Profile Device" "config-json-tab": "Json Config Profile Device"

Loading…
Cancel
Save