254 lines
6.7 KiB
Markdown
254 lines
6.7 KiB
Markdown
# GPS
|
|
|
|
Location fun. Tracking, logging, etc
|
|
|
|
## Inspiration / Further Reading
|
|
|
|
- [https://github.com/wadda/gps3](https://github.com/wadda/gps3)
|
|
- [https://learn.adafruit.com/adafruit-ultimate-gps-on-the-raspberry-pi?view=all](https://learn.adafruit.com/adafruit-ultimate-gps-on-the-raspberry-pi?view=all)
|
|
- [https://learn.adafruit.com/assets/3715](https://learn.adafruit.com/assets/3715)
|
|
- [https://learn.adafruit.com/adafruit-ultimate-gps?view=all](https://learn.adafruit.com/adafruit-ultimate-gps?view=all)
|
|
- [https://stackoverflow.com/questions/16989153/saving-gps-data-as-gpx](https://stackoverflow.com/questions/16989153/saving-gps-data-as-gpx)
|
|
- [http://www.catb.org/gpsd/gpspipe.html](http://www.catb.org/gpsd/gpspipe.html)
|
|
- [http://www.catb.org/gpsd/gpsd-time-service-howto.html#_feeding_chrony_from_gpsd](http://www.catb.org/gpsd/gpsd-time-service-howto.html#_feeding_chrony_from_gpsd)
|
|
- [http://thomasloughlin.com/gpspipe-gps-client/](http://thomasloughlin.com/gpspipe-gps-client/)
|
|
- [http://robotsforroboticists.com/chrony-gps-for-time-synchronization/](http://robotsforroboticists.com/chrony-gps-for-time-synchronization/)
|
|
- [https://forum.armbian.com/topic/4944-opi-zero-gps-ntpserver/](https://forum.armbian.com/topic/4944-opi-zero-gps-ntpserver/)
|
|
- [http://darethehair.net/gps_time_server.html](http://darethehair.net/gps_time_server.html)
|
|
- [https://forum.armbian.com/topic/7033-solved-orangepi-one-1-pps-ntp-server/
|
|
](https://forum.armbian.com/topic/7033-solved-orangepi-one-1-pps-ntp-server/
|
|
)
|
|
- [https://www.satsignal.eu/ntp/Raspberry-Pi-NTP.html](https://www.satsignal.eu/ntp/Raspberry-Pi-NTP.html)
|
|
|
|
## Hardware
|
|
|
|
The author chose the [Adafruit Ultimate GPS Breakout (link)](https://www.adafruit.com/product/746) for this guide. YMMV with other boards.
|
|
|
|
### Pinout
|
|
|
|
- Connect vcc to a 3v source on the main expansion header
|
|
- Connect gnd to a gnd on the main expansion header
|
|
- Connect tx to rx pin of uart2 on the main expansion header
|
|
- Connect rx to tx pin of uart2 on the main expaions header
|
|
- Connect pps to the PA6 pin on the main expansion header
|
|
|
|
## Setup
|
|
|
|
``` bash
|
|
|
|
armbian-config # Enable hardware uart2 and pps-gpio
|
|
# System
|
|
# Hardware
|
|
# Enable uart2 option
|
|
# Enable pps-gpio option
|
|
# Save/reboot
|
|
apt install gpsd gpsd-clients python-gps gpsbabel # necessary software
|
|
systemctl stop gpsd # stop gpsd to help with testin
|
|
gpsd -n -N -D 2 /dev/ttyS2 # run gpsd by hand
|
|
cgps -s # run a cli client to verify it works
|
|
|
|
```
|
|
|
|
Setup necessary ```gpsd``` defaults (daemon that provides location data to programs).
|
|
|
|
Edit ```/etc/default/gpsd```
|
|
|
|
- Add ```/dev/ttyS2``` to ```DEVICES```
|
|
- Add ```-n``` to ```GPSD_OPTIONS```
|
|
|
|
## Chrony
|
|
|
|
Setup PPS for chrony
|
|
|
|
``` bash
|
|
|
|
cat >> /boot/armbianEnv.txt <<EOF
|
|
# Orange Pi PC 2e PPS Pin
|
|
# param_pps_pin=PA6
|
|
# Pine64 PPS Pin
|
|
# param_pps_pin=PH9
|
|
|
|
EOF
|
|
systemctl reboot
|
|
demsg | grep -i pps # Verify pps is enabled and shows in the kernel
|
|
|
|
```
|
|
|
|
Add GPS as a time source to chrony
|
|
|
|
``` bash
|
|
|
|
cat >> /etc/chrony/chrony.conf <<EOF
|
|
# set larger delay to allow the NMEA source to overlap with
|
|
# the other sources and avoid the falseticker status
|
|
refclock SHM 0 refid GPS precision 1e-1 offset 0.9999 delay 0.2
|
|
refclock PPS /dev/pps0 lock NMEA
|
|
|
|
EOF
|
|
|
|
systemctl restart chrony
|
|
cgps # look for ```Status: 3D FIX```
|
|
chronyc sources -v # Should show PPS and GPS time sources as having a recent reading
|
|
chronyc tracking # Further details
|
|
|
|
```
|
|
|
|
## NTP For Network
|
|
|
|
To enable chrony on your lollipop as the ntp server for your local clients...
|
|
|
|
``` bash
|
|
|
|
cat > /etc/Networkmanager/dnsmasq-shared.d/ntp.conf <<EOF
|
|
dhcp-options=option:ntp-server,172.30.0.1
|
|
EOF
|
|
|
|
```
|
|
|
|
## GPX Tracks
|
|
|
|
### NextCloud
|
|
|
|
**GpxPod** for NextCloud is a good viewer for GPX track recordings
|
|
|
|
### Tracking
|
|
|
|
```gpspipe -r -d -l -o /tmp/xxx.nmea``` will record the raw GPS data from the module. Can be used for tracking.
|
|
|
|
### GPX Files
|
|
|
|
You can convert raw ```nmea``` data from ```gpspipe``` using ```gpsbabel```
|
|
|
|
Examples
|
|
|
|
- ```gpsbabel -t -r -w -i nmea -f /tmp/xxx.nmea -o gpx -F xxx.gpx```
|
|
- ```gpsbabel -t -i nmea -f /tmp/xxx.nmea -x track,pack,split=5m,title="LOG # %Y%m%d-%H%M" -o gpx -F out.gpx```
|
|
|
|
## Automatic Logging
|
|
|
|
The Python program used here is in the ```scripts``` directory.
|
|
|
|
``` bash
|
|
|
|
mkdir -p /tank/gps_data
|
|
chown -R gpsd:root /tank/gps_data
|
|
# put gpslog.py at /usr/local/bin
|
|
cat > /etc/systemd/system/gps-logger.service <<EOF
|
|
[Unit]
|
|
Description=Simple gps logger
|
|
After=gpsd.service gpsd.socket
|
|
|
|
[Service]
|
|
User=gpsd
|
|
ExecStart=/usr/local/bin/gpslog.py
|
|
Restart=on-failure
|
|
|
|
[Install]
|
|
WantedBy=multi-user.target
|
|
EOF
|
|
|
|
systemctl daemon-reload
|
|
systemctl enable gps-logger
|
|
systemctl start gps-logger
|
|
|
|
```
|
|
|
|
## Setup Auto GPX Track Creation/Upload
|
|
|
|
A handy trick for auto-converting your GPS log data as well as uploading it to NextCloud. The Python program used here is in the ```scripts``` directory.
|
|
|
|
``` bash
|
|
|
|
cat > /etc/systemd/system/gpsconvert.service <<EOF
|
|
[Unit]
|
|
Description=Merge GPS logs and upload to NextCloud
|
|
After=gps-logger
|
|
|
|
[Service]
|
|
ExecStart=/usr/local/bin/gpsconvert.py
|
|
EOF
|
|
|
|
cat > /etc/systemd/system/gpsconvert.timer <<EOF
|
|
[Unit]
|
|
Description=Run GPS log merge
|
|
|
|
[Timer]
|
|
OnCalendar=hourly
|
|
Persistent=true
|
|
|
|
[Install]
|
|
WantedBy=timers.target
|
|
EOF
|
|
|
|
systemctl daemon-reload
|
|
systemctl enable gpsconvert.timer
|
|
systemctl start gpsconvert.timer
|
|
|
|
```
|
|
|
|
## A-GPS
|
|
|
|
This sets up a form of A-GPS to speed locks when indoors or having a hard time getting a lock in general.
|
|
|
|
*This setup is specific to the Adafruit Ultimate GPS modules. You'll need to adapt this if using a different GPS receiver.*
|
|
|
|
### Setup mt3339 utils and get latest sattelite hints
|
|
|
|
``` bash
|
|
|
|
apt install python-pip python-setuptools python-wheel python3-pip python3-setuptools python3-wheel geoip-bin
|
|
pip install -U pyserial && pip3 install -U pyserial
|
|
cd /opt
|
|
git clone https://github.com/f5eng/mt3339-utils.git
|
|
cd /opt/mt3339-utils
|
|
./eporetrieve
|
|
|
|
```
|
|
|
|
### Get your current ip address
|
|
|
|
*Note: this MUST be done from your main internet connection, NOT VPN*
|
|
|
|
``` bash
|
|
|
|
curl http://ifconfig.co
|
|
|
|
```
|
|
|
|
### Setup Maxmind GeoIP database
|
|
|
|
``` bash
|
|
|
|
mkdir GeoLite2
|
|
cd GeoLite2
|
|
wget https://geolite.maxmind.com/download/geoip/database/GeoLite2-City.tar.gz
|
|
tar -xzf GeoLite2-City.tar.gz
|
|
cd ..
|
|
|
|
```
|
|
|
|
### Get IP Address Location
|
|
|
|
```
|
|
|
|
pip3 install -U maxminddb
|
|
python3
|
|
import maxminddb
|
|
reader = maxminddb.open_database('./GeoLite2/GeoLite2-City_20190402/GeoLite2-City.mmdb')
|
|
rec = reader.get('anipaddress')
|
|
print('%s,%s,0' %(rec['location']['latitude'], rec['location']['longitude']))
|
|
exit()
|
|
|
|
```
|
|
|
|
### Seed GPS Unit With Rough Location and System Time
|
|
|
|
``` bash
|
|
|
|
systemctl stop gpsd gpsd.socket gpsconvert.timer gpsconvert.service gps-logger
|
|
./epoloader --speed 9600 --time - --location python_output ./MTK14.EPO /dev/ttyS2
|
|
systemctl restart gpsd gpsd.socket gpsconvert.timer gpsconvert.service gps-logger
|
|
|
|
```
|
|
|