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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations