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