Researching APIs to push updates to Traccar --

Phonebuff 4 years ago

Good morning all,

I have been reading documentation and various posts and unfortunately I need to ask for a little help --

I have three specific feeds that are currently pushed to Esri GeoEvent / Velocity as JSON objects. Now someone is asking if we can push the same JSON objects to Traccar as well. I see a number of GPS update processes and all sorts of "protocols". I even see APIs for retrieving data from Traccar and an a reference to MQTT. But I really can't find a document or forum posting with regards to pushing Restful state JSON updates to Traccar.

I hope I am just not looking in the right place as I have not been here in a couple of years.

TIA.
Jeff -

Anton Tananaev 4 years ago

There are a few JSON-based protocols available. I would recommend source code. You can check unit tests for samples.

Phonebuff 4 years ago

So I missed something --

Built an AWS Debian Instanace an have Traccar installed --

Screen Comes up but the Device shows as Offline and The Position does not report -- So I must have missed some relationship I need to build --

Looking at source now, but maybe someone can give me a couple of quick tips as to which other tables I need to update / set values in ..

TIA --

mysql> select * from traccar.tc_positions ;
+----+----------+----------+---------------------+---------------------+---------------------+--------------+-----------+-------------+----------+-------+--------+---------+------------+----------+---------+
| id | protocol | deviceid | servertime          | devicetime          | fixtime             | valid        | latitude  | longitude   | altitude | speed | course | address | attributes | accuracy | network |
+----+----------+----------+---------------------+---------------------+---------------------+--------------+-----------+-------------+----------+-------+--------+---------+------------+----------+---------+
|  1 | LRRP     |        1 | 2022-03-21 00:00:00 | 2022-03-21 00:00:00 | 2022-03-21 00:00:00 | 0x01         | 39.880083 | -105.794471 |   2965.9 |   0.1 |     14 | NULL    | NULL       |      4.6 | NULL    |
+----+----------+----------+---------------------+---------------------+---------------------+--------------+-----------+-------------+----------+-------+--------+---------+------------+----------+---------+
1 row in set (0.00 sec)

mysql> select * from traccar.tc_devices;
+----+--------+--------------+---------------------+------------+---------+------------+-------+-------+---------+----------+--------------------+
| id | name   | uniqueid     | lastupdate          | positionid | groupid | attributes | phone | model | contact | category | disabled           |
+----+--------+--------------+---------------------+------------+---------+------------+-------+-------+---------+----------+--------------------+
|  1 | SPN067 | pcrid:447.67 | 2022-03-21 00:00:00 |          1 |    NULL | {}         |       |       |         | NULL     | 0x00               |
+----+--------+--------------+---------------------+------------+---------+------------+-------+-------+---------+----------+--------------------+
1 row in set (0.00 sec)
Anton Tananaev 4 years ago

Are you writing data directly to the database bypassing Traccar?

Phonebuff 4 years ago

I added the Device through the GUI, did a manual insert into tc_positions and then updated device with the last update and the position id value..

mysql> INSERT INTO traccar.tc_positions ( protocol, deviceid, servertime, devicetime, fixtime, latitude, longitude, altitude, speed, course, accuracy, valid)     VALUES("LRRP", 1, date("2022-03-21 14:03:06"), date("2022-03-21 14:03:00"), date("2022-03-21 14:03:00"), 39.880083 , -105.794471 , 2965.9, 0.1, 14, 4.6, TRUE);
Query OK, 1 row affected (0.01 sec)

mysql> update traccar.tc_devices set lastupdate = date("2022-03-21 00:00:00"), positionid = 1;
Query OK, 1 row affected (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 0
Anton Tananaev 4 years ago

Yeah, it won't work for many reasons. You should push data through Traccar via one of the supported protocols.

Phonebuff 4 years ago

I did try -- Getting an error 400.

http://127.0.0.1:5055/?id=1&lat=39.880083&LON=-105.794471&TIMESTAMP=2022-03-21%2014:03:00&ALTITUDe=2965.9&speed=0.1
Phonebuff 4 years ago

Which is because IZ used the OID not the Description Device ID value -

http://127.0.0.1:5055/?id=pcrid:447.67&lat=39.880083&LON=-105.794471&TIMESTAMP=2022-03-21%2014:03:00&ALTITUDe=2965.9&speed=0.1
Phonebuff 4 years ago

Although the data in the table is wrong -- So even that I am not doing correctly apparently :-(

An even more strange because the Lat is Right the Lon is wrong, but Lat does not show in the Attributes string while Lon with the correct value does --

mysql> select * from traccar.tc_positions where id = 2;
+----+----------+----------+---------------------+---------------------+---------------------+--------------+-----------+-----------+----------+-------+--------+---------+--------------------------------------------------------------------------------------------------------------------------+----------+---------+
| id | protocol | deviceid | servertime          | devicetime          | fixtime             | valid        | latitude  | longitude | altitude | speed | course | address | attributes                                                                                                               | accuracy | network |
+----+----------+----------+---------------------+---------------------+---------------------+--------------+-----------+-----------+----------+-------+--------+---------+--------------------------------------------------------------------------------------------------------------------------+----------+---------+
|  2 | osmand   |        1 | 2022-03-21 19:25:05 | 2022-03-21 19:25:05 | 2022-03-21 19:25:05 | 0x01         | 39.880083 |         0 |        0 |   0.1 |      0 | ES      | {"LON":-105.794471,"TIMESTAMP":"2022-03-21 14:03:00","ALTITUDe":2965.9,"distance":0.0,"totalDistance":0.0,"motion":true} |        0 | null    |
+----+----------+----------+---------------------+---------------------+---------------------+--------------+-----------+-----------+----------+-------+--------+---------+--------------------------------------------------------------------------------------------------------------------------+----------+---------+
1 row in set (0.00 sec)
Anton Tananaev 4 years ago

If you carefully look at your request you'll see the difference between the way you pass coordinates.

Phonebuff 4 years ago

So it's case sensitive :-(