Skip to main content

gps

GPS/GNSS receiver for position, altitude, speed, and satellite tracking via NMEA.

Overview

The gps node reads position data from any NMEA-compatible GPS/GNSS receiver via a serial connection. It parses standard NMEA sentences (GGA, RMC, GSA, GSV) to provide latitude, longitude, altitude, speed, course, satellite count, fix quality, and dilution of precision. Works with any generic GPS module that outputs NMEA data over UART.

NMEA
Protocol
UART
Interface
10Hz
Max Update Rate
2.5m
Typical Accuracy

Properties

Property Type Default Description
port string * /dev/ttyS0 Serial port for GPS module (required)
baudRate select 9600 Serial baud rate. Options: 4800, 9600, 19200, 38400, 57600, 115200
updateRate select 1 Position update rate in Hz. Options: 1, 5, 10

Output

{
  "latitude": 51.5074,
  "longitude": -0.1278,
  "altitude": 11.2,
  "speed": 0.52,
  "course": 215.3,
  "satellites": 9,
  "fix": "3D",
  "hdop": 1.2,
  "timestamp": 1640000000000
}

Wiring (UART)

Connection

VCC → 3.3V or 5V (check module)

GND → GND

TX → GPIO 15 (RXD, Pin 10)

RX → GPIO 14 (TXD, Pin 8)

Disable Bluetooth to free UART: add dtoverlay=disable-bt to /boot/config.txt

ASCII Wiring Diagram

  GPS Module         Raspberry Pi
  ----------         ------------
  VCC  ──────────── 3.3V (Pin 1)
  GND  ──────────── GND  (Pin 6)
  TX   ──────────── RXD  (Pin 10 / GPIO 15)
  RX   ──────────── TXD  (Pin 8  / GPIO 14)

  Note: TX on GPS connects to RX on Pi
        (and vice versa - crossed)

Example: Geofence Alert System

Monitor GPS position and trigger alerts when a device enters or leaves a defined geofence area.

gps function notification
// Function node: Geofence check
var lat = msg.latitude;
var lon = msg.longitude;

// Define geofence center and radius (meters)
var fenceLat = 51.5074;
var fenceLon = -0.1278;
var fenceRadius = 500; // meters

// Haversine distance calculation
var R = 6371000; // Earth radius in meters
var dLat = (lat - fenceLat) * Math.PI / 180;
var dLon = (lon - fenceLon) * Math.PI / 180;
var a = Math.sin(dLat/2) * Math.sin(dLat/2) +
        Math.cos(fenceLat * Math.PI / 180) *
        Math.cos(lat * Math.PI / 180) *
        Math.sin(dLon/2) * Math.sin(dLon/2);
var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
var distance = R * c;

var inside = distance <= fenceRadius;
var prevInside = flow.get('insideFence');

msg.payload = {
    latitude: lat,
    longitude: lon,
    distance: distance.toFixed(1),
    insideFence: inside,
    event: (inside !== prevInside) ?
        (inside ? "entered" : "exited") : "none"
};

flow.set('insideFence', inside);
return msg;

Example: Vehicle Trip Logger

Log GPS data points during a vehicle trip including distance traveled and average speed.

// Function node: Trip data logger
var lat = msg.latitude;
var lon = msg.longitude;
var speed = msg.speed; // km/h
var trip = flow.get('trip') || {
    start: null, distance: 0, maxSpeed: 0,
    points: 0, lastLat: null, lastLon: null
};

if (!trip.start) {
    trip.start = msg.timestamp;
}

// Calculate distance from last point
if (trip.lastLat !== null) {
    var R = 6371000;
    var dLat = (lat - trip.lastLat) * Math.PI / 180;
    var dLon = (lon - trip.lastLon) * Math.PI / 180;
    var a = Math.sin(dLat/2) * Math.sin(dLat/2) +
            Math.cos(trip.lastLat * Math.PI/180) *
            Math.cos(lat * Math.PI/180) *
            Math.sin(dLon/2) * Math.sin(dLon/2);
    var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
    trip.distance += R * c;
}

trip.lastLat = lat;
trip.lastLon = lon;
trip.points++;
if (speed > trip.maxSpeed) trip.maxSpeed = speed;

flow.set('trip', trip);

var elapsed = (msg.timestamp - trip.start) / 1000;

msg.payload = {
    position: { lat: lat, lon: lon },
    speed: speed,
    distance_km: (trip.distance / 1000).toFixed(2),
    elapsed_min: (elapsed / 60).toFixed(1),
    maxSpeed: trip.maxSpeed.toFixed(1),
    satellites: msg.satellites,
    fix: msg.fix
};

return msg;

Common Use Cases

Asset Tracking

Track vehicles, containers, or equipment location in real-time

Geofencing

Alert when tracked devices enter or leave defined geographic zones

Weather Stations

Geo-tag weather sensor data for distributed monitoring networks

Fleet Management

Monitor vehicle fleets with speed, route, and trip logging

Related Nodes