Skip to main content
GNSS HAT Library Documentation
Shop GitHub Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Back to homepage

Geofencing

Configure up to 4 circular geofences. The receiver reports per-fence and combined Inside/Outside/Unknown state in every navigation update.

Note
HAT Compatibility — Geofencing is available on the L1 GNSS HAT and L1/L5 RTK HAT. It is not supported on the TIME HAT.

Configuration Fields

FieldC++ TypeDescription
geofencesvector<Geofence>1–4 geofence zones
confidenceLeveluint8_tConfidence level 0–5 (sigma). Higher = more certain before reporting Inside/Outside
pioPinPolarityoptional<EPioPinPolarity>Optional PIO pin output polarity. Omit to disable hardware output

Geofence

FieldTypeDescription
latfloatCenter latitude in degrees
lonfloatCenter longitude in degrees
radiusfloatRadius in meters

PIO Pin Polarity

ValueC++CPythonDescription
Low = InsideLowMeansInsideJP_GNSS_PIO_PIN_POLARITY_LOW_MEANS_INSIDELOW_MEANS_INSIDEPin goes LOW when inside any geofence
Low = OutsideLowMeansOutsideJP_GNSS_PIO_PIN_POLARITY_LOW_MEANS_OUTSIDELOW_MEANS_OUTSIDEPin goes LOW when outside all geofences

The PIO pin (pin 6 on the u-blox module) drives an LED and relay on the HAT for hardware geofence signaling.

Examples

config.geofencing = GnssConfig::Geofencing {
    .geofences = {
        Geofence { .lat = 52.2297f, .lon = 21.0122f, .radius = 100.0f },
        Geofence { .lat = 52.2400f, .lon = 21.0200f, .radius = 50.0f }
    },
    .confidenceLevel = 3,
    .pioPinPolarity = EPioPinPolarity::LowMeansInside
};
jp_gnss_geofence_t fence1 = { .lat = 52.2297f, .lon = 21.0122f, .radius = 100.0f };
jp_gnss_geofence_t fence2 = { .lat = 52.2400f, .lon = 21.0200f, .radius = 50.0f };
jp_gnss_gnss_config_add_geofence(&config, fence1);
jp_gnss_gnss_config_add_geofence(&config, fence2);
config.geofencing_cfg.confidence_level = 3;
config.geofencing_cfg.pio_enabled = true;
config.geofencing_cfg.pin_polarity = JP_GNSS_PIO_PIN_POLARITY_LOW_MEANS_INSIDE;
config['geofencing'] = {
    'confidence_level': 3,
    'pin_polarity': gnsshat.PioPinPolarity.LOW_MEANS_INSIDE,
    'geofences': [
        { 'lat': 52.2297, 'lon': 21.0122, 'radius': 100.0 },
        { 'lat': 52.2400, 'lon': 21.0200, 'radius': 50.0 }
    ]
}

Runtime Status

Geofencing status is reported in every Navigation update via navigation.geofencing:

FieldDescription
geofencingStatusActive or NotAvailable
combinedStateCombined state across all fences: Inside, Outside, or Unknown
geofencesStatus[i]Per-fence state (up to 4)

See Geofencing Feature for runtime usage details.