You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

172 lines
5.9 KiB

10 years ago
7 years ago
8 years ago
9 years ago
8 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
  1. # Compass
  2. Compass is a GPS tracking server that stores data in [flat files](https://github.com/aaronpk/QuartzDB).
  3. ![mapview](screenshot-mapview.jpg)
  4. ## Requirements
  5. * PHP 5.5 or above
  6. * MySQL (for storing user accounts and lists of databases, not for storing the actual location data)
  7. This branch has been verified for PHP 8 compatibility, including PHP 8.0 and
  8. PHP 8.4.
  9. ### PHP extensions
  10. You'll need to make sure the following PHP extensions are installed. Typically these are installed using the package manager of your operating system.
  11. * curl
  12. * mbstring
  13. * zip
  14. * unzip
  15. ### Optional
  16. * Redis (for the job queue, can use MySQL instead)
  17. ## Setup
  18. Compass is built using the [Lumen framework](https://lumen.laravel.com/). If you have any trouble getting started, you can refer to the [Lumen documentation](https://lumen.laravel.com/docs/5.1) for tips that may have been skipped or assumed in these instructions.
  19. In the `compass` directory, copy `.env.example` to `.env` and fill in the details. Install the dependencies with composer.
  20. ```
  21. $ composer install
  22. ```
  23. Once you've created the database and configured the settings in `.env`, run the migrations to set up all the tables.
  24. ```
  25. $ php artisan migrate
  26. ```
  27. ### Web Server
  28. Your web server will need to support URL re-routing to the index.php file of compass. This will vary based on your web server.
  29. - If you're using Apache, this will involve URL re-writing likely using .htaccess
  30. - If you're using Nginx, this will involve incorporating the following code into your server block, you should also add any applicable fastcgi settings inside the location block below:
  31. ```
  32. try_files $uri /index.php?$args;
  33. location /index.php {
  34. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  35. }
  36. ```
  37. ### Job Queue
  38. For the job queue you will either need to have one of the supported options by Lumen. The two most likely options are an SQL database or Redis.
  39. You can find other supported options [here](https://lumen.laravel.com/docs/5.1/queues#introduction)
  40. If you're using the database queue driver (`QUEUE_DRIVER=database` defined in `.env`), you'll need to create the migration for that table:
  41. ```
  42. $ php artisan queue:table
  43. $ php artisan migrate
  44. ```
  45. If you're using Redis, make sure you've installed the Redis server and set `QUEUE_DRIVER=redis`.
  46. Make sure the storage folder you've defined in `STORAGE_DIR` is writable by the web server (or by the PHP process if you're using php-fpm).
  47. To process jobs on the queue, run
  48. ```
  49. $ php artisan queue:listen
  50. ```
  51. For more details on how to configure this to run in the background, see https://lumen.laravel.com/docs/5.1/queues#running-the-queue-listener
  52. ## API
  53. After you create a tracking database, you can visit the database's settings page to get a read or write token. These tokens are used with the API to update or retrieve data.
  54. ### Writing
  55. To write to a database, make a POST request in JSON format with the following keys:
  56. `POST /api/input`
  57. * locations - a list of GeoJSON objects
  58. * token - the write token for the database (as a query string parameter or in the post body)
  59. The GeoJSON objects must have at least one property, "timestamp", which is can be any value that can be interpreted as a date. The object can have any additional properties you wish.
  60. The open source iOS [Overland](https://github.com/aaronpk/Overland-iOS) will send data in this format by default.
  61. ```
  62. POST /api/input?token=XXXXXXX HTTP/1.1
  63. Content-type: application/json
  64. {
  65. "locations": [
  66. {
  67. "type": "Feature",
  68. "geometry": {
  69. "type": "Point",
  70. "coordinates": [-122.621, 45.535]
  71. },
  72. "properties": {
  73. "timestamp": "2017-01-01T10:00:00-0700",
  74. "horizontal_accuracy": 65
  75. }
  76. }
  77. ]
  78. }
  79. ```
  80. ### Reading
  81. To read a database, make a GET request as follows:
  82. #### Get all data for a calendar day
  83. `GET /api/query`
  84. * token - (required) the read token for the database
  85. * tz - (optional, default UTC) timezone string (e.g. America/Los_Angeles) which will be used to determine the absolute start/end times for the day
  86. * format - (optional, default "full") either "full" or "linestring"
  87. * full - return one JSON record for each result in the database
  88. * linestring - combine all the returned results into a GeoJSON linestring
  89. * date - specify a date to return all data on that day (YYYY-mm-dd format)
  90. #### Get the last location before a given timestamp
  91. `GET /api/last`
  92. * token - (required) the read token for the database
  93. * tz - (optional, default UTC) timezone string (e.g. America/Los_Angeles) which will be used to determine the absolute start/end times for the day
  94. * before - (optional, default to now) specify a full timestamp to return a single record before this date (the point returned will be no more than 24 hours before the given date)
  95. * geocode - (optional) if "true", then the location found will be reverse geocoded using [Atlas](https://atlas.p3k.io) to find the city and timezone at the location
  96. #### Find the last location matching a clock time
  97. `GET /api/find-from-localtime`
  98. This API method can help you answer the question "Where was I when my watch read 9:30am on July 15th?".
  99. Timestamps in Exif data do not include the timezone offset, and there is no standard mechanism for including the timezone offset in Exif. Some Canon cameras put the offset in a field, but not all of them do. You can use this method to find your location given an Exif date.
  100. * token - (required) the read token for the database
  101. * input - specify a clock time in the format `YYYY-mm-dd HH:MM:SS`
  102. This will query the database and find the closest matching location for when your clock read that time.
  103. ## Credits
  104. Compass icon by Ryan Spiering from the Noun Project.
  105. Screenshot of the map view by Sebastiaan Andeweg.
  106. ## License
  107. Copyright 2015 by Aaron Parecki
  108. Compass is licensed under the [Apache 2.0 license](http://opensource.org/licenses/Apache-2.0)
  109. Compass is built using the Lumen framework, which is licensed under the [MIT license](http://opensource.org/licenses/MIT)