=== Boat Position ===
Contributors: pcio
Donate link: https://www.paypal.com/donate/?hosted_button_id=DFM2JV8JKTTM6
Tags: boat, gps, tracking, map, logbook
Requires at least: 6.2
Tested up to: 7.0
Stable tag: 1.1.0
Requires PHP: 8.1
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Automatic sailing logbook — track your boat's live position and full route history using your onboard GPS router.

== Description ==

Boat Position turns your WordPress site into a live tracking and logbook service for your boat.

The plugin is designed around the Teltonika RUTX50 router (*), a compact Linux-based 5G router with built-in GPS. 
A shell script on the router sends a position to your site every minute. The plugin stores each position, runs a state machine to group positions into trips and legs, and serves three public pages:

* **Live map** (`/boat-position/map`) — shows the current position on an OpenStreetMap/OpenSeaMap map with a rotating arrow icon when underway and an idle indicator when stopped. Visible voyage plans are drawn as dashed green routes with flag markers.
* **Logbook** (`/boat-position/history`) — calendar sidebar with trip history. Click any day to see the full route on the map. Logged-in editors can label harbour names and merge incorrectly split trips.
* **Voyage plans** (`/boat-position/plans`) — plan future voyages as ordered lists of waypoints with optional ETAs. Multiple plans are supported; each plan can be toggled visible/hidden on the map independently.

Over 150 Danish harbours are included as seed data so harbour names are detected automatically from GPS coordinates.

No third-party services or API keys are required beyond your own WordPress site. Maps are rendered using the free Leaflet.js library with OpenStreetMap and OpenSeaMap tiles.

(*) There are other alternatives to using the RTUTX50 router, any device that has access to a GPS and the internet can be configured as the source of position data.
    E.g. a linux machine like Rasberry PI connected to either its own GPS or the boat NMEA data.
 
== Installation ==

1. Upload the `boat-position` directory to `/wp-content/plugins/`.
2. Activate the plugin in **Plugins** in the WordPress admin.
3. Go to **Settings → Boat Position** to set a secret API key and find the router configuration instructions.
4. Follow the router setup guide in **Plugins → Boat Position → About** to configure your router's `sendgps.sh` script and cron job.
5. Send a test position from a command prompt to verify the endpoint is working before installing on the boat.

After activation, if `/boat-position/map` returns a 404, go to **Settings → Permalinks** and click **Save Changes** to flush the rewrite rules.

== Frequently Asked Questions ==

= How do I use this plugin? =

Install and activate the plugin, then go to **Settings → Boat Position**. Set a secret API key, then follow the router configuration guide in the About page to set up your router's cron job.

= Does it only work with the RUTX50 router? =

No. Any device that can send an HTTP POST request with `lat`, `lon`, `speed`, `course`, and `gps_time` fields to the REST endpoint will work. The About page documents the exact format.

= Where are the public pages? =

The plugin registers three pages automatically — no WordPress pages or shortcodes are needed:

* Live map: `https://yoursite.com/boat-position/map`
* Logbook: `https://yoursite.com/boat-position/history`
* Voyage plans: `https://yoursite.com/boat-position/plans`

= Can I avoid storing the secret key in the database? =

Yes. Define the key as a constant in `wp-config.php`:

  define( 'PCIO_BOAT_POSITION_API_KEY', 'your-secret-key-here' );

When this constant is present, the database option is ignored and the settings field is shown as read-only.

= The logbook is empty — no trips appear. =

Check that the router is sending data by looking at your database's `wp_boat_positions` table. If rows are present but no trips appear, the trip engine may not have processed them yet — visit the ingest endpoint directly or check the About page for the manual trigger curl command.

== Upgrade Notice ==
Currently there is no updates available. Will be announced on pcio.dk when new evolution of the application is ready.

= Does this cost anything? =

The plugin is free. If you like my work, you are welcome to support the further development:

[Donate link](https://www.paypal.com/donate/?hosted_button_id=DFM2JV8JKTTM6)

= How do I uninstall? =

Deactivate and delete the plugin from the WordPress admin. To also remove the data, open your database admin tool and drop these tables (replace `wp_` with your actual table prefix):

* `wp_boat_harbours`
* `wp_boat_legs`
* `wp_boat_positions`
* `wp_boat_trips`

== Screenshots ==

1. Live map — current boat position with directional arrow on OpenSeaMap.
2. Logbook — calendar sidebar, trip list, and route drawn on the map.
3. Voyage plans — plan list with visibility toggles, edit and delete controls.
4. Waypoint view — ordered waypoint table with ETA, drag-to-reorder, and inline editing.

== Changelog ==

= 1.1 =
* **Voyage plans** (`/boat-position/plans`) — new page for planning future voyages.
  * Create and manage multiple named plans, each with an optional description.
  * Add waypoints with names, coordinates and optional ETAs (expected arrival dates).
  * Drag-and-drop to reorder waypoints; inline editing of name and ETA per row.
  * Rebase tool: shift all ETAs from a chosen waypoint onwards by a number of days.
  * Delete individual waypoints or entire plans.
  * Editable plan title and notes directly from the waypoint view.
  * Eye icon toggle per plan: **visible** (blue) or **hidden** (grey).
    Logged-in users save their choice to the database; anonymous visitors store it in browser localStorage.
  * All visible plans are drawn on the live map as dashed green routes with flag markers.
  * Clicking empty water on the map allows editors to add a waypoint directly to the active plan.
  * Quick-pick datalist when adding waypoints: suggests all known harbours and existing plan waypoints.
* Harbour management on the live map: all known harbours are shown as markers. Logged-in editors can click any harbour to rename or delete it, and can click empty water to add a new harbour at that location.

= 1.0 =
* Initial release with tracking and history logbook.


