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);
}
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);
}
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;
});
}
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);
}
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;
}
Aggregations