Search in sources :

Example 6 with LwM2MClientFwOtaInfo

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

the class DefaultLwM2MOtaUpdateService method onCurrentFirmwareDeliveryMethodUpdate.

@Override
public void onCurrentFirmwareDeliveryMethodUpdate(LwM2mClient client, Long value) {
    log.debug("[{}] Current fw delivery method: {}", client.getEndpoint(), value);
    LwM2MClientFwOtaInfo fwInfo = getOrInitFwInfo(client);
    fwInfo.setDeliveryMethod(value.intValue());
}
Also used : LwM2MClientFwOtaInfo(org.thingsboard.server.transport.lwm2m.server.ota.firmware.LwM2MClientFwOtaInfo)

Example 7 with LwM2MClientFwOtaInfo

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

Example 8 with LwM2MClientFwOtaInfo

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

the class DefaultLwM2MOtaUpdateService method forceFirmwareUpdate.

@Override
public void forceFirmwareUpdate(LwM2mClient client) {
    LwM2MClientFwOtaInfo fwInfo = getOrInitFwInfo(client);
    fwInfo.setRetryAttempts(0);
    fwInfo.setFailedPackageId(null);
    startFirmwareUpdateIfNeeded(client, fwInfo);
}
Also used : LwM2MClientFwOtaInfo(org.thingsboard.server.transport.lwm2m.server.ota.firmware.LwM2MClientFwOtaInfo)

Example 9 with LwM2MClientFwOtaInfo

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

the class DefaultLwM2MOtaUpdateService method init.

@Override
public void init(LwM2mClient client) {
    // TODO: add locks by client fwInfo.
    // TODO: check that the client supports FW and SW by checking the supported objects in the model.
    List<String> attributesToFetch = new ArrayList<>();
    LwM2MClientFwOtaInfo fwInfo = getOrInitFwInfo(client);
    if (fwInfo.isSupported()) {
        attributesToFetch.add(FIRMWARE_TITLE);
        attributesToFetch.add(FIRMWARE_VERSION);
        attributesToFetch.add(FIRMWARE_TAG);
        attributesToFetch.add(FIRMWARE_URL);
    }
    LwM2MClientSwOtaInfo swInfo = getOrInitSwInfo(client);
    if (swInfo.isSupported()) {
        attributesToFetch.add(SOFTWARE_TITLE);
        attributesToFetch.add(SOFTWARE_VERSION);
        attributesToFetch.add(SOFTWARE_TAG);
        attributesToFetch.add(SOFTWARE_URL);
    }
    var clientSettings = clientContext.getProfile(client.getProfileId()).getClientLwM2mSettings();
    initFwStrategy(client, clientSettings);
    initSwStrategy(client, clientSettings);
    if (!attributesToFetch.isEmpty()) {
        var future = attributesService.getSharedAttributes(client, attributesToFetch);
        DonAsynchron.withCallback(future, attrs -> {
            if (fwInfo.isSupported()) {
                Optional<String> newFwTitle = getAttributeValue(attrs, FIRMWARE_TITLE);
                Optional<String> newFwVersion = getAttributeValue(attrs, FIRMWARE_VERSION);
                Optional<String> newFwTag = getAttributeValue(attrs, FIRMWARE_TAG);
                Optional<String> newFwUrl = getAttributeValue(attrs, FIRMWARE_URL);
                if (newFwTitle.isPresent() && newFwVersion.isPresent() && !isOtaDownloading(client) && !UPDATING.equals(fwInfo.status)) {
                    onTargetFirmwareUpdate(client, newFwTitle.get(), newFwVersion.get(), newFwUrl, newFwTag);
                }
            }
            if (swInfo.isSupported()) {
                Optional<String> newSwTitle = getAttributeValue(attrs, SOFTWARE_TITLE);
                Optional<String> newSwVersion = getAttributeValue(attrs, SOFTWARE_VERSION);
                Optional<String> newSwTag = getAttributeValue(attrs, SOFTWARE_TAG);
                Optional<String> newSwUrl = getAttributeValue(attrs, SOFTWARE_URL);
                if (newSwTitle.isPresent() && newSwVersion.isPresent()) {
                    onTargetSoftwareUpdate(client, newSwTitle.get(), newSwVersion.get(), newSwUrl, newSwTag);
                }
            }
        }, throwable -> {
            if (fwInfo.isSupported()) {
                update(fwInfo);
            }
        }, executor);
    }
}
Also used : LwM2MClientSwOtaInfo(org.thingsboard.server.transport.lwm2m.server.ota.software.LwM2MClientSwOtaInfo) LwM2MClientFwOtaInfo(org.thingsboard.server.transport.lwm2m.server.ota.firmware.LwM2MClientFwOtaInfo) ArrayList(java.util.ArrayList)

Example 10 with LwM2MClientFwOtaInfo

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

the class DefaultLwM2MOtaUpdateService method initFwStrategy.

private LwM2MClientFwOtaInfo initFwStrategy(LwM2mClient client, OtherConfiguration configuration) {
    LwM2MClientFwOtaInfo fwInfo = getOrInitFwInfo(client);
    fwInfo.setStrategy(LwM2MFirmwareUpdateStrategy.fromStrategyFwByCode(configuration.getFwUpdateStrategy()));
    fwInfo.setBaseUrl(configuration.getFwUpdateResource());
    return fwInfo;
}
Also used : 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