HowTo Use an Android Phone as a GPSd Source

From MediaWiki
Revision as of 04:18, 15 October 2019 by Paul Blankenbaker (talk | contribs) (Removed -N option from /etc/sysconfig/gpsd example config file)
Jump to navigationJump to search

This HowTo details how to use an Android phone as a GPS source for a NST system. Much of the information presented here is based on the Tutorial - gpsd article found at the Linux Magazine web site.

Android Phone Setup

You will need to run an application on your Android phone that transmits UDP packets of containing information from the GPS in the phone to your NST system. To do this:

  1. Install GPSd Client by tiagoshibata from Google Play Store.
  2. Run the application and set the IPv4 address of the destination to the IPv4 of your NST system and the port number to 9999.
GPSd Client
GPSd Client

Verify GPS Data Feed

Once you have GPSd Client configured and running, you should see GPS information arriving on port 9999 on your NST system.

You can use the netcat utility to verify that the information is arriving at your NST system as well as the IPv4 address of your Android phone.

[test@nst ~]$ nc -vlu 9999 2>&1 | head
Ncat: Version 7.80SVN ( https://nmap.org/ncat )
Ncat: Listening on :::9999
Ncat: Listening on 0.0.0.0:9999
Ncat: Connection from 192.168.1.229.
$GPGSV,3,1,12,01,60,094,20,07,45,177,21,11,62,057,17,13,13,291,14*7B

$GPGSV,3,2,12,17,33,254,18,18,45,059,16,28,49,319,16,30,66,234,20*7B

$GPGSV,3,3,12,03,03,135,,08,21,053,,19,14,244,,22,10,115,*7B 

[test@nst ~]$ 

The above output shows that we are receiving GPS information from 192.168.1.229 on port 9999.

Configure gpsd.socket

Edit the /etc/sysconfig/gpsd config file and make sure that the OPTIONS parameter has a UDP source that accepts packets on port 9999.

# Options for gpsd, including serial devices
OPTIONS="udp://*:9999"
# Set to 'true' to add USB devices automatically via udev
USBAUTO="false"

The above configuration accepts UDP packets containing GPS information port 9999 from any machine on the network. If you know the IPv4 address of your Android phone, you can limit what packets are accepted to just those arriving from your phone by specifying the IPv4 address of your phone in the configuration file. For example, if you phone has an IPv4 address of 192.168.1.229, you can use the following configuration.

# Options for gpsd, including serial devices
OPTIONS="udp://192.168.1.229:9999"
# Set to 'true' to add USB devices automatically via udev
USBAUTO="false"

Verify gpsd.socket Running

By default, the gpsd.socket unit should be enabled. You can verify this by running the systemctl command shown below.

[test@nst ~]$ systemctl status gpsd.socket
● gpsd.socket - GPS (Global Positioning System) Daemon Sockets
   Loaded: loaded (/usr/lib/systemd/system/gpsd.socket; enabled; vendor preset: enabled)
   Active: active (listening) since Sat 2019-10-12 07:47:06 EDT; 1 day 22h ago
   Listen: /var/run/gpsd.sock (Stream)
           [::1]:2947 (Stream)
           127.0.0.1:2947 (Stream)
    Tasks: 0 (limit: 4915)
   Memory: 56.0K
   CGroup: /system.slice/gpsd.socket

Oct 12 07:47:06 refritos systemd[1]: Listening on GPS (Global Positioning System) Daemon Sockets.
[test@nst ~]$ 

NOTE: You do not need to enable or start gpsd.service. The gpsd.socket will take care of starting the necessary processes when clients connect to port 2947 on your NST system.

Verify Data

Using nc

You can use the netcat utility (nc) to check that you can connect to local gpsd server running on your NST system.

 [nst@test ~]$ nc -v 127.0.0.1 2947
 Ncat: Version 7.80SVN ( https://nmap.org/ncat )
 Ncat: Connected to 127.0.0.1:2947.
 {"class":"VERSION","release":"3.18.1","rev":"3.18.1","proto_major":3,"proto_minor":13}

Using Console Clients

gpspipe

The gpspipe console client from the gps-clients package is useful to see the raw data from a GPS source.

[nst@test ~]$ gpspipe -r | head -10
{"class":"VERSION","release":"3.18.1","rev":"3.18.1","proto_major":3,"proto_minor":13}
{"class":"DEVICES","devices":[{"class":"DEVICE","path":"udp://*:9999","driver":"NMEA0183","activated":"2019-10-14T11:09:22.601Z","flags":1}]}
{"class":"WATCH","enable":true,"json":false,"nmea":true,"raw":0,"scaled":false,"timing":false,"split24":false,"pps":false}
$GPGSV,3,1,09,03,26,052,20,06,68,265,16,12,12,317,14,17,59,037,24*76
$GPGSV,3,2,09,28,46,147,16,02,27,243,,19,62,354,,22,09,040,*7D
$GPGSV,3,3,09,24,15,288,*40
$GLGSV,3,1,10,78,28,319,18,86,24,049,18,76,21,187,13,87,52,334,24*69
$GLGSV,3,2,10,71,23,059,18,70,00,016,,77,54,250,,65,05,153,*60
$GLGSV,3,3,10,88,26,279,,72,23,113,*6B
$GPGGA,110959.0,3546.755123,N,07849.986918,W,2,05,1.2,130.7,M,-49.0,M,,*6D
[nst@test ~]$ 

cgps

The cgps console client from the gpsd-clients package can be used to show time and Console gpsd clients

[nst@test ~]$ cgps
┌───────────────────────────────────────────┐┌──────────────────Seen 20/Used  8┐
│ Time:          2019-10-14T10:58:20.000Z   ││    PRN  Elev   Azim   SNR  Use  │
│ Latitude:         36.17923583 N           ││GP    2    23    240    16    Y  │
│ Longitude:        79.23310118 W           ││GP    6    65    253    16    Y  │
│ Altitude:        433.727 ft               ││GP   17    61     26    22    Y  │
│ Speed:             0.00 mph               ││GP   28    51    144    18    Y  │
│ Heading:         223.5 deg (true)         ││GL   72    18    118    19    Y  │
│ Climb:            39.37 ft/min            ││GL   77    56    261    14    Y  │
│ Status:         3D DIFF FIX (6 secs)      ││GL   78    24    323    22    Y  │
│ Long Err  (XDOP, EPX):  0.62, +/- 10.0 ft ││GL   86    28     43    15    Y  │
│ Lat Err   (YDOP, EPY):  0.74, +/- 10.9 ft ││GP    1     0     49     0    N  │
│ Alt Err   (VDOP, EPV):  0.90, +/- 17.0 ft ││GP    3    29     57    14    N  │
│ 2D Err    (HDOP, CEP):  1.00, +/- 14.8 ft ││GP   12     7    317     0    N  │
│ 3D Err    (PDOP, SEP):  1.30, +/- 22.5 ft ││GP   19    60    341     0    N  │
│ Time Err  (TDOP):       1.02              ││GP   22    13     42     0    N  │
│ Geo Err   (GDOP):       2.08              ││GP   24    15    293     0    N  │
│ Speed Err (EPS):              +/- 14.8 mph││     65     0    156     0    N  │
│ Head Err  (EPD):        n/a               ││GL   70     3     21     0    N  │
│ Time offset:           -35.457 sec        ││GL   71    22     66     0    N  │
│ Grid Square:            FM05os            ││GL   76    28    188    19    N  │
└───────────────────────────────────────────┘└More...──────────────────────────┘
{"class":"TPV","device":"udp://*:9999","status":2,"mode":3,"time":"2019-10-14T10
:58:20.000Z","ept":0.005,"lat":35.779235833,"lon":-78.833101183,"alt":132.200,"e
px":3.055,"epy":3.314,"epv":5.175,"track":223.5000,"magtrack":223.5000,"speed":0
.000,"climb":0.200,"eps":6.63,"epc":10.35}

gpsmon

The gpsmon console client from the gpsd package can also be used to get information about the GPS source.

[nst@test ~]$ gpsmon
tcp://localhost:2947          NMEA0183>
┌──────────────────────────────────────────────────────────────────────────────┐
│Time: 2019-10-14T11:06:05.000Z Lat:  35 46' 45.02561" Non:  78 49' 59.01454" W│
└───────────────────────────────── Cooked TPV ─────────────────────────────────┘
┌──────────────────────────────────────────────────────────────────────────────┐
│ GPGSV GLGSV GPGGA GNGNS GPVTG GPRMC GPGSA GNGSA                              │
└───────────────────────────────── Sentences ──────────────────────────────────┘
┌──────────────────┐┌────────────────────────────┐┌────────────────────────────┐
│Ch PRN  Az El S/N ││Time:      110605.0         ││Time:      110605.0         │
│ 0   3  53 27  15 ││Latitude:   3546.754270 N   ││Latitude:  3546.754270      │
│ 1   6 261 67  15 ││Longitude: 07849.985758 W   ││Longitude: 07849.985758     │
│ 2  12 317 10  13 ││Speed:     0.0              ││Altitude:  130.1            │
│ 3  17  35 60  15 ││Course:    223.5            ││Quality:   2   Sats: 05     │
│ 4  19 350 61  12 ││Status:    A       FAA: D   ││HDOP:      2.2              │
│ 5  24 289 15  15 ││MagVar:    0.0  E           ││Geoid:     -49.0            │
│ 6  28 147 47  12 │└─────────── RMC ────────────┘└─────────── GGA ────────────┘
│ 7   2 243 26   0 │┌────────────────────────────┐┌────────────────────────────┐
│ 8  22  40 10   0 ││Mode: A2 Sats:              ││UTC:           RMS:         │
│ 9  70  18  1   0 ││DOP: H=2.3   V=0.9   P=2.5  ││MAJ:           MIN:         │
│10  77 253 54   0 ││TOFF: -35.113007340         ││ORI:           LAT:         │
│11  65 154  3   0 ││PPS:                        ││LON:           ALT:         │
└────── GSV ───────┘└──────── GSA + PPS ─────────┘└─────────── GST ────────────┘
(49) $GPGSA,A,2,03,06,17,19,24,,,,,,,,2.5,2.3,0.9*31
(70) $GPGSV,3,1,09,03,27,053,15,06,67,261,15,12,10,317,13,17,60,035,15*77

GUI gpsd clients

There are several GUI Clients as well.

  • xgps - Similar to cgps but has a graphical view of satellite locations.
  • xgpsspeed - A graphical speedometer with satellite overlay.
  • gpsdrive - A mapping application.

Kismet Configuration

To enable kismet-ng to make use of the location and time information provided by gpsd, edit the /etc/kismet/kismet.conf file and make sure that the gps parameter is set as shown below.

# New GPS configuration
# gps=type:options
#
gps=gpsd:host=localhost,port=2947

Running gpsd By Hand

If you need to run gpsd by hand, you will need to disable the gpsd.socket unit first. If you don't do this, systemd will hold port 2947 open and prevent your instance of gpsd from being able to bind to it.

systemctl stop gpsd.socket

After disabling the gpsd.socket unit, you can run gpsd in the foreground with debug output enabled as follows.

gpsd -D9 -N "udp://*:9999"

Or, if you want to limit the GPS source to a specific IPv4 address, substitute the IPv4 address from the *.

gpsd -D9 -N udp://192.168.1.229:9999