Skip to content

Update Total Distance and Hours

Update the total distance and engine hours for a specific device.

WARNING

  • Do not use uniqueID inplace of id (device id)
  • The device must have at least one position recorded in the database else the update will fail.

Usage

php
use ThingsTelemetry\Traccar\Dto\StatusData;
use ThingsTelemetry\Traccar\Enums\Status;
use ThingsTelemetry\Traccar\Facades\Device;

$deviceId = 6;
$totalDistance = 12345.6; // in meters
$hours = 789.0; // hours

$result = Device::updateTotals(deviceId: $deviceId, totalDistance: $totalDistance, hours: $hours); // returns ThingsTelemetry\Traccar\Dto\StatusData

if ($result->status === Status::SUCCESS) {
    // Totals updated successfully
}

Results

The response is a ThingsTelemetry\Traccar\Dto\StatusData object containing a ThingsTelemetry\Traccar\Enums\Status. A 204 response is treated as success.

php
$result->status->value; // 'success' or 'failure'
$result->status->label(); // 'Success' or 'Failure'

Errors

400 - Bad Request (400) Response: java.lang.IllegalArgumentException

shell
Bad Request (400) Response: java.lang.IllegalArgumentException at org.traccar.api.resource.DeviceResource.updateAccumulators(DeviceResource.java:183)

This means the device does not have any positions recorded in the database. Record some positions before updating the totals.

Released under the MIT License.