Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

124 Commits

Repository files navigation

Tracker

A tracking system for vehicles, which works by creating a log for a given date for each device. It can accept data from:

  • The Expo app app/
  • Devices compatible with Traccar, using the Traccar forwarding endpoint defined in XML on the Traccar server (powered by 1NCE SIM cards)
  • Devices compatible with flespi, using a flespi HTTP stream

These devices are generally powered by 1NCE SIM cards.

It uses a D1 database to store events, and a simple React Router 7 website to view them. The frontend website is in two logical halves:

  • A daily tracking section, which essentially acts as a logbook
  • An event tracking section, for trackers used at events (such as running races, cycling events, etc.). This is more intended for people to view the location of a device in real time, and see where it has been.

The logic for each is quite different, however as they share so many components they run on the same codebase. The website is in the website/ folder.

All times shown in the UI are rendered in Europe/London (see DISPLAY_TIME_ZONE in website/app/utils/dateTime.ts). Days are always UTC: events.date_string buckets by UTC day and /:password/:date means that UTC day, so a summer log for a given date runs 01:00 to 00:59 local.

Logbook

/:password/:date/logbook condenses a day's position reports into the lines a ship's logbook carries — first and last report, arrivals and departures, timing points passed, and engine/charge changes — rather than one line per fix. Previous/next skip to the nearest day that actually has data.

Stops and voltage bands are configured per device under Admin → Devices → Logbook. Leaving the config blank uses the defaults (stopped = 15 minutes within 100 m, no voltage lines). Voltage sources are addressed by JSON path into events.data because only the tracker's internal battery has a fixed field — engine/input voltage arrives as an unmapped flespi key under data.other. That admin page lists the numeric paths the device has actually reported so they can be copied rather than guessed.

Anyone with the viewing password can name a stop, which creates a timing point at that position. Editing or deleting it afterwards needs admin access.

Daily email

If a device has email recipients set on that same admin page, the daily-logbook-email Workflow runs at 00:05 UTC, renders the previous UTC day's logbook to a PDF with Browser Rendering, and emails it to each recipient. Devices with no recipients, or with no events that day, are skipped.

The schedule lives on the Workflow binding in wrangler.jsonc (schedules), not as a worker cron trigger.

Rendered PDFs for finished days are kept in the R2_BUCKET R2 bucket, so a day is only ever rendered once — whichever of the nightly email or the page's Download PDF link comes first warms the cache for the other. Today's log is never cached, because it is still growing; the download link only appears once the UTC day has ended. Deleting an object from the bucket simply causes it to be re-rendered on next request, so the bucket is safe to prune.

Setup that cannot be done from the repository:

  • Onboard the sender domain (EMAIL_FROM in wrangler.jsonc) in Cloudflare Email Sending. The zone must use Cloudflare DNS.
  • Make sure the Cloudflare Access policy is scoped to /admin and not the whole zone, or Browser Rendering cannot fetch /print/logbook/....

For local development, put the secret in website/.dev.vars (gitignored):

PDF_SIGNING_SECRET=local-development-secret

The BROWSER and EMAIL bindings are deliberately not marked "remote": true, because that would make every npm run dev require Cloudflare credentials. Neither has a working local simulator, so to exercise the workflow end to end run npx wrangler dev --remote.

Tracking Devices

Expo App

The Expo app is a simple app in the app/ folder which uploads location data to the server. It is designed to be run on a device with a GPS chip, such as a phone or tablet.

SinoTrack Devices

ST-915L

RCONF command

ST915/4G,ID:[ID Redacted],PW:0000,U1:,U2:,U3:,MODE:GPRS-MOVE,DAILY:OFF,GEO FENCE:OFF,OVER SPEED:OFF,VOICE:OFF,SHAKE ALARM:OFF,SLEEP:ON,APN:iot.1nce.net,,,IP:FLESPI URL]:[FLESPI IP],GPRS UPLOAD TIME:30s,TIME ZONE:0.0

ST-901 Device

ST-901L

RCONF command

ST-901/4G,ID:[ID Redacted],PW:0000,U1:,U2:,U3:,MODE:GPRS,POWER ALARM:OFF,ACCSMS:OFF,ACCCALL:OFF,GEO FENCE:OFF,OVER SPEED:OFF,VOICE:OFF,SHAKE ALARM:OFF,SLEEP:OFF,APN:iot.1nce.net,,,IP:[FLESPI URL]:[FLESPI IP],GPRS UPLOAD TIME 1:20,GPRS UPLOAD TIME 2:20,TIME ZONE:0.0

ST909 Device

The device uses H02 protocol (port 5013) You can SMS the device using https://portal.1nce.com/portal/customer/dashboard

To set a new address send a message saying IP,10.10.10.10,5013 (replacing 10.10.10.10 with the IP of the traccar/flespi server)

Default address is IP,27.aika168.com,8185

Device manualDevice manualDevice manual

From a similar device online:

Device CommandsDevice Commands

Forwarders

Traccar

You can use traccar as the intermediary for tracking devices with different protocols.

Setup Traccar forwarding

Stored in /opt/traccar/conf/traccar.xml on the traccar server.

true url https://[URL GOES HERE]/upload-traccar.json?name={name}&status={status}&deviceId={deviceId}&protocol={protocol}&deviceTime={deviceTime}&fixTime={fixTime}&valid={valid}&latitude={latitude}&longitude={longitude}&altitude={altitude}&speed={speed}&course={course}&accuracy={accuracy}&statusCode={statusCode} true 10000 1000 1000 https://[URL GOES HERE]/upload-traccar.json json

flespi

For flespi HTTP streams, send POST requests to:

https://[URL GOES HERE]/upload-flespi.json

The endpoint accepts flespi message payloads as a single JSON object, an array of message objects, or wrapped in result, messages, or data.

It reads location and timestamp fields from either dot-notation keys (position.latitude) or nested objects (position.latitude) and stores them in the same events table used by other upload endpoints.

About

Tracking for distance based events using an Expo App and Cloudflare Workers

Resources

Code of conduct

Security policy

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages