Fix for lastActivityTime in devices created by gateway
This commit is contained in:
parent
cff36668ed
commit
1bdd7d69bf
@ -53,6 +53,7 @@ message SessionInfoProto {
|
||||
int64 gwSessionIdLSB = 11;
|
||||
int64 deviceProfileIdMSB = 12;
|
||||
int64 deviceProfileIdLSB = 13;
|
||||
bool activityTimeFromGatewayDevice = 14;
|
||||
}
|
||||
|
||||
enum SessionEvent {
|
||||
|
||||
@ -15,6 +15,8 @@
|
||||
*/
|
||||
package org.thingsboard.server.transport.mqtt.session;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.thingsboard.server.common.data.DeviceProfile;
|
||||
import org.thingsboard.server.common.transport.SessionMsgListener;
|
||||
@ -37,6 +39,14 @@ public class GatewayDeviceSessionCtx extends MqttDeviceAwareSessionContext imple
|
||||
DeviceProfile deviceProfile, ConcurrentMap<MqttTopicMatcher, Integer> mqttQoSMap) {
|
||||
super(UUID.randomUUID(), mqttQoSMap);
|
||||
this.parent = parent;
|
||||
JsonParser parser = new JsonParser();
|
||||
boolean activityTimeFromGatewayDevice = Boolean.FALSE;
|
||||
if ("null".equals(this.parent.getDeviceInfo().getAdditionalInfo())) {
|
||||
JsonObject additionalInfo = parser.parse(this.parent.getDeviceInfo().getAdditionalInfo()).getAsJsonObject();
|
||||
if (additionalInfo.get("activityTimeFromGatewayDevice") != null) {
|
||||
activityTimeFromGatewayDevice = additionalInfo.get("activityTimeFromGatewayDevice").getAsBoolean();
|
||||
}
|
||||
}
|
||||
setSessionInfo(SessionInfoProto.newBuilder()
|
||||
.setNodeId(parent.getNodeId())
|
||||
.setSessionIdMSB(sessionId.getMostSignificantBits())
|
||||
@ -51,6 +61,7 @@ public class GatewayDeviceSessionCtx extends MqttDeviceAwareSessionContext imple
|
||||
.setGwSessionIdLSB(parent.getSessionId().getLeastSignificantBits())
|
||||
.setDeviceProfileIdMSB(deviceInfo.getDeviceProfileId().getId().getMostSignificantBits())
|
||||
.setDeviceProfileIdLSB(deviceInfo.getDeviceProfileId().getId().getLeastSignificantBits())
|
||||
.setActivityTimeFromGatewayDevice(activityTimeFromGatewayDevice)
|
||||
.build());
|
||||
setDeviceInfo(deviceInfo);
|
||||
setDeviceProfile(deviceProfile);
|
||||
|
||||
@ -34,6 +34,7 @@ import io.netty.handler.codec.mqtt.MqttPublishMessage;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.thingsboard.server.common.data.DeviceInfo;
|
||||
import org.thingsboard.server.common.data.id.DeviceId;
|
||||
import org.thingsboard.server.common.transport.TransportService;
|
||||
import org.thingsboard.server.common.transport.TransportServiceCallback;
|
||||
@ -179,6 +180,8 @@ public class GatewaySessionHandler {
|
||||
return deviceSessionCtx.getPayloadAdaptor();
|
||||
}
|
||||
|
||||
public TransportDeviceInfo getDeviceInfo() { return deviceSessionCtx.getDeviceInfo(); }
|
||||
|
||||
void deregisterSession(String deviceName) {
|
||||
GatewayDeviceSessionCtx deviceSessionCtx = devices.remove(deviceName);
|
||||
if (deviceSessionCtx != null) {
|
||||
|
||||
@ -510,7 +510,8 @@ public class DefaultTransportService implements TransportService {
|
||||
long lastActivityTime = sessionMD.getLastActivityTime();
|
||||
TransportProtos.SessionInfoProto sessionInfo = sessionMD.getSessionInfo();
|
||||
if (sessionInfo.getGwSessionIdMSB() != 0 &&
|
||||
sessionInfo.getGwSessionIdLSB() != 0) {
|
||||
sessionInfo.getGwSessionIdLSB() != 0 &&
|
||||
sessionInfo.getActivityTimeFromGatewayDevice()) {
|
||||
SessionMetaData gwMetaData = sessions.get(new UUID(sessionInfo.getGwSessionIdMSB(), sessionInfo.getGwSessionIdLSB()));
|
||||
if (gwMetaData != null) {
|
||||
lastActivityTime = Math.max(gwMetaData.getLastActivityTime(), lastActivityTime);
|
||||
|
||||
@ -100,9 +100,15 @@
|
||||
required>
|
||||
</tb-device-data>
|
||||
<div formGroupName="additionalInfo" fxLayout="column">
|
||||
<mat-checkbox fxFlex formControlName="gateway" style="padding-bottom: 16px;">
|
||||
{{ 'device.is-gateway' | translate }}
|
||||
</mat-checkbox>
|
||||
<div fxLayout="row" fxLayout.xs="column" style="padding-bottom: 16px;">
|
||||
<mat-checkbox fxFlex.gt-sm="30" fxFlex formControlName="gateway">
|
||||
{{ 'device.is-gateway' | translate }}
|
||||
</mat-checkbox>
|
||||
<mat-checkbox fxFlex *ngIf="entityForm.get('additionalInfo.gateway').value"
|
||||
formControlName="activityTimeFromGatewayDevice">
|
||||
{{ 'device.activity-time-from-gateway-device' | translate }}
|
||||
</mat-checkbox>
|
||||
</div>
|
||||
<mat-form-field class="mat-block">
|
||||
<mat-label translate>device.description</mat-label>
|
||||
<textarea matInput formControlName="description" rows="2"></textarea>
|
||||
|
||||
@ -84,6 +84,7 @@ export class DeviceComponent extends EntityComponent<DeviceInfo> {
|
||||
additionalInfo: this.fb.group(
|
||||
{
|
||||
gateway: [entity && entity.additionalInfo ? entity.additionalInfo.gateway : false],
|
||||
activityTimeFromGatewayDevice: [entity && entity.additionalInfo ? entity.additionalInfo.activityTimeFromGatewayDevice: false],
|
||||
description: [entity && entity.additionalInfo ? entity.additionalInfo.description : ''],
|
||||
}
|
||||
)
|
||||
@ -96,8 +97,13 @@ export class DeviceComponent extends EntityComponent<DeviceInfo> {
|
||||
this.entityForm.patchValue({deviceProfileId: entity.deviceProfileId});
|
||||
this.entityForm.patchValue({label: entity.label});
|
||||
this.entityForm.patchValue({deviceData: entity.deviceData});
|
||||
this.entityForm.patchValue({additionalInfo:
|
||||
{gateway: entity.additionalInfo ? entity.additionalInfo.gateway : false}});
|
||||
this.entityForm.patchValue({
|
||||
additionalInfo:
|
||||
{
|
||||
gateway: entity.additionalInfo ? entity.additionalInfo.gateway : false,
|
||||
activityTimeFromGatewayDevice: entity.additionalInfo ? entity.additionalInfo.activityTimeFromGatewayDevice : false
|
||||
}
|
||||
});
|
||||
this.entityForm.patchValue({additionalInfo: {description: entity.additionalInfo ? entity.additionalInfo.description : ''}});
|
||||
}
|
||||
|
||||
|
||||
@ -906,6 +906,7 @@
|
||||
"unable-delete-device-alias-title": "Unable to delete device alias",
|
||||
"unable-delete-device-alias-text": "Device alias '{{deviceAlias}}' can't be deleted as it used by the following widget(s):<br/>{{widgetsList}}",
|
||||
"is-gateway": "Is gateway",
|
||||
"activity-time-from-gateway-device": "Activity time from gateway device",
|
||||
"public": "Public",
|
||||
"device-public": "Device is public",
|
||||
"select-device": "Select device",
|
||||
@ -1721,6 +1722,7 @@
|
||||
"entity-field": "Entity field",
|
||||
"access-token": "Access token",
|
||||
"isgateway": "Is Gateway",
|
||||
"activity-time-from-gateway-device": "Activity time from gateway device",
|
||||
"description": "Description"
|
||||
},
|
||||
"stepper-text":{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user