From f020e0472d4544c7f968d8fb2504ad8e85174a49 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Fri, 10 Dec 2021 19:23:38 -0800 Subject: Handle missing attributes --- .../org/traccar/protocol/FlexApiProtocolDecoder.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'src/main/java/org') diff --git a/src/main/java/org/traccar/protocol/FlexApiProtocolDecoder.java b/src/main/java/org/traccar/protocol/FlexApiProtocolDecoder.java index d2b3c6960..25a8f7090 100644 --- a/src/main/java/org/traccar/protocol/FlexApiProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/FlexApiProtocolDecoder.java @@ -68,10 +68,18 @@ public class FlexApiProtocolDecoder extends BaseProtocolDecoder { getLastLocation(position, new Date(payload.getInt("obd.ts") * 1000L)); - position.set(Position.KEY_OBD_SPEED, payload.getJsonNumber("obd.speed").doubleValue()); - position.set(Position.KEY_OBD_ODOMETER, payload.getInt("obd.odo")); - position.set(Position.KEY_RPM, payload.getInt("obd.rpm")); - position.set(Position.KEY_VIN, payload.getString("obd.vin")); + if (payload.containsKey("obd.speed")) { + position.set(Position.KEY_OBD_SPEED, payload.getJsonNumber("obd.speed").doubleValue()); + } + if (payload.containsKey("obd.odo")) { + position.set(Position.KEY_OBD_ODOMETER, payload.getInt("obd.odo")); + } + if (payload.containsKey("obd.rpm")) { + position.set(Position.KEY_RPM, payload.getInt("obd.rpm")); + } + if (payload.containsKey("obd.vin")) { + position.set(Position.KEY_VIN, payload.getString("obd.vin")); + } } else { -- cgit v1.2.3