Browse Source

Merge branch 'master' of github.com:thingsboard/thingsboard

pull/4719/head
Igor Kulikov 5 years ago
parent
commit
dbc3ef95ce
  1. 19
      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. 7
      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. 77
      ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-device-profile-transport-configuration.component.ts
  8. 13
      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

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

@ -482,13 +482,16 @@ public class CoapTransportResource extends AbstractCoapTransportResource {
String title = exchange.getQueryParameter("title");
String version = exchange.getQueryParameter("version");
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)) {
String firmwareId = new UUID(msg.getOtaPackageIdMSB(), msg.getOtaPackageIdLSB()).toString();
String strChunkSize = exchange.getQueryParameter("size");
String strChunk = exchange.getQueryParameter("chunk");
int chunkSize = StringUtils.isEmpty(strChunkSize) ? 0 : Integer.parseInt(strChunkSize);
int chunk = StringUtils.isEmpty(strChunk) ? 0 : Integer.parseInt(strChunk);
exchange.respond(CoAP.ResponseCode.CONTENT, transportContext.getOtaPackageDataCache().get(firmwareId, chunkSize, chunk));
}
else if (firmwareId != null) {
sendOtaData(exchange, firmwareId);
} else {
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 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.common.data.Device;
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.OtaPackageType;
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.TransportServiceCallback;
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.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.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.LwM2mTransportUtil.DEVICE_ATTRIBUTES_REQUEST;
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);
SessionInfoProto sessionInfo = client.getSession();
if (sessionInfo != null) {
transportService.deregisterSession(sessionInfo);
this.doCloseSession(sessionInfo);
transportService.deregisterSession(sessionInfo);
sessionStore.remove(registration.getEndpoint());
log.info("Client close session: [{}] unReg [{}] name [{}] profile ", registration.getId(), registration.getEndpoint(), sessionInfo.getDeviceType());
} 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
protected void processHandleGet(CoapExchange exchange) {
log.warn("90) processHandleGet [{}]", exchange);
if (exchange.getRequestOptions().getUriPath().size() == 2 &&
(FIRMWARE_UPDATE_COAP_RECOURSE.equals(exchange.getRequestOptions().getUriPath().get(0)) ||
SOFTWARE_UPDATE_COAP_RECOURSE.equals(exchange.getRequestOptions().getUriPath().get(0)))) {
this.sentOtaData(exchange);
if (exchange.getRequestOptions().getUriPath().size() >= 2 &&
(FIRMWARE_UPDATE_COAP_RECOURSE.equals(exchange.getRequestOptions().getUriPath().get(exchange.getRequestOptions().getUriPath().size()-2)) ||
SOFTWARE_UPDATE_COAP_RECOURSE.equals(exchange.getRequestOptions().getUriPath().get(exchange.getRequestOptions().getUriPath().size()-2)))) {
this.sendOtaData(exchange);
}
}
@ -129,23 +129,25 @@ public class LwM2mTransportCoapResource extends AbstractLwM2mTransportResource {
}
}
private void sentOtaData(CoapExchange exchange) {
String idStr = exchange.getRequestOptions().getUriPath().get(1);
private void sendOtaData(CoapExchange exchange) {
String idStr = exchange.getRequestOptions().getUriPath().get(exchange.getRequestOptions().getUriPath().size()-1
);
UUID currentId = UUID.fromString(idStr);
if (exchange.getRequestOptions().getBlock2() != null) {
int chunkSize = exchange.getRequestOptions().getBlock2().getSzx();
int chunk = 0;
Response response = new Response(CoAP.ResponseCode.CONTENT);
byte[] fwData = this.getOtaData(currentId);
log.warn("91) read softWare data (length): [{}]", fwData.length);
if (fwData != null && fwData.length > 0) {
response.setPayload(fwData);
Response response = new Response(CoAP.ResponseCode.CONTENT);
byte[] fwData = this.getOtaData(currentId);
log.warn("91) read softWare data (length): [{}]", fwData.length);
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, chunk);
log.warn("92) Send currentId: [{}], length: [{}], chunkSize [{}], moreFlag [{}]", currentId.toString(), fwData.length, chunkSize, moreFlag);
exchange.respond(response);
response.getOptions().setBlock2(chunkSize, moreFlag, 0);
log.warn("92) with blokc2 Send currentId: [{}], length: [{}], chunkSize [{}], moreFlag [{}]", currentId.toString(), fwData.length, chunkSize, moreFlag);
}
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.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Predicate;
import static org.eclipse.leshan.core.SecurityMode.NO_SEC;
import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.convertPathFromObjectIdToIdVer;
@ -137,14 +138,19 @@ public class LwM2mClientContextImpl implements LwM2mClientContext {
@Override
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()))
.equals((new UUID(c.getSession().getSessionIdMSB(), c.getSession().getSessionIdLSB())))
).findAny().orElse(null);
.equals((new UUID(c.getSession().getSessionIdMSB(), c.getSession().getSessionIdLSB())));
if (this.lwM2mClientsByEndpoint.size() > 0) {
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) {
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());
}
return lwM2mClient;

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

@ -192,11 +192,8 @@ public class LwM2mFwSwUpdate {
request.sendAllRequest(this.lwM2MClient, targetIdVer, WRITE_REPLACE, ContentFormat.OPAQUE,
firmwareChunk, handler.config.getTimeout(), this.rpcRequest);
} else if (LwM2mTransportUtil.LwM2MFirmwareUpdateStrategy.OBJ_5_TEMP_URL.code == this.updateStrategy) {
Registration registration = this.getLwM2MClient().getRegistration();
// String api = handler.config.getHostRequests();
String api = "0.0.0.0";
int port = registration.getIdentity().isSecure() ? handler.config.getSecurePort() : handler.config.getPort();
String uri = "coap://" + api + ":" + Integer.valueOf(port) + "/" + FIRMWARE_UPDATE_COAP_RECOURSE + "/" + this.currentId.toString();
String apiFont = "coap://176.36.143.9:5685";
String uri = apiFont + "/" + FIRMWARE_UPDATE_COAP_RECOURSE + "/" + this.currentId.toString();
log.warn("89) coapUri: [{}]", uri);
request.sendAllRequest(this.lwM2MClient, targetIdVer, WRITE_REPLACE, null,
uri, handler.config.getTimeout(), this.rpcRequest);

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 }}">
<ng-template matTabContent>
<section [formGroup]="lwm2mDeviceProfileFormGroup">
<div *ngIf="false" class="mat-padding" style="padding-bottom: 0px">
<mat-form-field class="mat-block">
<mat-label>{{ 'device-profile.lwm2m.client-strategy-label' | translate }}</mat-label>
<mat-select formControlName="clientStrategy"
matTooltip="{{ 'device-profile.lwm2m.client-strategy-tip' | translate:
{ count: +lwm2mDeviceProfileFormGroup.get('clientStrategy').value } }}"
matTooltipPosition="above">
<mat-option value=1>{{ 'device-profile.lwm2m.client-strategy' | translate:
{count: 1} }}</mat-option>
<mat-option value=2>{{ 'device-profile.lwm2m.client-strategy' | translate:
{count: 2} }}</mat-option>
</mat-select>
</mat-form-field>
</div>
<div class="mat-padding" style="padding-bottom: 0px">
<mat-form-field class="mat-block">
<mat-label>{{ 'device-profile.lwm2m.fw-update-strategy-label' | translate }}</mat-label>
<mat-select formControlName="fwUpdateStrategy">
<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=2>{{ 'device-profile.lwm2m.fw-update-strategy' | translate:
{count: 3} }}</mat-option>
</mat-select>
</mat-form-field>
<mat-form-field class="mat-block">
<mat-label>{{ 'device-profile.lwm2m.sw-update-strategy-label' | translate }}</mat-label>
<mat-select formControlName="swUpdateStrategy">
<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>
<mat-accordion multi="true" class="mat-body-1">
<div *ngIf="false">
<mat-expansion-panel>
<mat-expansion-panel-header>
<mat-panel-title>
<div
class="tb-panel-title">{{ 'device-profile.lwm2m.client-strategy' | translate | uppercase }}</div>
</mat-panel-title>
</mat-expansion-panel-header>
<ng-template matExpansionPanelContent>
<div fxLayout="column">
<mat-form-field class="mat-block">
<mat-label>{{ 'device-profile.lwm2m.client-strategy-label' | translate }}</mat-label>
<mat-select formControlName="clientStrategy"
matTooltip="{{ 'device-profile.lwm2m.client-strategy-tip' | translate:
{ count: +lwm2mDeviceProfileFormGroup.get('clientStrategy').value } }}"
matTooltipPosition="above">
<mat-option value=1>{{ 'device-profile.lwm2m.client-strategy-connect' | translate:
{count: 1} }}</mat-option>
<mat-option value=2>{{ 'device-profile.lwm2m.client-strategy-connect' | translate:
{count: 2} }}</mat-option>
</mat-select>
</mat-form-field>
</div>
</ng-template>
</mat-expansion-panel>
</div>
<mat-expansion-panel>
<mat-expansion-panel-header>
<mat-panel-title>
<div
class="tb-panel-title">{{ 'device-profile.lwm2m.ota-update-strategy' | translate | uppercase }}</div>
</mat-panel-title>
</mat-expansion-panel-header>
<ng-template matExpansionPanelContent>
<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>
</ng-template>
</mat-tab>

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

@ -22,6 +22,8 @@ import {
ATTRIBUTE,
BINDING_MODE,
BINDING_MODE_NAMES,
DEFAULT_FW_UPDATE_RESOURCE,
DEFAULT_SW_UPDATE_RESOURCE,
getDefaultProfileConfig,
Instance,
INSTANCES,
@ -41,6 +43,7 @@ import { Direction } from '@shared/models/page/sort-order';
import _ from 'lodash';
import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
import { MatSelectChange } from '@angular/material/select';
@Component({
selector: 'tb-profile-lwm2m-device-transport-configuration',
@ -67,6 +70,8 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro
bootstrapServer: string;
lwm2mServer: string;
sortFunction: (key: string, value: object) => object;
isFwUpdateStrategy: boolean;
isSwUpdateStrategy: boolean;
get required(): boolean {
return this.requiredValue;
@ -95,6 +100,8 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro
clientStrategy: [1, []],
fwUpdateStrategy: [1, []],
swUpdateStrategy: [1, []],
fwUpdateRecourse: ['', []],
swUpdateRecourse: ['', []]
});
this.lwm2mDeviceConfigFormGroup = this.fb.group({
configurationJson: [null, Validators.required]
@ -169,6 +176,12 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro
}
private updateWriteValue = (value: ModelValue): void => {
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({
objectIds: value,
observeAttrTelemetry: this.getObserveAttrTelemetryObjects(value.objectsList),
@ -181,9 +194,17 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro
lwm2mServer: this.configurationValue.bootstrap.lwm2mServer,
clientStrategy: this.configurationValue.clientLwM2mSettings.clientStrategy,
fwUpdateStrategy: this.configurationValue.clientLwM2mSettings.fwUpdateStrategy,
swUpdateStrategy: this.configurationValue.clientLwM2mSettings.swUpdateStrategy
swUpdateStrategy: this.configurationValue.clientLwM2mSettings.swUpdateStrategy,
fwUpdateRecourse: fwResource,
swUpdateRecourse: swResource
},
{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 => {
@ -215,6 +236,8 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro
this.configurationValue.clientLwM2mSettings.clientStrategy = config.clientStrategy;
this.configurationValue.clientLwM2mSettings.fwUpdateStrategy = config.fwUpdateStrategy;
this.configurationValue.clientLwM2mSettings.swUpdateStrategy = config.swUpdateStrategy;
this.configurationValue.clientLwM2mSettings.fwUpdateRecourse = config.fwUpdateRecourse;
this.configurationValue.clientLwM2mSettings.swUpdateRecourse = config.swUpdateRecourse;
this.upDateJsonAllConfig();
this.updateModel();
}
@ -264,7 +287,7 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro
const pathParameter = Array.from(path.split('/'), String);
const objectLwM2M = clientObserveAttrTelemetry.find(x => x.keyId === pathParameter[0]);
if (objectLwM2M) {
const instance = this.updateInInstanceKeyName (objectLwM2M.instances[0], +pathParameter[1]);
const instance = this.updateInInstanceKeyName(objectLwM2M.instances[0], +pathParameter[1]);
objectLwM2M.instances.push(instance);
}
});
@ -489,4 +512,54 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro
}
});
}
changeFwUpdateStrategy($event: MatSelectChange) {
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) {
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();
}
}

13
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 DEFAULT_ID_SERVER = 123;
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_BOOTSTRAP_NO_SEC = 5687;
export const DEFAULT_CLIENT_HOLD_OFF_TIME = 1;
@ -43,6 +43,9 @@ export const KEY_REGEXP_HEX_DEC = /^[-+]?[0-9A-Fa-f]+\.?[0-9A-Fa-f]*?$/;
export const KEY_REGEXP_NUMBER = /^(\-?|\+?)\d*$/;
export const INSTANCES_ID_VALUE_MIN = 0;
export const INSTANCES_ID_VALUE_MAX = 65535;
export const DEFAULT_OTA_UPDATE_PROTOCOL = "coap://";
export const DEFAULT_FW_UPDATE_RESOURCE = DEFAULT_OTA_UPDATE_PROTOCOL + DEFAULT_LOCAL_HOST_NAME + ":"+ DEFAULT_PORT_SERVER_NO_SEC;
export const DEFAULT_SW_UPDATE_RESOURCE = DEFAULT_OTA_UPDATE_PROTOCOL + DEFAULT_LOCAL_HOST_NAME + ":"+ DEFAULT_PORT_SERVER_NO_SEC;
export enum BINDING_MODE {
@ -168,6 +171,8 @@ export interface ClientLwM2mSettings {
clientStrategy: string;
fwUpdateStrategy: string;
swUpdateStrategy: string;
fwUpdateRecourse: string;
swUpdateRecourse: string;
}
export interface ObservableAttributes {
@ -231,7 +236,7 @@ export function getDefaultProfileConfig(hostname?: any): Lwm2mProfileConfigModel
return {
clientLwM2mSettings: getDefaultProfileClientLwM2mSettingsConfig(),
observeAttr: getDefaultProfileObserveAttrConfig(),
bootstrap: getDefaultProfileBootstrapSecurityConfig((hostname) ? hostname : DEFAULT_HOST_NAME)
bootstrap: getDefaultProfileBootstrapSecurityConfig((hostname) ? hostname : DEFAULT_LOCAL_HOST_NAME)
};
}
@ -239,7 +244,9 @@ function getDefaultProfileClientLwM2mSettingsConfig(): ClientLwM2mSettings {
return {
clientStrategy: "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

@ -1267,6 +1267,7 @@
"bootstrap-server-account-timeout": "Account after the timeout",
"bootstrap-server-account-timeout-tip": "Bootstrap-Server Account after the timeout value given by this resource.",
"others-tab": "Other settings...",
"client-strategy": "Client strategy when connecting",
"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-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.} }",
@ -1275,9 +1276,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).} }",
"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).} }",
"blockwise-settings": "Blockwise settings",
"blockwise-enabled": "Enable blockwise",
"blockwise-status-lifetime": "Blockwise Status Lifetime",
"ota-update-recourse": "Ota update Coap recourse",
"fw-update-recourse": "Firmware update Coap recourse",
"sw-update-recourse": "Software update Coap recourse",
"config-json-tab": "Json Config Profile Device"

Loading…
Cancel
Save