use of org.thingsboard.server.common.data.device.profile.lwm2m.OtherConfiguration in project thingsboard by thingsboard.
the class LwM2mClientContextImpl method onUplink.
@Override
public void onUplink(LwM2mClient client) {
PowerMode powerMode = client.getPowerMode();
OtherConfiguration profileSettings = null;
if (powerMode == null) {
var clientProfile = getProfile(client.getProfileId());
profileSettings = clientProfile.getClientLwM2mSettings();
powerMode = profileSettings.getPowerMode();
if (powerMode == null) {
powerMode = PowerMode.DRX;
}
}
if (PowerMode.DRX.equals(powerMode)) {
client.updateLastUplinkTime();
return;
}
client.lock();
try {
long uplinkTime = client.updateLastUplinkTime();
long timeout;
if (PowerMode.PSM.equals(powerMode)) {
Long psmActivityTimer = client.getPsmActivityTimer();
if (psmActivityTimer == null && profileSettings != null) {
psmActivityTimer = profileSettings.getPsmActivityTimer();
}
if (psmActivityTimer == null || psmActivityTimer == 0L) {
psmActivityTimer = config.getPsmActivityTimer();
}
timeout = psmActivityTimer;
} else {
Long pagingTransmissionWindow = client.getPagingTransmissionWindow();
if (pagingTransmissionWindow == null && profileSettings != null) {
pagingTransmissionWindow = profileSettings.getPagingTransmissionWindow();
}
if (pagingTransmissionWindow == null || pagingTransmissionWindow == 0L) {
pagingTransmissionWindow = config.getPagingTransmissionWindow();
}
timeout = pagingTransmissionWindow;
}
Future<Void> sleepTask = client.getSleepTask();
if (sleepTask != null) {
sleepTask.cancel(false);
}
Future<Void> task = context.getScheduler().schedule(() -> {
if (uplinkTime == client.getLastUplinkTime() && !otaUpdateService.isOtaDownloading(client)) {
asleep(client);
}
return null;
}, timeout, TimeUnit.MILLISECONDS);
client.setSleepTask(task);
} finally {
client.unlock();
}
}
use of org.thingsboard.server.common.data.device.profile.lwm2m.OtherConfiguration in project thingsboard by thingsboard.
the class LwM2mClientContextImpl method getRequestTimeout.
@Override
public Long getRequestTimeout(LwM2mClient client) {
Long timeout = null;
if (PowerMode.E_DRX.equals(client.getPowerMode()) && client.getEdrxCycle() != null) {
timeout = client.getEdrxCycle();
} else {
var clientProfile = getProfile(client.getProfileId());
OtherConfiguration clientLwM2mSettings = clientProfile.getClientLwM2mSettings();
if (PowerMode.E_DRX.equals(clientLwM2mSettings.getPowerMode())) {
timeout = clientLwM2mSettings.getEdrxCycle();
}
}
if (timeout == null || timeout == 0L) {
timeout = this.config.getTimeout();
}
return timeout;
}
use of org.thingsboard.server.common.data.device.profile.lwm2m.OtherConfiguration in project thingsboard by thingsboard.
the class AbstractLwM2MIntegrationTest method getTransportConfiguration.
protected Lwm2mDeviceProfileTransportConfiguration getTransportConfiguration(String observeAttr, List<LwM2MBootstrapServerCredential> bootstrapServerCredentials) {
Lwm2mDeviceProfileTransportConfiguration transportConfiguration = new Lwm2mDeviceProfileTransportConfiguration();
TelemetryMappingConfiguration observeAttrConfiguration = JacksonUtil.fromString(observeAttr, TelemetryMappingConfiguration.class);
OtherConfiguration clientLwM2mSettings = JacksonUtil.fromString(CLIENT_LWM2M_SETTINGS, OtherConfiguration.class);
transportConfiguration.setBootstrapServerUpdateEnable(true);
transportConfiguration.setObserveAttr(observeAttrConfiguration);
transportConfiguration.setClientLwM2mSettings(clientLwM2mSettings);
transportConfiguration.setBootstrap(bootstrapServerCredentials);
return transportConfiguration;
}
use of org.thingsboard.server.common.data.device.profile.lwm2m.OtherConfiguration in project thingsboard by thingsboard.
the class LwM2mClientContextImpl method isDownlinkAllowed.
@Override
public boolean isDownlinkAllowed(LwM2mClient client) {
PowerMode powerMode = client.getPowerMode();
OtherConfiguration profileSettings = null;
if (powerMode == null) {
var clientProfile = getProfile(client.getProfileId());
profileSettings = clientProfile.getClientLwM2mSettings();
powerMode = profileSettings.getPowerMode();
if (powerMode == null) {
powerMode = PowerMode.DRX;
}
}
if (PowerMode.DRX.equals(powerMode) || otaUpdateService.isOtaDownloading(client)) {
return true;
}
client.lock();
long timeSinceLastUplink = System.currentTimeMillis() - client.getLastUplinkTime();
try {
if (PowerMode.PSM.equals(powerMode)) {
Long psmActivityTimer = client.getPsmActivityTimer();
if (psmActivityTimer == null && profileSettings != null) {
psmActivityTimer = profileSettings.getPsmActivityTimer();
}
if (psmActivityTimer == null || psmActivityTimer == 0L) {
psmActivityTimer = config.getPsmActivityTimer();
}
return timeSinceLastUplink <= psmActivityTimer;
} else {
Long pagingTransmissionWindow = client.getPagingTransmissionWindow();
if (pagingTransmissionWindow == null && profileSettings != null) {
pagingTransmissionWindow = profileSettings.getPagingTransmissionWindow();
}
if (pagingTransmissionWindow == null || pagingTransmissionWindow == 0L) {
pagingTransmissionWindow = config.getPagingTransmissionWindow();
}
boolean allowed = timeSinceLastUplink <= pagingTransmissionWindow;
if (!allowed) {
return client.checkFirstDownlink();
} else {
return true;
}
}
} finally {
client.unlock();
}
}
use of org.thingsboard.server.common.data.device.profile.lwm2m.OtherConfiguration in project thingsboard by thingsboard.
the class DefaultLwM2mUplinkMsgHandler method onDeviceProfileUpdate.
// TODO: review and optimize the logic to minimize number of the requests to device.
private void onDeviceProfileUpdate(List<LwM2mClient> clients, Lwm2mDeviceProfileTransportConfiguration oldProfile, DeviceProfile deviceProfile) {
if (clientContext.profileUpdate(deviceProfile) != null) {
TelemetryMappingConfiguration oldTelemetryParams = oldProfile.getObserveAttr();
Set<String> attributeSetOld = oldTelemetryParams.getAttribute();
Set<String> telemetrySetOld = oldTelemetryParams.getTelemetry();
Set<String> observeOld = oldTelemetryParams.getObserve();
Map<String, String> keyNameOld = oldTelemetryParams.getKeyName();
Map<String, ObjectAttributes> attributeLwm2mOld = oldTelemetryParams.getAttributeLwm2m();
var newProfile = clientContext.getProfile(deviceProfile.getUuidId());
TelemetryMappingConfiguration newTelemetryParams = newProfile.getObserveAttr();
Set<String> attributeSetNew = newTelemetryParams.getAttribute();
Set<String> telemetrySetNew = newTelemetryParams.getTelemetry();
Set<String> observeNew = newTelemetryParams.getObserve();
Map<String, String> keyNameNew = newTelemetryParams.getKeyName();
Map<String, ObjectAttributes> attributeLwm2mNew = newTelemetryParams.getAttributeLwm2m();
Set<String> observeToAdd = diffSets(observeOld, observeNew);
Set<String> observeToRemove = diffSets(observeNew, observeOld);
Set<String> newObjectsToRead = new HashSet<>();
Set<String> newObjectsToCancelRead = new HashSet<>();
if (!attributeSetOld.equals(attributeSetNew)) {
newObjectsToRead.addAll(diffSets(attributeSetOld, attributeSetNew));
newObjectsToCancelRead.addAll(diffSets(attributeSetNew, attributeSetOld));
}
if (!telemetrySetOld.equals(telemetrySetNew)) {
newObjectsToRead.addAll(diffSets(telemetrySetOld, telemetrySetNew));
newObjectsToCancelRead.addAll(diffSets(telemetrySetNew, telemetrySetOld));
}
if (!keyNameOld.equals(keyNameNew)) {
ParametersAnalyzeResult keyNameChange = this.getAnalyzerKeyName(keyNameOld, keyNameNew);
newObjectsToRead.addAll(keyNameChange.getPathPostParametersAdd());
}
ParametersAnalyzeResult analyzerParameters = getAttributesAnalyzer(attributeLwm2mOld, attributeLwm2mNew);
clients.forEach(client -> {
LwM2MModelConfig modelConfig = new LwM2MModelConfig(client.getEndpoint());
modelConfig.getToRead().addAll(diffSets(observeToAdd, newObjectsToRead));
modelConfig.getToCancelRead().addAll(newObjectsToCancelRead);
modelConfig.getToCancelObserve().addAll(observeToRemove);
modelConfig.getToObserve().addAll(observeToAdd);
Set<String> clientObjects = clientContext.getSupportedIdVerInClient(client);
Set<String> pathToAdd = analyzerParameters.getPathPostParametersAdd().stream().filter(target -> clientObjects.contains("/" + target.split(LWM2M_SEPARATOR_PATH)[1])).collect(Collectors.toUnmodifiableSet());
modelConfig.getAttributesToAdd().putAll(pathToAdd.stream().collect(Collectors.toMap(t -> t, attributeLwm2mNew::get)));
Set<String> pathToRemove = analyzerParameters.getPathPostParametersDel().stream().filter(target -> clientObjects.contains("/" + target.split(LWM2M_SEPARATOR_PATH)[1])).collect(Collectors.toUnmodifiableSet());
modelConfig.getAttributesToRemove().addAll(pathToRemove);
modelConfigService.sendUpdates(client, modelConfig);
});
// update value in fwInfo
OtherConfiguration newLwM2mSettings = newProfile.getClientLwM2mSettings();
OtherConfiguration oldLwM2mSettings = oldProfile.getClientLwM2mSettings();
if (!newLwM2mSettings.getFwUpdateStrategy().equals(oldLwM2mSettings.getFwUpdateStrategy()) || (StringUtils.isNotEmpty(newLwM2mSettings.getFwUpdateResource()) && !newLwM2mSettings.getFwUpdateResource().equals(oldLwM2mSettings.getFwUpdateResource()))) {
clients.forEach(lwM2MClient -> otaService.onFirmwareStrategyUpdate(lwM2MClient, newLwM2mSettings));
}
if (!newLwM2mSettings.getSwUpdateStrategy().equals(oldLwM2mSettings.getSwUpdateStrategy()) || (StringUtils.isNotEmpty(newLwM2mSettings.getSwUpdateResource()) && !newLwM2mSettings.getSwUpdateResource().equals(oldLwM2mSettings.getSwUpdateResource()))) {
clients.forEach(lwM2MClient -> otaService.onCurrentSoftwareStrategyUpdate(lwM2MClient, newLwM2mSettings));
}
}
}
Aggregations