Skip to main content
Version: v3.9.2

GPS

The GPS manager resolves agent geographic coordinates for Controller reporting. It supports auto, dynamic, manual, and off, and starts initialization asynchronously.

Code: internal/gps/

Purpose​

  • Read coordinates from a serial GPS device, from IP geolocation, or from manual config
  • Expose gpsStatus on edgelet system info and on the Controller status post
  • Post latitude and longitude to the Controller when the stored coordinates change

Dependencies​

Depends onReason
configGPS mode, manual coordinates, device path, scan frequency
fieldagentPosts latitude and longitude when the GPS callback runs
Used byReason
supervisorStarted before EdgeletAPI. Wires the GPS config callback
edgeletapiGET/POST /v1/system/gps, gpsStatus on GET /v1/system/info
fieldagentgpsStatus on the Controller status post

Modes​

ModeBehavior
offNo coordinate collection
manualStatic gpsCoordinates from config. POST /v1/system/gps switches to this mode
dynamicSerial NMEA device (gpsDevice). IP geolocation runs only when that device cannot be read
autoIP geolocation only

gpsScanFrequency is the scan interval in seconds. 0 disables the scheduler, so neither the device nor IP geolocation is polled.

Implementation split: device.go, nmea/, web.go.

Dynamic scan​

dynamic with a configured gpsDevice opens that serial device read-only. Edgelet does not set baud, data bits, or parity. The port must already be configured by the OS. Serial polling is unix. Windows returns a device error for this path.

Each scan reads the lines already buffered on the port, up to 128, and stops when the port is idle. The latest RMC or GGA sentence in that burst wins. Other NMEA sentences are ignored. A valid fix is stored as lat,lon with five decimal places.

The Controller GPS post (config/gps) runs only when that five-decimal string changes. A repeated fix at the same rounded position does not post again. The status post still carries gpsStatus on its normal interval.

Lifecycle​

Start​

  1. Reset context (supervisor restart safe)
  2. startCoordinateUpdateScheduler()
  3. Async initializeGps() in a goroutine. A panic or init error falls back to off

If dynamic is selected and the device cannot be opened, startup falls through to the IP handler. The configured mode string stays dynamic, and later scans keep using the IP fallback while the device handler is not running.

Stop​

Cancel the scheduler and the main context, then close the device or web handler.

Configuration​

GPS settings live in config profiles and in Controller-pushed fog config. Keys: gpsMode, gpsDevice, gpsScanFrequency, gpsCoordinates. See Configuration.

The supervisor registers SetGPSConfigCallback. That callback posts coordinates. It does not run on every config reload. A reload calls InstanceConfigUpdated, which restarts the scheduler and re-initializes the active mode.

Module status​

PropertyValue
StatusReporter index6 (utils.GPSManager)

gps.Status stores only the health value. Coordinates stay on gpsCoordinates. edgelet system info and the Controller status field gpsStatus both read this health value.

gpsStatusMeaning
HEALTHYLatest RMC or GGA is a valid fix, or auto / manual is in use. A dynamic port that just opened stays HEALTHY until the first scan
NO_FIXThe serial port is producing data and the latest position sentence has no fix. Previous device coordinates stay. No IP lookup
DEVICE_ERRORThe port produced no data, or it could not be read. That scan does one IP lookup. A successful lookup leaves this status in place
IP_ERRORThe IP lookup failed
OFFMode is off, or initialization failed

A change into NO_FIX logs GPS no fix; keeping last coordinates. A later valid fix logs GPS fix acquired.

External APIs​

RouteRole
GET /v1/system/infoIncludes gpsStatus with the GPS config fields
GET /v1/system/gpsCurrent lat and lon
POST /v1/system/gpsBody lat and lon. Sets mode to manual and persists gpsCoordinates

Controller sync is PATCH config/gps with latitude and longitude, and gpsStatus on the status post.

Observability​

  • Log module: "GPS Manager" for mode and status changes
  • Log module: "GPS Device Handler" for the serial read
  • Log module: "GPS Web Handler" for IP geolocation

Failure modes​

SymptomTypical cause
gpsStatus NO_FIXReceiver has no satellite fix yet. Coordinates are unchanged
gpsStatus DEVICE_ERRORDevice missing, port silent, or open failed. Coordinates may come from IP geolocation
gpsStatus IP_ERRORIP lookup failed. Previous coordinates stay
OFF after startInit error
Coordinates never movegpsScanFrequency is 0, mode is off or manual, or scans stay on NO_FIX

Code map​

FileRole
manager.goMode scheduling, init, status, Controller post gate
device.goSerial scan and coordinate update
device_poll_unix.goBounded line read
web.goIP geolocation
nmea/RMC and GGA parsing
status.gogpsStatus values

Related: Field agent, Edgelet API module, Status reporter.

Group 3See anything wrong with the document? Help us improve it!