"Hours" Accumulator not working

Sergio Hevia6 years ago

Hello All,
Anyone knows if there had been any change in the way the "Hours" accumulator works in last version (4.3).
I updated my Traccar server about two weeks ago and i realized that "Hours" accumulator it's not working anymore. It works with version 4.2.
Distance Accumulator works ok.
I double check my config file (Which its the same than the older version had) and everythings look fine.

Anyone can help???

Thanks in advance!!!

Anton Tananaev6 years ago

I don't think there were any changes to the accumulator. Have you checked if your device reports ignition correctly?

Sergio Hevia6 years ago

I use:

<entry key='processing.copyAttributes.enable'>true</entry>
<entry key='processing.copyAttributes'>power,ignition,battery</entry>

Protocol its gt06 from a chinese clone device tk103.
I check in the database and i got ignition in each record.

{"sat":7,"distance":47.26,"totalDistance":5885040.22,"ip":"85.52.230.131","motion":true,"hours":3600000,"ignition":true}
{"sat":6,"distance":52.88,"totalDistance":5885093.1,"ip":"85.52.230.131","motion":true,"hours":3600000,"ignition":true}
{"sat":6,"distance":50.41,"totalDistance":5885143.51,"ip":"85.52.230.131","motion":true,"hours":3600000,"ignition":true}
{"sat":6,"distance":48.5,"totalDistance":5885192.01,"ip":"85.52.230.131","motion":true,"hours":3600000,"ignition":true}
{"sat":7,"distance":48.0,"totalDistance":5885240.01,"ip":"85.52.230.131","motion":true,"hours":3600000,"ignition":true}
{"status":66,"ignition":true,"charge":false,"blocked":false,"batteryLevel":100,"rssi":15,"distance":0.0,"totalDistance":5885240.01,"ip":"85.52.230.131","motion":true,"hours":3600000}
{"sat":6,"distance":50.27,"totalDistance":5885290.28,"ip":"85.52.230.131","motion":true,"hours":3600000,"ignition":true}
{"sat":6,"distance":48.1,"totalDistance":5885338.38,"ip":"85.52.230.131","motion":true,"hours":3600000,"ignition":true}
{"sat":6,"distance":45.49,"totalDistance":5885383.87,"ip":"85.52.230.131","motion":true,"hours":3600000,"ignition":true}
{"sat":7,"distance":42.84,"totalDistance":5885426.71,"ip":"85.52.230.131","motion":true,"hours":3600000,"ignition":true}
{"sat":7,"distance":44.99,"totalDistance":5885471.7,"ip":"85.52.230.131","motion":true,"hours":3600000,"ignition":true}

But hours parameter keeps fixed in that value 3600000. Distance works ok.

Regards,

Anton Tananaev6 years ago

Maybe your device reports hours?

Sergio Hevia6 years ago

No. Its a simple tk103 clone device. No hours nor distance. For ignition its mandatory to copy attributes, other way its not possible to got it.

Sergio Hevia6 years ago

I attach a message fron the log as an example.

2019-04-10 15:32:59  INFO: [47f0ef4b: 5023 < 185.124.31.82] HEX: 78781f1213040a0d1b14c80497f6e9009b37aa093cbf000000000000000020bf2fb40d0a
2019-04-10 15:32:59  INFO: [47f0ef4b: 5023 > 185.124.31.82] HEX: 7878051220bfcceb0d0a
2019-04-10 15:32:59  INFO: [47f0ef4b] id: 352887079076752, time: 2019-04-10 15:27:20, lat: 42.81556, lon: -5.65129, speed: 4.9, course: 191.0

As long as i follow the code, when a position is received you add the interval time to the hours accum, but also i saw a resetDeviceAccumulators function that overwrites the current value with the one in the last postition.

I'm trying to follow the code from the reception of the msg to the ddbb saving, but i get lost in some points. If i found more clues i write down here.

Regards,

Sergio Hevia6 years ago

Ok, I think i found the "problem".
I was testing traccar with version 4.2. In that version everythings work ok (Accumulators also).
When i include the rest of devices and start some kind of production environment i change to Traccar 4.3.

The problem with this version and protocol GT06 is that i cannot get Engine Hours accum work.

The environment:
I have 11 devices with GT06 protocol. This devices didn't send "ignition" in each packet, so i decided to use:

<entry key='processing.copyAttributes.enable'>true</entry>
<entry key='processing.copyAttributes'>power,ignition,battery</entry>

In the database i found the "ignition" parameter its ok saved. So the problem must be in the way traccar deals with engineHours + copyAttributes.

I modified EngineHoursHandler:

protected Position handlePosition(Position position) {
        if (!position.getAttributes().containsKey(Position.KEY_HOURS)) {
            Position last = identityManager.getLastPosition(position.getDeviceId());
            if (last != null) {
                long hours = last.getLong(Position.KEY_HOURS);
                LOGGER.warn("Hours - 1 - " + hours );
                LOGGER.warn("Hours - 2 - Last position IGN  " + last.getBoolean(Position.KEY_IGNITION));
                LOGGER.warn("Hours - 3 - Current position IGN  " + position.getBoolean(Position.KEY_IGNITION));
                
                if (last.getBoolean(Position.KEY_IGNITION) && position.getBoolean(Position.KEY_IGNITION)) {
                    hours += position.getFixTime().getTime() - last.getFixTime().getTime();
                    LOGGER.warn("Hours - 4 - IGNITION ON - " + hours );
                }
                if (hours != 0) {
                    position.set(Position.KEY_HOURS, hours);
                    LOGGER.warn("Hours - 5 - SAVED - " + hours );
                }
            }
        }
        return position;
    }

I get the following in the log:

2019-04-22 17:49:55  INFO: [fea3fb40: gt06 < 85.52.243.76] HEX: 78781f121304160f313bc80497fa76009b4e7f003c0000d60327b0000bc10556ae370d0a
2019-04-22 17:49:55  INFO: [fea3fb40: gt06 > 85.52.243.76] HEX: 787805120556ebaf0d0a
2019-04-22 17:49:55  WARN: Hours - 1 - 18000000
2019-04-22 17:49:55  WARN: Hours - 2 - Last position IGN  true
2019-04-22 17:49:55  WARN: Hours - 3 - Current position IGN  false
2019-04-22 17:49:55  WARN: Hours - 3 - SAVED - 18000000
2019-04-22 17:49:55  INFO: [fea3fb40] id: 352887079076877, time: 2019-04-22 17:49:59, lat: 42.81607, lon: -5.65454, course: 0.0

So, the EngineHoursHandler never updates the engineHours. The problem seems to be in BasePipelineFactory:
I change this:

 addHandlers(
                pipeline,
                FilterHandler.class,
                GeocoderHandler.class,
                MotionHandler.class,
                EngineHoursHandler.class,                
                CopyAttributesHandler.class,
                ComputedAttributesHandler.class,
                WebDataHandler.class,
                DefaultDataHandler.class);

to this:

 addHandlers(
                pipeline,
                FilterHandler.class,
                GeocoderHandler.class,
                MotionHandler.class,
                CopyAttributesHandler.class,
                EngineHoursHandler.class,
                ComputedAttributesHandler.class,
                WebDataHandler.class,
                DefaultDataHandler.class);

The order in the handlers generates the problem. Traccar copy the attributes after handling the engine hours, so never updates.

I hope this could help some people with the same problem.

P.D. Its possible to change the order of the handlers in the "official" version Anton??

Regards,

Anton Tananaev6 years ago

Sure, send a pull request on GitHub.

Sergio Hevia6 years ago

Sended, Thanks for all!!!
Regards,

Saqib5 years ago

Sergio Hevia: where I can find this EngineHoursHandler file?

Rodrigo Oliveira4 years ago

Sergio, i am using version 4.2 of traccar and it is also not updating my hours, it could help me, i saw that you solved your problem by changing the BasePipelineFactory file but I did not find it in any Traccar folder. can you help me please?

Rapiego4 years ago

Hello Rodrigo,
My best advice is move to Traccar latest version.
If you canĀ“t, the BasePipelineFactory.java is in the root folder of Traccar project, but you need to recompile.
Regards,