use of org.thingsboard.server.transport.lwm2m.server.ota.software.LwM2MClientSwOtaInfo 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.transport.lwm2m.server.ota.software.LwM2MClientSwOtaInfo in project thingsboard by thingsboard.
the class DefaultLwM2MOtaUpdateService method onTargetSoftwareUpdate.
@Override
public void onTargetSoftwareUpdate(LwM2mClient client, String newSoftwareTitle, String newSoftwareVersion, Optional<String> newSoftwareUrl, Optional<String> newSoftwareTag) {
LwM2MClientSwOtaInfo fwInfo = getOrInitSwInfo(client);
fwInfo.updateTarget(newSoftwareTitle, newSoftwareVersion, newSoftwareUrl, newSoftwareTag);
update(fwInfo);
startSoftwareUpdateIfNeeded(client, fwInfo);
}
use of org.thingsboard.server.transport.lwm2m.server.ota.software.LwM2MClientSwOtaInfo 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;
}
use of org.thingsboard.server.transport.lwm2m.server.ota.software.LwM2MClientSwOtaInfo in project thingsboard by thingsboard.
the class DefaultLwM2MOtaUpdateService method initSwStrategy.
private LwM2MClientSwOtaInfo initSwStrategy(LwM2mClient client, OtherConfiguration configuration) {
LwM2MClientSwOtaInfo swInfo = getOrInitSwInfo(client);
swInfo.setStrategy(LwM2MSoftwareUpdateStrategy.fromStrategySwByCode(configuration.getSwUpdateStrategy()));
swInfo.setBaseUrl(configuration.getSwUpdateResource());
return swInfo;
}
use of org.thingsboard.server.transport.lwm2m.server.ota.software.LwM2MClientSwOtaInfo 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);
}
Aggregations