Search in sources :

Example 1 with LwM2MClientFwOtaInfo

use of org.thingsboard.server.transport.lwm2m.server.ota.firmware.LwM2MClientFwOtaInfo in project thingsboard by thingsboard.

the class DefaultLwM2MOtaUpdateService method onCurrentFirmwareVersionUpdate.

@Override
public void onCurrentFirmwareVersionUpdate(LwM2mClient client, String version) {
    log.debug("[{}] Current fw version(5): {}", client.getEndpoint(), version);
    LwM2MClientFwOtaInfo fwInfo = getOrInitFwInfo(client);
    fwInfo.setCurrentVersion(version);
}
Also used : LwM2MClientFwOtaInfo(org.thingsboard.server.transport.lwm2m.server.ota.firmware.LwM2MClientFwOtaInfo)

Example 2 with LwM2MClientFwOtaInfo

use of org.thingsboard.server.transport.lwm2m.server.ota.firmware.LwM2MClientFwOtaInfo in project thingsboard by thingsboard.

the class DefaultLwM2MOtaUpdateService method onTargetFirmwareUpdate.

@Override
public void onTargetFirmwareUpdate(LwM2mClient client, String newFirmwareTitle, String newFirmwareVersion, Optional<String> newFirmwareUrl, Optional<String> newFirmwareTag) {
    LwM2MClientFwOtaInfo fwInfo = getOrInitFwInfo(client);
    fwInfo.updateTarget(newFirmwareTitle, newFirmwareVersion, newFirmwareUrl, newFirmwareTag);
    update(fwInfo);
    startFirmwareUpdateIfNeeded(client, fwInfo);
}
Also used : LwM2MClientFwOtaInfo(org.thingsboard.server.transport.lwm2m.server.ota.firmware.LwM2MClientFwOtaInfo)

Example 3 with LwM2MClientFwOtaInfo

use of org.thingsboard.server.transport.lwm2m.server.ota.firmware.LwM2MClientFwOtaInfo in project thingsboard by thingsboard.

the class DefaultLwM2MOtaUpdateService method getOrInitFwInfo.

private LwM2MClientFwOtaInfo getOrInitFwInfo(LwM2mClient client) {
    return this.fwStates.computeIfAbsent(client.getEndpoint(), endpoint -> {
        LwM2MClientFwOtaInfo info = otaInfoStore.getFw(endpoint);
        if (info == null) {
            var profile = clientContext.getProfile(client.getProfileId());
            info = new LwM2MClientFwOtaInfo(endpoint, profile.getClientLwM2mSettings().getFwUpdateResource(), LwM2MFirmwareUpdateStrategy.fromStrategyFwByCode(profile.getClientLwM2mSettings().getFwUpdateStrategy()));
            update(info);
        }
        return info;
    });
}
Also used : LwM2MClientFwOtaInfo(org.thingsboard.server.transport.lwm2m.server.ota.firmware.LwM2MClientFwOtaInfo)

Example 4 with LwM2MClientFwOtaInfo

use of org.thingsboard.server.transport.lwm2m.server.ota.firmware.LwM2MClientFwOtaInfo 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 5 with LwM2MClientFwOtaInfo

use of org.thingsboard.server.transport.lwm2m.server.ota.firmware.LwM2MClientFwOtaInfo in project thingsboard by thingsboard.

the class DefaultLwM2MOtaUpdateService method isOtaDownloading.

@Override
public boolean isOtaDownloading(LwM2mClient client) {
    String endpoint = client.getEndpoint();
    LwM2MClientFwOtaInfo fwInfo = fwStates.get(endpoint);
    LwM2MClientSwOtaInfo swInfo = swStates.get(endpoint);
    if (fwInfo != null && (DOWNLOADING.equals(fwInfo.getStatus()))) {
        return true;
    }
    if (swInfo != null && (DOWNLOADING.equals(swInfo.getStatus()))) {
        return true;
    }
    return false;
}
Also used : LwM2MClientSwOtaInfo(org.thingsboard.server.transport.lwm2m.server.ota.software.LwM2MClientSwOtaInfo) LwM2MClientFwOtaInfo(org.thingsboard.server.transport.lwm2m.server.ota.firmware.LwM2MClientFwOtaInfo)

Aggregations

LwM2MClientFwOtaInfo (org.thingsboard.server.transport.lwm2m.server.ota.firmware.LwM2MClientFwOtaInfo)11 OtaPackageUpdateStatus (org.thingsboard.server.common.data.ota.OtaPackageUpdateStatus)2 LwM2MClientSwOtaInfo (org.thingsboard.server.transport.lwm2m.server.ota.software.LwM2MClientSwOtaInfo)2 ArrayList (java.util.ArrayList)1 FirmwareUpdateResult (org.thingsboard.server.transport.lwm2m.server.ota.firmware.FirmwareUpdateResult)1 FirmwareUpdateState (org.thingsboard.server.transport.lwm2m.server.ota.firmware.FirmwareUpdateState)1