DMT Protocol - Missing Battery Level

JMVSL3 years ago

Hi,
the DMT protocol appears to be missing the battery level percentage (it has voltage) which would be particularly useful for battery powered devices.

It should be fieldID 21 "Profiling Counters"

It would be most helpful if this could be added into the DMT Protocol Decoder

Thanks
James

Anton Tananaev3 years ago

Sure, feel free to send a pull request.

JMVSL3 years ago

ok, I'm still trying to work out how to add this into the DMT Protocol - some pointers would be helpful. I'm not a developer.

The spec says:

FID = 21: Profiling Counters
Length = N
Reports long term, low frequency counters for performance monitoring and prediction.
This is commonly used on battery powered devices (Remora, Oyster, etc)


Offset       Data Type         Length          Field                  Description
-------------------------------------------------------------------------------------------------------
0               BYTE                   1                 Counter Id         Unique across device types
1               INT16/INT32       2/4             Counter Value   32-bit if top bit of Counter Id is set  11
1 + L0       BYTE                   1                 Counter Id  
2 + L0       INT16/INT32       2/4             Counter Value
-------------------------------------------------------------------------------------------------------

Counter Id’s:
-------------------------------------------------------------------------------------------------------
Id    Description            Scaling – LSb Equal To
-------------------------------------------------------------------------------------------------------
0     Internal Battery Voltage  1 mV
1     Internal Battery   0.01 %                       <<<--- This is the one we need
2     Est. Battery Capacity Used   1 mAh
3     Maximum Temperature   0.01 C°
4     Initial Internal Battery Voltage  1 mV
5     Average Successful GPS Fix Time  1 s per fix
6     Average Failed GPS Fix Time  1 s per failed fix
7     Average GPS Freshen Time   1 s per freshen attempt
8     Average Wakeups Per Trip   1 wakeup per trip

So I'm thinking that something like this needs adding to the DmtProtocolDecoder:

else if (fieldId == 21) {

                        while (buf.readerIndex() < fieldEnd) {
                            if(buf.readUnsignedIntLE() == 1) {
                                position.set(Position.KEY_BATTERY_LEVEL, buf.readUnsignedIntLE() *1000);
                            }
                        }
                }

I've tried this and it doesn't work, so I'm obviously missing something... as I say, not a developer :)

JMVSL3 years ago

I have this working now, but probably not the most elegant solution:

else if (fieldId == 21) {

                    buf.readUnsignedByte();     // Id 0 - Internal Battery Voltage
                    position.set("altBatteryVoltage", buf.readUnsignedShortLE() * 0.001 ); // val 0 - Internal Battery Voltage
                    buf.readUnsignedByte();     // Id 1 - Internal Battery Percent
                    position.set(Position.KEY_BATTERY_LEVEL, buf.readUnsignedShortLE() * 0.01);
                    buf.readUnsignedByte();     // Id 2 - Internal Battery ah used
                    position.set("batteryAhUsed", buf.readUnsignedShortLE() * 0.01);
                    buf.readUnsignedByte();     // Id 3 - Internal Battery ah used
                    position.set("maxTemp", buf.readUnsignedShortLE() * 0.01);
                    buf.readUnsignedByte();     // Id 4 - Internal Battery initial Voltage
                    position.set("initialVoltage", buf.readUnsignedShortLE() * 0.001);

                } 

I'm thinking it would be better to loop through each of the counters?

JMVSL3 years ago

although this works, it doesn't seem to get copied across to every position with the copy attributes option set - any thoughts?

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

others do copy over without any issue

Anton Tananaev3 years ago

Should be copied. Make sure it matches the key exactly.

JMVSL3 years ago

It definitely looks to match:

    <entry key="processing.copyAttributes.enable">true</entry>
        <entry key="processing.copyAttributes">power,ignition,motion,batteryLevel</entry>
 public static final String KEY_BATTERY_LEVEL = "batteryLevel"; // percentage
id	                attributes
23429953            {"index":865,"event":42,"altBatteryVoltage":3.9170000000000003,"batteryLevel":99.9,"batteryAhUsed":0.03,"maxTemp":0.0,"initialVoltage":2.319,"distance":4.42,"totalDistance":49752.78,"motion":false,"hours":2866000}
23429952            {"index":864,"event":11,"pdop":1.6,"ignition":false,"input":2,"output":0,"status":2,"battery":3.9170000000000003,"deviceTemp":23.19,"rssi":19,"solarPower":3.857,"distance":4.42,"totalDistance":49748.36,"motion":false,"hours":2866000}
23429951            {"index":861,"event":21,"distance":0.0,"totalDistance":49743.94,"motion":false,"hours":2866000}
23429950            {"index":860,"event":21,"distance":0.0,"totalDistance":49743.94,"motion":false,"hours":2866000}
23429949            {"index":859,"event":21,"distance":0.0,"totalDistance":49743.94,"motion":false,"hours":2866000}
23429948            {"index":858,"event":21,"distance":0.0,"totalDistance":49743.94,"motion":false,"hours":2866000}
23429947            {"index":857,"event":21,"distance":0.0,"totalDistance":49743.94,"motion":false,"hours":2866000}
23429946            {"index":856,"event":42,"altBatteryVoltage":3.938,"batteryLevel":99.94,"batteryAhUsed":0.01,"maxTemp":0.0,"initialVoltage":2.271,"distance":6.86,"totalDistance":49750.8,"motion":true,"hours":2866000}
23429945            {"index":855,"event":11,"pdop":2.0,"ignition":false,"input":2,"output":0,"status":2,"battery":3.938,"deviceTemp":22.71,"rssi":19,"solarPower":3.887,"distance":6.86,"totalDistance":49743.94,"motion":false,"hours":2866000}
23429944            {"index":852,"event":21,"distance":0.0,"totalDistance":49737.08,"motion":true,"hours":2866000}
23429943            {"index":851,"event":21,"distance":0.0,"totalDistance":49737.08,"motion":true,"hours":2866000}
23429942            {"index":850,"event":21,"distance":0.0,"totalDistance":49737.08,"motion":true,"hours":2866000}
23429941            {"index":849,"event":21,"distance":0.0,"totalDistance":49737.08,"motion":true,"hours":2866000}
23429940            {"index":848,"event":21,"distance":0.0,"totalDistance":49737.08,"motion":true,"hours":2866000}
JMVSL3 years ago

After a bit more digging, it looks like none of the copy attributes are working (note ignition isn't copied either).

Possibly a bug in 4.11?

The only change I have made is the addition of the code above, which I presume shouldn't break it.

I'll test it in untouched 4.12 and see if it exists there too.

It was working in my current live version 4.08 as I've restored my live database to test server and can see the attributes stop copying at the point of upgrade.

JMVSL3 years ago

Testing seems to suggest that the above seems to break attribute copying in 4.11

JMVSL3 years ago

It appears that this is broken in an untouched build of 4.11 too

JMVSL3 years ago

ok, I can only assume that somehow my compiling of the tracker-server file is breaking the copyAttributesHandler

Some pointers would be appreciated. Is there anything I can check? I've tried starting the server in "fine" and "finer" logging modes and there don't seem to be any errors or anything at the point of adding positions.