Skip to content

Tracking System

The tracking system predicts beacon locations based on RSSI data from adv4 messages. It is implemented in server/src/tracking.ts with algorithm implementations in server/src/algs/.

Overview

When tracking is active, the system:

  1. Receives adv4 RSSI data from MQTT (beacon signal strength at each gateway)
  2. Maintains in-memory caches of zones, gateways, and maps
  3. Runs a prediction algorithm to determine which zone a beacon is in
  4. Publishes updates to WebSocket subscribers
  5. Logs tracking intervals to protobuf files

Algorithms

Three tracking algorithms are available:

Zone Voting (tracking_alg_zone_voting)

The simplest algorithm. Each gateway "votes" for the zone it belongs to, weighted by the beacon's signal strength at that gateway. The zone with the most votes wins.

Trilateration (tracking_alg_trilateration)

Uses RSSI values from multiple gateways to estimate the beacon's 2D position via trilateration, then maps the position to the nearest zone.

Brutus (tracking_alg_brutus)

An enhanced algorithm that combines signal strength analysis with zone graph connectivity. Uses smoothing and history to reduce zone prediction jitter.

Control API

EndpointMethodDescription
/tracking/start/:algPOSTStart tracking with a named algorithm
/tracking/stopPOSTStop tracking
/tracking/statusGETCurrent tracking state and algorithm
/tracking/algorithmsGETList available algorithms
/tracking/:idGETGet tracking data for a beacon

WebSocket Updates

The tracking system pushes updates to three types of WebSocket subscribers:

  • track-{mac}: Position update for a specific beacon
  • track-debug-{mac}: Debug data including RSSI values, gateway distances, and algorithm internals
  • overview-{map_id}: All beacon positions on a specific map

Tracking Logs

Tracking intervals (beacon enters/exits a zone) are logged to protobuf files under the logs/ directory. These can be queried via the /beacon/:id/intervals endpoint.

In-Memory Caches

The tracking module maintains caches loaded from the database:

CacheContentsPurpose
ZonesAll zones with coordinatesZone lookup for predictions
GatewaysGateways with map/zone assignmentsMap RSSI to gateways
MapsMap metadataZone-to-map mapping
RSSIRecent RSSI readings per beaconAlgorithm input data

The cache is loaded at startup via tracking_load_cache() and refreshed when maps, zones, or gateways are modified.