Showing
1 changed file
with
10 additions
and
1 deletions
... | ... | @@ -53,6 +53,8 @@ import java.io.ByteArrayInputStream; |
53 | 53 | import java.io.IOException; |
54 | 54 | import java.util.ArrayList; |
55 | 55 | import java.util.List; |
56 | +import java.util.concurrent.TimeUnit; | |
57 | +import java.util.concurrent.atomic.AtomicInteger; | |
56 | 58 | |
57 | 59 | import static org.thingsboard.server.gen.transport.TransportProtos.KeyValueType.BOOLEAN_V; |
58 | 60 | |
... | ... | @@ -64,6 +66,13 @@ public class LwM2mTransportServerHelper { |
64 | 66 | |
65 | 67 | private final LwM2mTransportContext context; |
66 | 68 | private final LwM2MJsonAdaptor adaptor; |
69 | + private final AtomicInteger atomicTs = new AtomicInteger(0); | |
70 | + | |
71 | + | |
72 | + public long getTS() { | |
73 | + int addTs = atomicTs.getAndIncrement() >= 1000 ? atomicTs.getAndSet(0) : atomicTs.get(); | |
74 | + return TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis()) * 1000L + addTs; | |
75 | + } | |
67 | 76 | |
68 | 77 | /** |
69 | 78 | * send to Thingsboard Attribute || Telemetry |
... | ... | @@ -96,7 +105,7 @@ public class LwM2mTransportServerHelper { |
96 | 105 | public void sendParametersOnThingsboardTelemetry(List<TransportProtos.KeyValueProto> result, SessionInfoProto sessionInfo) { |
97 | 106 | PostTelemetryMsg.Builder request = PostTelemetryMsg.newBuilder(); |
98 | 107 | TransportProtos.TsKvListProto.Builder builder = TransportProtos.TsKvListProto.newBuilder(); |
99 | - builder.setTs(System.currentTimeMillis()); | |
108 | + builder.setTs(this.getTS()); | |
100 | 109 | builder.addAllKv(result); |
101 | 110 | request.addTsKvList(builder.build()); |
102 | 111 | PostTelemetryMsg postTelemetryMsg = request.build(); | ... | ... |