This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

HTTP GET with authorisation
#1
Hello,

I want integrate with Traccer server. This server give the JSON when I log in and brows such address:
http://demo.traccar.org/api/positions/


But for LM communication I must have some authorisation. What should I add to this script?

Code:
-- load required modules
http = require("socket.http")
mime = require("mime")

-- Alternatively, one could fill the appropriate header and authenticate
-- the request directly.
r, c, d, e = http.request {
  url = "http://demo.traccar.org/api/positions/",
  headers = { authorization = "Basic " .. (mime.b64("login:password")) }
}

log(r,c,d,e)
Now it gives:

Code:
* arg: 1
 * number: 1
* arg: 2
 * number: 200
* arg: 3
 * table:
  [server]
   * string: Jetty(9.2.19.v20160908)
  [content-type]
   * string: application/json
  [connection]
   * string: close
  [content-length]
   * string: 393
  [access-control-allow-headers]
   * string: origin, content-type, accept, authorization
  [access-control-allow-origin]
   * string: *
  [date]
   * string: Sat, 29 Oct 2016 22:39:46 GMT
  [access-control-allow-credentials]
   * string: true
  [access-control-allow-methods]
   * string: GET, POST, PUT, DELETE, OPTIONS
* arg: 4
 * string: HTTP/1.1 200 OK

[b]Traccar[/b] 30.10.2016 00:39:27
* arg: 1
 * number: 1
* arg: 2
 * number: 200
* arg: 3
 * table:
  [server]
   * string: Jetty(9.2.19.v20160908)
  [content-type]
   * string: application/json
  [connection]
   * string: close
  [content-length]
   * string: 393
  [access-control-allow-headers]
   * string: origin, content-type, accept, authorization
  [access-control-allow-origin]
   * string: *
  [date]
   * string: Sat, 29 Oct 2016 22:39:27 GMT
  [access-control-allow-credentials]
   * string: true
  [access-control-allow-methods]
   * string: GET, POST, PUT, DELETE, OPTIONS
* arg: 4
 * string: HTTP/1.1 200 OK

Login is an email so it has '@'.
Reply
#2
200 status means that requests work correctly, you just have to get the response like this:
Code:
-- load required modules
http = require("socket.http")
mime = require("mime")
ltn12 = require("ltn12")

t = {}

r, c, d, e = http.request {
  url = "http://demo.traccar.org/api/positions/",
  headers = { authorization = "Basic " .. (mime.b64("login:password")) },
  sink = ltn12.sink.table(t)
}

response = table.concat(t)
log(response)
Reply
#3
It works perfectlyWink
Reply
#4
Hi Buuuuudzik,
the first code is saved as user script? What about the second script?
How is it managed?
Thanks.

Do you use it for geofencis? Because it seems Traccar does not support geofencis.
Thank you for your help.
Regards.
Reply
#5
(04.11.2016, 17:27)Domoticatorino Wrote: Hi Buuuuudzik,
the first code is saved as user script? What about the second script?
How is it managed?
Thanks.

Do you use it for geofencis? Because it seems Traccar does not support geofencis.
Thank you for your help.
Regards.

Traccar has 2 applications:
- server (you can use demo server or you can install server on your pc) or you can use LM as a server for clients,
- clients (iOS, Android etc.) (you can set interval for sending data to server)

This is the example respond from the server:
* string: [{"id":123141121,"attributes":{"battery":"0","ip":"37.47.0.6","distance":0.0,"totalDistance":4.865613311E7},"deviceId":34294,"type":null,"protocol":"osmand","serverTime":null,"deviceTime":"2016-10-30T08:05:35.000+0000","fixTime":"2016-10-30T08:05:35.000+0000","outdated":false,"valid":true,"latitude":50.98288,"longitude":23.170059,"altitude":185.619,"speed":0.0,"course":0.0,"address":null}]

You have this data from server and for example you can use it for detecting how far some person is from home etc. For Geofencing you must use additionally some other server which converts latitude and longtitude into e.g. city.
Reply
#6
Thank you.
But what is the procedure to install the server on LM?
Please consider that I am using Homelynk by Schneider.
Thank you?
Reply
#7
Here is a ready example for Geolocalization with LogicMachine based on Traccar service:
http://openrb.com/geolocalization-with-l...ar-service

Thanks to buuuudzik for this nice step-by-step guide! Smile
Reply
#8
Hi Edgards,
Does it work with iPhone only?
Reply
#9
No, it works on iphone and android and on a lot of professional gps trackers.

Look here for information about mobile clients:
https://www.traccar.org/client/

List of GPS tracking devices and applications supported by Traccar server:
https://www.traccar.org/devices/
Reply
#10
battery drain is very high on iphones
Reply


Forum Jump: