The location data is not updating

Sasi Kiran24 days ago

Hi all,

I'm encountering an issue with my integration to the Traccar server. I'm successfully sending location data, but it isn't updating on the server. Here's a breakdown of the setup and the code I'm using.

Environment:
Language: Java
Framework: Spring Boot
Endpoint: Traccar server

This is the url i am using :
http://<my ip address>:5055/?id=7396312531&lat=16.309433&lon=80.453514&timestamp=2025-02-03T22:20:02Z&hdop=0&altitude=0&speed=0.000000

Problem: The code successfully sends data to the Traccar server and receives a 200 OK response, but the location data does not update on the Traccar server.

What I've Tried:

Ensured the timestamp is converted to UTC.Confirmed the server URL and parameters are correct.Verified that the phone number format is as expected.

I'm looking for guidance on what might be going wrong or any suggestions on how to further debug this issue.

Thank you in advance for your help!

Anton Tananaev24 days ago

What do you see in the server logs?

Sasi Kiran23 days ago

public void sendDataToTraccar(LocationData locationData) {

        // Parse the original timestamp in IST and convert to UTC
        DateTimeFormatter originalFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS Z");
        LocalDateTime localDateTime = LocalDateTime.parse(locationData.getTimestamp(), originalFormatter);
        ZonedDateTime istZonedDateTime = localDateTime.atZone(ZoneId.of("Asia/Kolkata"));
        ZonedDateTime utcZonedDateTime = istZonedDateTime.withZoneSameInstant(ZoneId.of("UTC"));

        // Format the timestamp as 'yyyy-MM-dd'T'HH:mm:ss'Z''
        DateTimeFormatter desiredFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss'Z'");
        String formattedTimestamp = utcZonedDateTime.format(desiredFormatter);

        String phoneNumber = locationData.getPhoneNumber();
        if (phoneNumber.startsWith("91")) {
            phoneNumber = phoneNumber.substring(2); // Remove the "91" prefix
        }

        // Constructing the request body
        String payload = String.format(url + "?id=%s&lat=%f&lon=%f&timestamp=%s&hdop=0&altitude=0&speed=%f",
                phoneNumber,
                locationData.getLatitude(),
                locationData.getLongitude(),
                formattedTimestamp,
                locationData.getAverageSpeed()
        );
        System.out.println(payload);

        HttpHeaders headers = new HttpHeaders();
        HttpEntity<String> request = new HttpEntity<>(headers);

        try {
            ResponseEntity<String> response = restTemplate.exchange(payload, HttpMethod.POST, request, String.class);

            if (response.getStatusCode() == HttpStatus.OK) {
                System.out.println("Data sent successfully to Traccar for phone number: " + locationData.getPhoneNumber());
            } else {
                System.out.println("Failed to send data to Traccar for phone number: " + locationData.getPhoneNumber());
            }
        } catch (HttpClientErrorException e) {
            System.out.println("Error sending data to Traccar for phone number: " + locationData.getPhoneNumber() +
                    ". Status code: " + e.getStatusCode() + ", Response body: " + e.getResponseBodyAsString());
            // Handle the exception and continue processing
        } catch (Exception e) {
            System.out.println("Unexpected error occurred for phone number: " + locationData.getPhoneNumber() +
                    ". Error: " + e.getMessage());
            // Handle the exception and continue processing
        }
    }

This is my code snippet and the below one are my server logs and there is no error in server logs

http://<my ip address>:5055/?id=7396312531&lat=16.334368&lon=80.449110×tamp=2025-02-04T02:35:02Z&hdop=0&altitude=0&speed=0.000000
Data sent successfully to Traccar for phone number: 917396312531
http://<my ip address>:5055/?id=9874331723&lat=22.483600&lon=88.375300×tamp=2025-02-04T02:37:21Z&hdop=0&altitude=0&speed=0.000000
Data sent successfully to Traccar for phone number: 919874331723
http://<my ip address>:5055/?id=8123932531&lat=12.933057&lon=77.736020×tamp=2025-02-04T02:42:19Z&hdop=0&altitude=0&speed=0.000000
Data sent successfully to Traccar for phone number: 918123932531

And in the Traccar dashboard, for my device it is showing the time like this
Device Time 02/04/2025, 01:35:02 PM
Fix Time 02/04/2025, 01:35:02 PM

Sasi Kiran23 days ago

In the URL i am sending the UTC timestamp as it accepts, so now in my browser it should show the current IST(indian standard time) right?, but it is showing around 5hr 30mins Ahead of IST, WHY?
And in the Traccar dashboard, for my device it is showing the time like this
Device Time 02/04/2025, 01:35:02 PM
Fix Time 02/04/2025, 01:35:02 PM

Anton Tananaev23 days ago

I recommend sending unix timestamp. If you send formatted time, send with the timezone.

Sasi Kiran23 days ago

These are the logs

2025-02-04 05:42:48  INFO: [T95a2662b] connected
2025-02-04 05:42:48  INFO: [T95a2662b: osmand < 13.235.32.114] POST /?id=7396312531&lat=16.334368&lon=80.449110×tamp=2025-02-04T05:35:02Z&hdop=0&altitude=0&speed=0.000000 HTTP/1.1\r\nAccept: text/plain, application/json, application/cbor, application/*+json, */*\r\nUser-Agent: Java/11.0.26\r\nHost: 35.200.176.48:5055\r\nConnection: keep-alive\r\nContent-type: application/x-www-form-urlencoded\r\nContent-Length: 0\r\n\r\n
2025-02-04 05:42:48  INFO: [T95a2662b] id: 7396312531, time: 2025-02-04 05:35:02, lat: 16.33437, lon: 80.44911, course: 0.0
2025-02-04 05:42:48  INFO: [T95a2662b: osmand > 13.235.32.114] HTTP/1.1 200 OK\r\ncontent-length: 0\r\n\r\n

2025-02-04 05:42:48  INFO: [T95a2662b: osmand < 13.235.32.114] POST /?id=9874331723&lat=22.483600&lon=88.375300×tamp=2025-02-04T05:37:33Z&hdop=0&altitude=0&speed=0.000000 HTTP/1.1\r\nAccept: text/plain, application/json, application/cbor, application/*+json, */*\r\nUser-Agent: Java/11.0.26\r\nHost: 35.200.176.48:5055\r\nConnection: keep-alive\r\nContent-type: application/x-www-form-urlencoded\r\nContent-Length: 0\r\n\r\n
2025-02-04 05:42:48  INFO: Event id: 9874331723, time: 2025-02-04 05:42:48, type: deviceOnline, notifications: 0
2025-02-04 05:42:48  INFO: [T95a2662b] id: 9874331723, time: 2025-02-04 05:37:33, lat: 22.48360, lon: 88.37530, course: 0.0
2025-02-04 05:42:48  INFO: [T95a2662b: osmand > 13.235.32.114] HTTP/1.1 200 OK\r\ncontent-length: 0\r\n\r\n

2025-02-04 05:42:48  INFO: [T95a2662b: osmand < 13.235.32.114] POST /?id=8123932531&lat=12.932584&lon=77.736290×tamp=2025-02-04T05:42:23Z&hdop=0&altitude=0&speed=0.000000 HTTP/1.1\r\nAccept: text/plain, application/json, application/cbor, application/*+json, */*\r\nUser-Agent: Java/11.0.26\r\nHost: 35.200.176.48:5055\r\nConnection: keep-alive\r\nContent-type: application/x-www-form-urlencoded\r\nContent-Length: 0\r\n\r\n
2025-02-04 05:42:48  INFO: Event id: 8123932531, time: 2025-02-04 05:42:48, type: deviceOnline, notifications: 0
2025-02-04 05:42:48  INFO: [T95a2662b] id: 8123932531, time: 2025-02-04 05:42:23, lat: 12.93258, lon: 77.73629, course: 0.0
2025-02-04 05:42:48  INFO: [T95a2662b: osmand > 13.235.32.114] HTTP/1.1 200 OK\r\ncontent-length: 0\r\n\r\n
2025-02-04 05:42:48  INFO: [T95a2662b: osmand < 13.235.32.114] POST /?id=8290748131&lat=12.933135&lon=77.735980×tamp=2025-02-04T05:41:22Z&hdop=0&altitude=0&speed=0.000000 HTTP/1.1\r\nAccept: text/plain, application/json, application/cbor, application/*+json, */*\r\nUser-Agent: Java/11.0.26\r\nHost: 35.200.176.48:5055\r\nConnection: keep-alive\r\nContent-type: application/x-www-form-urlencoded\r\nContent-Length: 0\r\n\r\n
Anton Tananaev23 days ago

The time looks correct in the logs.