Search in sources :

Example 1 with FirmwareUpdateState

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

the class DefaultLwM2MOtaUpdateService method onCurrentFirmwareStateUpdate.

@Override
public void onCurrentFirmwareStateUpdate(LwM2mClient client, Long stateCode) {
    log.debug("[{}] Current fw state: {}", client.getEndpoint(), stateCode);
    LwM2MClientFwOtaInfo fwInfo = getOrInitFwInfo(client);
    FirmwareUpdateState state = FirmwareUpdateState.fromStateFwByCode(stateCode.intValue());
    if (FirmwareUpdateState.DOWNLOADED.equals(state)) {
        executeFwUpdate(client);
    }
    fwInfo.setUpdateState(state);
    Optional<OtaPackageUpdateStatus> status = toOtaPackageUpdateStatus(state);
    if (FirmwareUpdateState.IDLE.equals(state) && DOWNLOADING.equals(fwInfo.getStatus())) {
        fwInfo.setFailedPackageId(fwInfo.getTargetPackageId());
        status = Optional.of(FAILED);
    }
    status.ifPresent(otaStatus -> {
        fwInfo.setStatus(otaStatus);
        sendStateUpdateToTelemetry(client, fwInfo, otaStatus, "Firmware Update State: " + state.name());
    });
    update(fwInfo);
}
Also used : LwM2MClientFwOtaInfo(org.thingsboard.server.transport.lwm2m.server.ota.firmware.LwM2MClientFwOtaInfo) OtaPackageUpdateStatus(org.thingsboard.server.common.data.ota.OtaPackageUpdateStatus) FirmwareUpdateState(org.thingsboard.server.transport.lwm2m.server.ota.firmware.FirmwareUpdateState)

Aggregations

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