Use get request to get location of a gps using Traccar Client Services

Hi to all.

I think what i am trying is something new, 'cause a have no seen nothing here to help me.

I’m Phd. Transportation Student from The University of Puerto Rico.

We are working i a project to locate Buses using cellphones. We want to get the location of a cell phone that has a client service that transmit several attributes (like geographic location) to a server.
I started to test the programs that store and transmit the location.

First, i have downloaded the client in my cellphone. The program i have use is called Traccar.

Once installed, i run the app, and it gives a cell a unique id. Device Identifier

I have to specifies the server address. The address is shown in the next figure.

And then, start the services.

After the installation in my cellphone, i go to the server address: demo.traccar.org, and introduce my credentials

Once done, the webb loads, and i can see the location of my phone.

And the geographic coordinates (latitude, longitude) of my device

The question is, How can i get the latitude, longitude, speed, time-stamp or other information, using the Get Service Node ?

i have followed the basics of " Sending a GET Request to a REST service" that is in this link:
https://www.knime.com/knime-introductory-course/chapter2/section3/sending-get-request-to-rest-service

The address of the server:

My credentials:

But all i can get is this output, without the information that i need.

I have read in that link : https://www.traccar.org/forums/reply/49688/ , that the folowing code works in Python3.:

import json
import requests

###Settings####
TCurl = ''            #Server address of traccar system i.e. 'http://demo.traccar.org'
TCportR = ''                        #port for traccar system usually ':8082' 
Traccar_user = ''                #User for traccar (user needs to have access to group in where devices are located) 
Traccar_password = ''                #Traccar User password

headers = {'Content-type': 'application/json', 'Accept': 'application/json'}

data={
'id':None,
'name':'RWS 20',
'uniqueId':'SEA-244690995',
'lastUpdate':None,
'positionId':'',
'groupId':15,
'attributes':{},
'phone':'',
'model':'',
'contact':'',
'category':'boat',
'disabled':False,
'status':None
}
response = requests.post(TCurl + TCportR + '/api/devices', auth=(Traccar_user, Traccar_password), headers=headers, data=json.dumps(data))
print (response.content)
print (response.status_code)

I have trying to use it in the Python source node, but with no luck.

Please, somebody help me in that.

1 Like

Hi there @jodomofo,

interesting project indeed! Once you’ll have data in KNIME what analysis are you planning?

Seems to me the next thing to do is to learn Traccar API. When you do that you’ll figure out how to configure and with what data to feed GET Request node in order to return data you want.

Here is Traccar’s API info page: https://www.traccar.org/traccar-api/

If you need additional mobile phone for testing let me know :wink:

Br,
Ivan

Hi @ipazin.
Thanks for your response.

I have already made a workflow to process the data, by cleaning and restructure it, but with static AVL data (AVL for automatic vehicle location). We want now to do it with dynamic data (in real time), to estimate performance measure, like the headway on a bus-stop.

I have tried to understand of getting info from traccar by a request, but i still don’t get it !. Unfortunately the documentation is not so clear to me, and the support is not good enough.

I know the code presented in python may work, but i don’t know how to correlate this code with the data to be introduce in get request node, to get the response for location of the device or other information.

Hi @jodomofo,

From what I see you’ll have to feed data to Get Request node in JSON format. But seems you’ll have to learn more about REST API in general for this project. Then figure out Traccar’s API and then use KNIME to get data.

Good luck!

Br,
Ivan

Hi @ipazin.

I have figured out ho to do it !

I still don’t understand so much. But you can access the information making a request via web using this sentence or format:

http://Username:Password@demo.traccar.org/api/... (1)

Where Username and Password are the credencial to enter in the server. The information that i want to get, is specified in the end fo the url form showed in (1).

If i wanna know something about the gps, like the id i have to use “/devices”. If i wanna know the position of the gps i have to use “/positions”, like the examples below:

http://Username:Password@demo.traccar.org/api/devices (2)
http://Username:Password@demo.traccar.org/api/positions (3)

The references can be taken from the documentation page of traccar that you correctly mentioned:

https://www.traccar.org/api-reference/

The web request using (2), give the following response via webpage:

The web request using (1), give the following response via webpage:

So far, so good. Now into knime !
We can use the Get Response node to have access. Just writing the url showed in (4) and (5) in the Connection Settings from the configuration of the node, like i show in the next figure.

http://demo.traccar.org/api/devices (4)
http://demo.traccar.org/api/positions (5)


In the Authentication tab, we have to write the credentials (Username and Password)

In the Request Headers tab, we can use the template to add headers parameters. It is necessary to add this two showed in the next figure:

Header Key: Accept
Header Value: application/json; charset=utf-8
Value kind: Constant
Header Key: Content-Type
Header Value: application/json; charset=utf-8
Value kind: Constant

In the Respose Headers tab, we can use the checkbox “Extract all headers”, like i show in the next figure:

The result is in json format, and it can be easy extract using knime nodes.

Here is the workflow to access to traccar. Just write your credentials in the Authentication tab.

The first node “Table Creator”, is because the loop node needs a initial information (i think it is). The other nodes are to convert the json format to table form. The loop is to define an interval to acces. For example, if i wanna get the record of a location from a device gps for 1 hour, for each 5 seconds, i can set the Interval Loop Start from 0 to 12 iterations and the Wait node to 00:00:05 seconds

Workflow:
GetTraccar.knwf (22.6 KB)

Thanks @ipazin for your interest to help me. I hope this can help anyone else.

2 Likes

A post was split to a new topic: Process data in real time

Hi @jodomofo,

glad you made it :wink:

Moved your new question to new topic cause it is different problem.

Br,
Ivan

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.