Server communication with GPS Watch

Anton Tananaev7 years ago

The problem is that there are two types of devices. For one it's overspeed, for the other one it's watch removed alarm. We can use attributes to check type of device.

dgrub7 years ago

Hello Anton,

first of all, thank you very much for your great software!

Could you please explain it to me, how I can implement the watch removed alarm as I'm facing the same issue.
The watch sends alarm code 000008 and the server interprets it as overspeed alarm - although I'm trying to generate a watch removed alarm.

Could you please tell me, how to solve this problem?

Is it neccessary to modify the watch-decoder protocol? Especially the alarms?
If yes, how can I embedd the source to a running server (set up with the installer-file) ?

Thank you very much and kind regards!

Anton Tananaev7 years ago

It is necessary to change the code. You would need to re-compile the source and replace binary on the running server. If you need help, send an email to support address.

chmanos7 years ago

Regarding Q50, does anyone have the list of the SMS commands so to set a device?

I need to setup a Q50 to a traccar server.

Thank you

Packetloss7 years ago

@iorgu123 or someone else, Can you please post a link (Ali expres, banggood or something like that) with the watch that you found compatible with traccar?

Anton, I'd like to help fixing the "watch removal alarm" for the Q50 (that's the device I have). How would you want me to do the "differentiation" between it and the "other" watches?

Anton Tananaev6 years ago

The best option is probably to make it configurable (globally and per device/group).

with no automatic "guessing"? I mean at least for "watch" protocol the default could be "watch removed", for the other protocols keep it "overspeed"

Also I'm looking at org/traccar/protocol/WatchProtocolDecoder.java:249:

        } else if (type.equals("UD") || type.equals("UD2") || type.equals("UD3")
                || type.equals("AL") || type.equals("WT")) {

            Position position = decodePosition(deviceSession, buf.toString(StandardCharsets.US_ASCII));

            if (type.equals("AL")) {
                if (position != null) {
                    position.set(Position.KEY_ALARM, Position.ALARM_SOS);
                }
                sendResponse(channel, id, index, "AL");
            }

Why do you override the alarm with SOS if the type is AL? It doesn't look right when I look at the logs, not when I look at the documentation, and not even when I look at the code here: org.traccar.protocol.WatchProtocolDecoder#decodeAlarm

     } else if (BitUtil.check(status, 16)) {
           return Position.ALARM_SOS;

The code already knows about the SOS bit.

Can I change decodeAlarm to return a comma separated list of all the strings who's bit is set to 1 and remove the override in WatchProtocolDecoder.java:249?

something like:

    private static final Map<Integer, String> alarmBit2Name = new HashMap<>();
    static {
        alarmBit2Name.put(0, Position.ALARM_LOW_BATTERY);
        alarmBit2Name.put(1, Position.ALARM_GEOFENCE_EXIT);
        alarmBit2Name.put(2, Position.ALARM_GEOFENCE_ENTER);
        alarmBit2Name.put(3, Position.ALARM_OVERSPEED);
        alarmBit2Name.put(16, Position.ALARM_SOS);
        alarmBit2Name.put(17, Position.ALARM_LOW_BATTERY);
        alarmBit2Name.put(18, Position.ALARM_GEOFENCE_EXIT);
        alarmBit2Name.put(19, Position.ALARM_GEOFENCE_ENTER);
        alarmBit2Name.put(20, Position.ALARM_REMOVING);
        alarmBit2Name.put(21, Position.ALARM_FALL_DOWN);

    }
    private String decodeAlarm(int status) {
        StringBuilder sb = new StringBuilder();
        boolean first = true;
        for (Map.Entry<Integer, String> entry : alarmBit2Name.entrySet()) {
            if (BitUtil.check(status, entry.getKey())) {
                if (first) {
                    first = false;
                } else {
                    sb.append(',');
                }
                sb.append(entry.getValue());
            }
        }
        return first ? null : sb.toString();
    }