If you’re working with GPS data, testing your software with real-world data can be challenging. Thankfully, tools like gpsfake
and gpsd
make it possible to simulate GPS data. gpsfake
allows you to replay NMEA data streams, while gpsd
acts as the GPS daemon to manage and process the GPS data. This guide walks you through the steps to feed NMEA data to gpsfake
and use it effectively with gpsd
.
Prerequisites
Before proceeding, ensure the following tools are installed on your system:
- gpsd: The GPS daemon that handles GPS data.
- gpsfake: A tool to simulate GPS data for testing purposes.
- NMEA Data File: You’ll need a file containing GPS data in NMEA format. If you don’t have one, you can find sample files online or record your own using GPS hardware and
gpspipe
.
You can install these tools on Linux with:
sudo apt update
sudo apt install gpsd gpsd-clients python3-gps
Step 1: Prepare Your NMEA Data
Ensure your NMEA file is formatted correctly. It should look something like this:
$GPGGA,123519,4807.038,N,01131.000,E,1,08,0.9,545.4,M,46.9,M,,*47
$GPRMC,123519,A,4807.038,N,01131.000,E,022.4,084.4,230394,003.1,W*6A
You can name the file something like testdata.nmea
.
Step 2: Start the gpsd
Daemon
First, ensure that gpsd
is not already running:
sudo systemctl stop gpsd.socket
gpsd.service
Now, start gpsd
manually to avoid conflicts:
sudo gpsd -N -D5 /dev/null
- The
-N
flag keepsgpsd
running in the foreground. - The
-D5
flag sets the debug level to 5 for detailed logs. /dev/null
is a placeholder since we’ll be feeding data fromgpsfake
.
Step 3: Feed NMEA Data to gpsfake
Run gpsfake
with your NMEA file:
gpsfake -D 5 -c testdata.nmea
-D 5
: Sets the debug level.-c
: Feeds the data togpsd
in real-time.
gpsfake
will replay the NMEA sentences, simulating a live GPS device.
Step 4: Verify the Data with gpsd
To ensure that gpsd
is receiving the simulated data, use tools like cgps
or gpsmon
:
- Run
cgps
to view the data:
cgps
- You should see the coordinates, satellite information, and other data.
- Alternatively, use
gpsmon
for detailed NMEA sentence analysis:
gpsmon
Both tools should display the data as if it were coming from a real GPS device.
Troubleshooting
- Ensure Correct File Permissions: Make sure your NMEA file is readable:
chmod +r testdata.nmea
- Check for Conflicting Services: Ensure no other instances of
gpsd
are running.
ps aux | grep gpsd
sudo kill <PID>
- Verify NMEA Data Integrity: Ensure your NMEA file contains valid sentences. Use tools like
gpsbabel
to validate:
gpsbabel -i nmea -f testdata.nmea -o nmea -F /dev/null
By combining gpsfake
and gpsd
, you can simulate GPS data streams for testing and debugging GPS-enabled applications. This setup is particularly useful for software development and testing in environments where real GPS hardware isn’t available or practical.
Now that you have your simulated environment ready, you can focus on building and testing your GPS-based applications with ease.