diff options
Diffstat (limited to 'src/org/traccar/protocol/OwnTracksProtocolDecoder.java')
-rw-r--r-- | src/org/traccar/protocol/OwnTracksProtocolDecoder.java | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/src/org/traccar/protocol/OwnTracksProtocolDecoder.java b/src/org/traccar/protocol/OwnTracksProtocolDecoder.java index f664d113b..ea604f4ac 100644 --- a/src/org/traccar/protocol/OwnTracksProtocolDecoder.java +++ b/src/org/traccar/protocol/OwnTracksProtocolDecoder.java @@ -58,6 +58,11 @@ public class OwnTracksProtocolDecoder extends BaseProtocolDecoder { JsonObject root = Json.createReader( new StringReader(request.getContent().toString(StandardCharsets.US_ASCII))).readObject(); + if (!root.containsKey("_type") || !root.getString("_type").equals("location")) { + sendResponse(channel, HttpResponseStatus.BAD_REQUEST); + return null; + } + Position position = new Position(); position.setProtocol(getProtocolName()); position.setValid(true); @@ -83,13 +88,21 @@ public class OwnTracksProtocolDecoder extends BaseProtocolDecoder { if (root.containsKey("batt")) { position.set(Position.KEY_BATTERY, root.getInt("batt")); } - if (root.containsKey("topic")) { - position.set("topic", root.getString("topic")); - } position.setTime(new Date(root.getJsonNumber("tst").longValue() * 1000)); - DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, root.getString("tid")); + String uniqueId; + + if (root.containsKey("topic")) { + uniqueId = root.getString("topic"); + if (root.containsKey("tid")) { + position.set("tid", root.getString("tid")); + } + } else { + uniqueId = root.getString("tid"); + } + + DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, uniqueId); if (deviceSession == null) { sendResponse(channel, HttpResponseStatus.BAD_REQUEST); return null; @@ -99,5 +112,4 @@ public class OwnTracksProtocolDecoder extends BaseProtocolDecoder { sendResponse(channel, HttpResponseStatus.OK); return position; } - } |