Search in sources :

Example 1 with FirmwareUpdateResult

use of org.thingsboard.server.transport.lwm2m.server.ota.firmware.FirmwareUpdateResult 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)

Aggregations

OtaPackageUpdateStatus (org.thingsboard.server.common.data.ota.OtaPackageUpdateStatus)1 FirmwareUpdateResult (org.thingsboard.server.transport.lwm2m.server.ota.firmware.FirmwareUpdateResult)1 LwM2MClientFwOtaInfo (org.thingsboard.server.transport.lwm2m.server.ota.firmware.LwM2MClientFwOtaInfo)1