Search in sources :

Example 1 with OtaPackageUpdateStatus

use of org.thingsboard.server.common.data.ota.OtaPackageUpdateStatus in project thingsboard by thingsboard.

the class DefaultLwM2MOtaUpdateService method onCurrentSoftwareStateUpdate.

@Override
public void onCurrentSoftwareStateUpdate(LwM2mClient client, Long stateCode) {
    log.debug("[{}] Current sw state: {}", client.getEndpoint(), stateCode);
    LwM2MClientSwOtaInfo swInfo = getOrInitSwInfo(client);
    SoftwareUpdateState state = SoftwareUpdateState.fromUpdateStateSwByCode(stateCode.intValue());
    if (SoftwareUpdateState.INITIAL.equals(state)) {
        startSoftwareUpdateIfNeeded(client, swInfo);
    } else if (SoftwareUpdateState.DELIVERED.equals(state)) {
        executeSwInstall(client);
    }
    swInfo.setUpdateState(state);
    Optional<OtaPackageUpdateStatus> status = toOtaPackageUpdateStatus(state);
    status.ifPresent(otaStatus -> sendStateUpdateToTelemetry(client, swInfo, otaStatus, "Firmware Update State: " + state.name()));
    update(swInfo);
}
Also used : LwM2MClientSwOtaInfo(org.thingsboard.server.transport.lwm2m.server.ota.software.LwM2MClientSwOtaInfo) OtaPackageUpdateStatus(org.thingsboard.server.common.data.ota.OtaPackageUpdateStatus) SoftwareUpdateState(org.thingsboard.server.transport.lwm2m.server.ota.software.SoftwareUpdateState)

Example 2 with OtaPackageUpdateStatus

use of org.thingsboard.server.common.data.ota.OtaPackageUpdateStatus in project thingsboard by thingsboard.

the class DefaultLwM2MOtaUpdateService method onCurrentFirmwareResultUpdate.

@Override
public void onCurrentFirmwareResultUpdate(LwM2mClient client, Long code) {
    log.debug("[{}] Current fw result: {}", client.getEndpoint(), code);
    LwM2MClientFwOtaInfo fwInfo = getOrInitFwInfo(client);
    FirmwareUpdateResult result = FirmwareUpdateResult.fromUpdateResultFwByCode(code.intValue());
    Optional<OtaPackageUpdateStatus> status = toOtaPackageUpdateStatus(result);
    if (FirmwareUpdateResult.INITIAL.equals(result) && OtaPackageUpdateStatus.UPDATING.equals(fwInfo.getStatus())) {
        status = Optional.of(UPDATED);
        fwInfo.setRetryAttempts(0);
        fwInfo.setFailedPackageId(null);
    }
    status.ifPresent(otaStatus -> {
        fwInfo.setStatus(otaStatus);
        sendStateUpdateToTelemetry(client, fwInfo, otaStatus, "Firmware Update Result: " + result.name());
    });
    if (result.isAgain() && fwInfo.getRetryAttempts() <= 2) {
        fwInfo.setRetryAttempts(fwInfo.getRetryAttempts() + 1);
        startFirmwareUpdateIfNeeded(client, fwInfo);
    } else {
        fwInfo.update(result);
    }
    update(fwInfo);
}
Also used : LwM2MClientFwOtaInfo(org.thingsboard.server.transport.lwm2m.server.ota.firmware.LwM2MClientFwOtaInfo) OtaPackageUpdateStatus(org.thingsboard.server.common.data.ota.OtaPackageUpdateStatus) FirmwareUpdateResult(org.thingsboard.server.transport.lwm2m.server.ota.firmware.FirmwareUpdateResult)

Example 3 with OtaPackageUpdateStatus

use of org.thingsboard.server.common.data.ota.OtaPackageUpdateStatus in project thingsboard by thingsboard.

the class DefaultLwM2MOtaUpdateService method onCurrentSoftwareResultUpdate.

@Override
public void onCurrentSoftwareResultUpdate(LwM2mClient client, Long code) {
    log.debug("[{}] Current sw result: {}", client.getEndpoint(), code);
    LwM2MClientSwOtaInfo swInfo = getOrInitSwInfo(client);
    SoftwareUpdateResult result = SoftwareUpdateResult.fromUpdateResultSwByCode(code.intValue());
    Optional<OtaPackageUpdateStatus> status = toOtaPackageUpdateStatus(result);
    status.ifPresent(otaStatus -> sendStateUpdateToTelemetry(client, swInfo, otaStatus, "Software Update Result: " + result.name()));
    if (result.isAgain() && swInfo.getRetryAttempts() <= 2) {
        swInfo.setRetryAttempts(swInfo.getRetryAttempts() + 1);
        startSoftwareUpdateIfNeeded(client, swInfo);
    } else {
        swInfo.update(result);
    }
    update(swInfo);
}
Also used : LwM2MClientSwOtaInfo(org.thingsboard.server.transport.lwm2m.server.ota.software.LwM2MClientSwOtaInfo) OtaPackageUpdateStatus(org.thingsboard.server.common.data.ota.OtaPackageUpdateStatus) SoftwareUpdateResult(org.thingsboard.server.transport.lwm2m.server.ota.software.SoftwareUpdateResult)

Example 4 with OtaPackageUpdateStatus

use of org.thingsboard.server.common.data.ota.OtaPackageUpdateStatus in project thingsboard by thingsboard.

the class OtaLwM2MIntegrationTest method testFirmwareUpdateWithClientWithoutFirmwareOtaInfoFromProfile.

@Test
public void testFirmwareUpdateWithClientWithoutFirmwareOtaInfoFromProfile() throws Exception {
    Lwm2mDeviceProfileTransportConfiguration transportConfiguration = getTransportConfiguration(OBSERVE_ATTRIBUTES_WITH_PARAMS, getBootstrapServerCredentialsNoSec(NONE));
    createDeviceProfile(transportConfiguration);
    LwM2MDeviceCredentials deviceCredentials = getDeviceCredentialsNoSec(createNoSecClientCredentials(this.CLIENT_ENDPOINT_WITHOUT_FW_INFO));
    final Device device = createDevice(deviceCredentials, this.CLIENT_ENDPOINT_WITHOUT_FW_INFO);
    createNewClient(SECURITY_NO_SEC, COAP_CONFIG, false, this.CLIENT_ENDPOINT_WITHOUT_FW_INFO, false, null);
    device.setFirmwareId(createFirmware().getId());
    final Device savedDevice = doPost("/api/device", device, Device.class);
    Thread.sleep(1000);
    assertThat(savedDevice).as("saved device").isNotNull();
    assertThat(getDeviceFromAPI(device.getId().getId())).as("fetched device").isEqualTo(savedDevice);
    List<TsKvEntry> ts = toTimeseries(doGetAsyncTyped("/api/plugins/telemetry/DEVICE/" + savedDevice.getId().getId() + "/values/timeseries?keys=fw_state", new TypeReference<>() {
    }));
    List<OtaPackageUpdateStatus> statuses = ts.stream().map(KvEntry::getValueAsString).map(OtaPackageUpdateStatus::valueOf).collect(Collectors.toList());
    List<OtaPackageUpdateStatus> expectedStatuses = Collections.singletonList(FAILED);
    Assert.assertEquals(expectedStatuses, statuses);
}
Also used : TsKvEntry(org.thingsboard.server.common.data.kv.TsKvEntry) LwM2MDeviceCredentials(org.thingsboard.server.common.data.device.credentials.lwm2m.LwM2MDeviceCredentials) Device(org.thingsboard.server.common.data.Device) Lwm2mDeviceProfileTransportConfiguration(org.thingsboard.server.common.data.device.profile.Lwm2mDeviceProfileTransportConfiguration) OtaPackageUpdateStatus(org.thingsboard.server.common.data.ota.OtaPackageUpdateStatus) TsKvEntry(org.thingsboard.server.common.data.kv.TsKvEntry) KvEntry(org.thingsboard.server.common.data.kv.KvEntry) TypeReference(com.fasterxml.jackson.core.type.TypeReference) Test(org.junit.Test) AbstractOtaLwM2MIntegrationTest(org.thingsboard.server.transport.lwm2m.ota.AbstractOtaLwM2MIntegrationTest)

Example 5 with OtaPackageUpdateStatus

use of org.thingsboard.server.common.data.ota.OtaPackageUpdateStatus in project thingsboard by thingsboard.

the class OtaLwM2MIntegrationTest method testFirmwareUpdateByObject5.

@Test
public void testFirmwareUpdateByObject5() throws Exception {
    Lwm2mDeviceProfileTransportConfiguration transportConfiguration = getTransportConfiguration(OBSERVE_ATTRIBUTES_WITH_PARAMS_OTA, getBootstrapServerCredentialsNoSec(NONE));
    createDeviceProfile(transportConfiguration);
    LwM2MDeviceCredentials deviceCredentials = getDeviceCredentialsNoSec(createNoSecClientCredentials(this.CLIENT_ENDPOINT_OTA5));
    final Device device = createDevice(deviceCredentials, this.CLIENT_ENDPOINT_OTA5);
    createNewClient(SECURITY_NO_SEC, COAP_CONFIG, false, this.CLIENT_ENDPOINT_OTA5, false, null);
    device.setFirmwareId(createFirmware().getId());
    final Device savedDevice = doPost("/api/device", device, Device.class);
    Thread.sleep(1000);
    assertThat(savedDevice).as("saved device").isNotNull();
    assertThat(getDeviceFromAPI(device.getId().getId())).as("fetched device").isEqualTo(savedDevice);
    final List<OtaPackageUpdateStatus> expectedStatuses = Arrays.asList(QUEUED, INITIATED, DOWNLOADING, DOWNLOADED, UPDATING, UPDATED);
    List<TsKvEntry> ts = await("await on timeseries").atMost(30, TimeUnit.SECONDS).until(() -> toTimeseries(doGetAsyncTyped("/api/plugins/telemetry/DEVICE/" + savedDevice.getId().getId() + "/values/timeseries?orderBy=ASC&keys=fw_state&startTs=0&endTs=" + System.currentTimeMillis(), new TypeReference<>() {
    })), hasSize(expectedStatuses.size()));
    List<OtaPackageUpdateStatus> statuses = ts.stream().sorted(Comparator.comparingLong(TsKvEntry::getTs)).map(KvEntry::getValueAsString).map(OtaPackageUpdateStatus::valueOf).collect(Collectors.toList());
    Assert.assertEquals(expectedStatuses, statuses);
}
Also used : TsKvEntry(org.thingsboard.server.common.data.kv.TsKvEntry) LwM2MDeviceCredentials(org.thingsboard.server.common.data.device.credentials.lwm2m.LwM2MDeviceCredentials) Device(org.thingsboard.server.common.data.Device) Lwm2mDeviceProfileTransportConfiguration(org.thingsboard.server.common.data.device.profile.Lwm2mDeviceProfileTransportConfiguration) OtaPackageUpdateStatus(org.thingsboard.server.common.data.ota.OtaPackageUpdateStatus) TsKvEntry(org.thingsboard.server.common.data.kv.TsKvEntry) KvEntry(org.thingsboard.server.common.data.kv.KvEntry) Test(org.junit.Test) AbstractOtaLwM2MIntegrationTest(org.thingsboard.server.transport.lwm2m.ota.AbstractOtaLwM2MIntegrationTest)

Aggregations

OtaPackageUpdateStatus (org.thingsboard.server.common.data.ota.OtaPackageUpdateStatus)7 Test (org.junit.Test)3 Device (org.thingsboard.server.common.data.Device)3 LwM2MDeviceCredentials (org.thingsboard.server.common.data.device.credentials.lwm2m.LwM2MDeviceCredentials)3 Lwm2mDeviceProfileTransportConfiguration (org.thingsboard.server.common.data.device.profile.Lwm2mDeviceProfileTransportConfiguration)3 KvEntry (org.thingsboard.server.common.data.kv.KvEntry)3 TsKvEntry (org.thingsboard.server.common.data.kv.TsKvEntry)3 AbstractOtaLwM2MIntegrationTest (org.thingsboard.server.transport.lwm2m.ota.AbstractOtaLwM2MIntegrationTest)3 LwM2MClientFwOtaInfo (org.thingsboard.server.transport.lwm2m.server.ota.firmware.LwM2MClientFwOtaInfo)2 LwM2MClientSwOtaInfo (org.thingsboard.server.transport.lwm2m.server.ota.software.LwM2MClientSwOtaInfo)2 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 FirmwareUpdateResult (org.thingsboard.server.transport.lwm2m.server.ota.firmware.FirmwareUpdateResult)1 FirmwareUpdateState (org.thingsboard.server.transport.lwm2m.server.ota.firmware.FirmwareUpdateState)1 SoftwareUpdateResult (org.thingsboard.server.transport.lwm2m.server.ota.software.SoftwareUpdateResult)1 SoftwareUpdateState (org.thingsboard.server.transport.lwm2m.server.ota.software.SoftwareUpdateState)1