1

Get Unit's Mileage

Тема: Get Unit's Mileage

Hi GT

I want to get unit's mileage via remote API and I guess the easiest way is to get them via events with data flag of counter.
Please advise me if there is easier way or more accurate one.
The problem I have now is that it takes time to update unit's mileages in events and we have some inaccuracy. If we check it when units are in stationary state then that's fine and we experience less inaccuracy but when a unit is moving with 120 KMH speed even 10 minutes for updating counters' values causes inaccuracy. I thought this problem may have a solution (in WL) from server side settings, maybe!

2

Get Unit's Mileage

Re: Get Unit's Mileage

Hi Hamed,

To get more frequent data about mileage counter it's possible via events methods - detector type 'counters'

To get online data you need to execute request events/check_updates
http://sdk.wialon.com/wiki/en/sidebar/r … ck_updates

More :

+ открыть спойлер

1. First (after login) it needs to add required units to session via request  svc=events/update_units
http://sdk.wialon.com/wiki/en/sidebar/r … date_units

https://hst-api.wialon.com/wialon/ajax.html?svc=events/update_units&params={"mode":"add","units":[{"id":23130642,"detect":{"counters":0}},{"id":21728414,"detect":{"counters":0}}]}&sid=0277a2aae551196a2eba9160ea3ab0b

"units" - units array where  'id' - unit's id, 'detect' - required events types, in our case only "counters":0 means to all counters data
2. After required units has been added to session, we can get online the mileage update via request events/check_updates which can be executed for example every 2 sec or rarely , it depends on how often the device sends data to the server

https://hst-api.wialon.com/wialon/ajax.html?svc=events/check_updates&params={"detalization":3}&sid=0277a2aae551196a2eba9160ea3ab0b5

First response returns the latest data (the latest message)
{
    "21728414": [
        {
            "counters": {
                "from": {
                    "t": 1618315947,
                    "y": 45.8113670349,
                    "x": 15.9847402573
                },
                "to": {
                    "t": 1618315947,
                    "y": 45.8113670349,
                    "x": 15.9847402573
                },
                "m": 1618315947,
                "f": 0,
                "engine_hours": 720000,
                "mileage": 981000,
                "bytes": 77272248
            }
        }
    ]
}

Next - empty response as there is not yet new messages coming

{}

New message coming

{
    "21728414": [
        {
            "counters": {
                "from": {
                    "t": 1618316007,
                    "y": 45.8113670349,
                    "x": 15.9847402573
                },
                "to": {
                    "t": 1618316007,
                    "y": 45.8113670349,
                    "x": 15.9847402573
                },
                "m": 1618316007,
                "f": 0,
                "engine_hours": 720000,
                "mileage": 981000,
                "bytes": 77272248
            }
        }
    ]
}

Next new messages, and mileage has been changed -

{
    "21728414": [
        {
            "counters": {
                "from": {
                    "t": 1618316172,
                    "y": 41.8631362915,
                    "x": 15.1339998245
                },
                "to": {
                    "t": 1618316172,
                    "y": 41.8631362915,
                    "x": 15.1339998245
                },
                "m": 1618316172,
                "f": 0,
                "engine_hours": 720000,
                "mileage": 1048965,
                "bytes": 77277336
            }
        }
    ]
}





{
    "21728414": [
        {
            "counters": {
                "from": {
                    "t": 1618316472,
                    "y": 41.8631362915,
                    "x": 11.1339998245
                },
                "to": {
                    "t": 1618316472,
                    "y": 41.8631362915,
                    "x": 11.1339998245
                },
                "m": 1618316472,
                "f": 0,
                "engine_hours": 720000,
                "mileage": 1825490,
                "bytes": 77277336
            }
        }
    ]
}

So you can calculated difference between messages for parameter 'mileage' (in meters)
In example above the total difference  is  (1825490 - 981000 ) / 10000 = 844.49 km

Diana Cheley
Wialon Hosting Expert
Gurtam