calc_last

To get the last known sensor values, counters, and position for units, use the unit/calc_last method.

To get the data, you need the View object and its basic properties access right to every unit specified in the request.

Endpoint

Copied!
svc=unit/calc_last&params={
    "itemIds": [<long>]
}

Parameters

The request must contain the following parameter:

Parameter Description
itemIds Array of IDs of the units for which you want to get the last known values. The array mustn’t be empty.

Example

Below is an example of the unit/calc_last request.

Copied!
svc=unit/calc_last&params={
    "itemIds": [16091323, 16454260]
}

Response

If the request is completed successfully, the response is returned in the following format:

Copied!
[
    {
        "i": <long>,         /* Unit ID */
        "mileage": {         /* Mileage counter */
            "value": <double>,
            "format": {
                "value": <text>  /* Formatted value with units of measurement (for example, "24498.82 km") */
            }
        },
        "engine_hours": {    /* Engine hours counter */
            "value": <double>,
            "format": {
                "value": <text>  /* Formatted value with units of measurement (for example, "0.00 h") */
            }
        },
        "pos": {             /* Last known position */
            "y": <double>,   /* Latitude */
            "x": <double>,   /* Longitude */
            "c": <int>,      /* Course */
            "z": {           /* Altitude */
                "value": <double>,
                "format": {
                    "value": <text>  /* Formatted value with units of measurement (for example, "139.00 m") */
                }
            },
            "s": {           /* Speed */
                "value": <double>,
                "format": {
                    "value": <text>  /* Formatted value with units of measurement (for example, "75.00 km/h") */
                }
            },
            "sc": <int>      /* Number of satellites */
        },
        "sensors": {         /* Values of all sensors of the unit */
            "<sensor_id>": {
                "value": <double|text>,    /* Sensor value */
                "format": {
                    "value": <text>        /* Formatted sensor value with units of measurement */
                }
            }
        }
    }
]

The response has the following features:

  • The sensors section contains all sensors of the unit. For sensors that return text values, value contains text instead of a number.
  • If a sensor value falls into a custom value interval with a text description (the ci parameter of the unit/update_sensor method), the format section contains this description followed by the value in parentheses.
  • If a value can’t be calculated, --- is returned instead of it.
  • If the unit has no messages with a position, all the pos fields are set to zero.
  • Values are converted to the measurement system of the current session, which you can set with the render/set_locale method.

If the request fails, an error code is returned.

Error codes

Error code Description
4 Invalid input parameters.
7 No View object and its basic properties access right to units.

If you find a mistake in the text, please select it and press Ctrl+Enter.