Merge branch 'develop' into feature/time-server/EVA-2020-02
[EVA-2020-02.git] / doc / location / README.org
CommitLineData
170f63ba 1* Location Logging
f7628e90
SBS
2#+TITLE: Ninfacyzga-01 Manual
3#+AUTHOR: Steven Baltakatei Sandoval
f7628e90 4#+EMAIL: baltakatei@gmail.com
7b09912b
SBS
5** About
6This document was created by Steven Baltakatei Sandoval on
7~2020-06-29T12:14Z~ under a [[https://creativecommons.org/licenses/by-sa/4.0/][Creative Commons BY-SA 4.0 license]]. It
ce11ca44 8was updated by Steven Baltakatei Sandoval on ~2020-10-08T18:14Z~
7b09912b 9
170f63ba
SBS
10** Narrative
11Ninfacyzga-01 records (logs) its position in time and space using a
12[[https://en.wikipedia.org/wiki/Satellite_navigation_device][GPS receiver]]. The NMEA location data produced by the receiver is
13converted into the more commonly used GPS data storage formats of GPX
14and KML. All three types of data are then compressed and encrypted
15against a set of public keys. The encrypted data is then written to
16disk. Data produced by the receiver is segmented into 60-second chunks
17before being processed and written to disk.
18** Description
19*** Hardware
20**** Raspberry Pi Zero W
21See the [[https://www.raspberrypi.org/pi-zero-w/][OEM]] webpage for this product.
22**** PiZ UpTime 2.0
23See the [[https://alchemy-power.com/piz-uptime-2-0/][OEM]] webpage for this product.
24*** Software
aedd19f6
SBS
25~bklog~ : A bash script that saves its stdin stream to a tar file. The
26file may be compressed by ~gzip~ and encrypted by ~age~. It is an
27executable file contained within this repository at ~exec/bklog~. It
28should be copied to ~$HOME/.local/bin~.
29
30~bkgpslog~ : A legacy bash script similar to ~bklog~ but narrower in
31scope in that it only records output from ~gpspipe~.
170f63ba
SBS
32
33~gpsd~ : A background daemon app capable of interfacing with the
34Ozzmaker BerryGPS-IMU's GPS submodule. Installed and initialized by
35~apt~.
36
37~gpspipe~ : A command line app that polls ~gpsd~ and produces a stream
38stdout consisting of GPS data lines in NMEA format. Installed via
39~apt~.
40
41~gpsbabel~ : A command line app that converts GPS data from one format
aedd19f6 42into another. ~bklog~ may be used to convert NMEA data into GPX and
170f63ba
SBS
43KML. Installed via ~apt~.
44
45~gzip~ : A simple command line app that compresses stdin into a
46smaller stdout stream.
47
48~age~ : A simple command line app that encrypts stdin against public
49keys specified in its options. Produces encrypted stdout. Is an
50executable file contained within this repository at ~exec/age~. It
51should be copied to ~$HOME/.local/bin~.
52
53**** Narrative
aedd19f6
SBS
54~bklog~ may be used to log location data by receiving stdout produced
55by ~gpspipe~. ~bklog~ contains options that allow file writes to be
56performed at adjustable time intervals (default: 300 seconds),
57compressed (with ~gzip~), and encrypted (with ~age~). Files are
58written in the form of appendages to a ~tar~ archive saved to a
59specified location. The NMEA data produced by ~gpspipe~ may be
60processed via a ~gpsbabel~ command string specified as an option to
61~bklog~, assuming ~gpsbabel~ is installed.
170f63ba
SBS
62
63*** Output
aedd19f6
SBS
64
65Several output file formats have been tested with ~bklog~.
66
170f63ba
SBS
67**** File Formats
68***** NMEA
ebeb4cb3
SBS
69~NMEA~ is an acronym for National marine Electronics Association. The
70NMEA format described in this document follows the NMEA 0183
71standard. It is a newline-delimited streaming text format that encodes
72global positioning system (GPS) data such as WGS84 location, time and
73date information, satellite count, accuracy, and other
74information. Each line is an "NMEA sentence". Descriptions of various
75NMEA sentences can be found on [[http://aprs.gids.nl/nmea/][this]] webpage.
76
77See the [[https://en.wikipedia.org/wiki/NMEA_0183][Wikipedia page for NMEA 0183]] for this. This file format is the
78default output of the ~gpspipe -r~ command.
170f63ba 79***** GPX
aedd19f6
SBS
80See the [[https://en.wikipedia.org/wiki/GPS_Exchange_Format][Wikipedia page]] for this. [[http://wiki.gis.com/wiki/index.php/WGS84][WGS84]] is the datum used. An NMEA file
81may be converted to this format using ~gpsbabel~.
170f63ba 82***** KML
aedd19f6
SBS
83See the [[https://en.wikipedia.org/wiki/Keyhole_Markup_Language][Wikipedia page]] for this. [[http://wiki.gis.com/wiki/index.php/WGS84][WGS84]] is the datum used. An NMEA file
84may be converted to this format using ~gpsbabel~.
85
170f63ba 86**** Encryption Method
7b09912b 87See [[file:../setup/README.org][Main Setup]] procedures.
aedd19f6 88
170f63ba
SBS
89** Operating Procedures
90*** Initial Startup
27a8996a 91See OEM (Ozzmaker) [[https://ozzmaker.com/berrygps-berrygps-imu-quick-start-guide/][quickstart guide for the BerryGPS-IMU]].
27a8996a
SBS
92**** Physical Setup
93
94BerryGPS-IMU must be electrically connected to the correct pins on the
95GPIO header of a Raspberry Pi Zero W.
96
97*Optional*: stack together with PiZ Uptime 2.0 module. No GPIO pins
98conflict so a simple stacking and soldering with long header pins is
99possible.
100
101**** Software Setup
27a8996a 102***** Install Executables
ef3c23a1
SBS
103Follow the [[file:../setup/README.org][Main Setup]] procedures to obtain required files from this
104repository.
105
ce11ca44 106Install ~gpsd~, ~gpsd-clients~, and ~gpsbabel~.
27a8996a 107
ce11ca44 108: $ sudo apt install gpsd gpsd-clients gpsbabel
27a8996a 109
b9a2869d
SBS
110***** Setup Serial for BerryGPS
111The Ozzmaker BerryGPS-IMU unit requires that the serial console be
112disabled and the serial port enabled. (see [[https://ozzmaker.com/berrygps-setup-guide-raspberry-pi/][ref]]).
113
114: $ sudo raspi-config
115
116Navigate to ~5 Interfacing Options~, then ~P6 Serial~.
117
118When prompted "Would you like a login shell to be accessible over
119serial?", answer ~No~.
120
121When prompted "Would you like the serial port hardware to be
122enabled?", answer ~Yes~.
123
124***** Configure ~gpsd~
125~gpsd~ needs to know which serial port to look at for NMEA location
126data generated by the GPS unit. This can be done by modifying the
127~gpsd~ configuration file at ~/etc/default/gpsd~.
128
129: sudo nano /etc/default/gpsd
130
131Change
132
133: DEVICES=""
134
135to
136
137: DEVICES="/dev/serial0"
138
27a8996a 139***** Automatic Start Configuration
aedd19f6
SBS
140It is recommended to create a daily ~cron~ job that executes a bash
141script that starts ~bklog~ jobs to record location along with other
142types of data recording. An example of such a script is below:
27a8996a
SBS
143
144#+BEGIN_EXAMPLE
aedd19f6
SBS
145#!/bin/bash
146
147# Log location
148gpspipe -r | /bin/bash "$HOME/.local/bin/bklog" -c -e -z "UTC" -t "/dev/shm" \
149 -r age1kza7pfshy7xwygf9349zgmk7x53mquvedgw9r98qwyyqhssh830qqjzlsw \
150 -r age1ce3pvzrqfcn2pc6zqzglc8ac8yjk3fzukpy08cesqjjwns53xywqmaq7xw \
151 -R "$HOME/.config/bklog/recipients" -w ".nmea" -b "300" -B "day" \
152 -o "$HOME/Sync/Evanescent_Location" -l "location" \
153 -p "gpsbabel -i nmea -f - -o gpx -F - " ".gpx" \
154 -p "gpsbabel -i nmea -f - -o kml -F - " ".kml" &
155# Log pressure
156python ~/.local/bin/bmp388.py | /bin/bash "$HOME/git-OC/ninfacyzga-01/exec/bklog" \
157 -c -e -z "UTC" -t "/dev/shm" \
158 -r age1kza7pfshy7xwygf9349zgmk7x53mquvedgw9r98qwyyqhssh830qqjzlsw \
159 -r age1ce3pvzrqfcn2pc6zqzglc8ac8yjk3fzukpy08cesqjjwns53xywqmaq7xw \
160 -R "$HOME/.config/bklog/recipients" -w ".txt" -b "300" -B "day" \
161 -o "$HOME/Sync/Evanescent_Location" -l "pressure" &
27a8996a
SBS
162#+END_EXAMPLE
163
aedd19f6
SBS
164This script, if it were saved at
165~"$HOME/.local/bin/cron/dailylog.sh"~ would then be added as a
166line in the ~crontab~ file as shown below:
b11c81de
SBS
167
168#+BEGIN_EXAMPLE
aedd19f6
SBS
169$ crontab -e
1700 0 * * * /bin/bash ~/.local/bin/cron/dailylog.sh
171@reboot /bin/bash ~/.local/bin/cron/dailylog.sh
b11c81de
SBS
172#+END_EXAMPLE
173
aedd19f6
SBS
174In the example script, the options are:
175
176: -c : tells bklog to compress output
177: -e : tells bklog log to encrypt output
178: -r : tells bklog to interpret the next argument as a pubkey string
179: -R : tells bklog to interpret the next argument as a directory
180: where public keys may be found (first line of each file is
181: read).
182: -o : tells bklog to write output files to the directory represented
183: -t : tells bklog to interpret the next argument as a directory
184: for storing temporary files
b11c81de 185: by the next argument
aedd19f6
SBS
186: -p : tells bklog a command string through which output is piped
187: before being compressed and encrypted. Also expected is a
188: file extension to be appended before the compression and
189: encryption file extensions.
190: -w : tells bklog to save the unprocessed stdin with a specified
191: file extension (instead of the default '.stdin').
192: -b : tells bklog how long each buffer round (time between file
193: writes) lasts in seconds.
194: -B : specifies the time-to-live for the bklog script. A valid value may
195: one of the time elements such as "day" or "hour".
196: -l : specfies a custom string to be used in output file names to
197: help differentiate tar files produced via bklog from different
198: sources of data.
199: -z : specifies a time zone to be used to determine the script time-to-live.
200: By default, bklog uses whatever time is specified by the TZ
201: environment variable.
b11c81de 202
27a8996a 203***** Log Transfer Configuration
7b09912b
SBS
204See [[file:../setup/README.org][Main Setup]] procedures.
205
27a8996a
SBS
206Log files may be shared to other machines via ~syncthing~. See [[https://docs.syncthing.net/][this]]
207manual for how to set up a shared folder and add Ninfacyzga-01 as a
208device. Syncthing's directory synchronization capability allows a
209remote machine to delete files from Ninfacyzga-01 by deleting from the
210shared folder that they both share.
211
212When log files are removed from Ninfacyzga-01 is not within the scope
213of this document.
214
215***** Key Generation
7b09912b 216See [[file:../setup/README.org][Main Setup]] procedures.
27a8996a 217
170f63ba 218*** Normal Startup
27a8996a
SBS
219Turn on Ninfacyzga-01 by supplying 5VDC power to the Raspberry Pi. No
220further interaction should be required.
221*** Normal Operation
222No interaction beyond continually supplying approximately 100mA of
2235VDC power and occasionally removing log files to conserve disk space
224is required.
225**** Log Transfer
226Log files may be transferred by use of ~syncthing~ shared folders.
227**** Automatic Updates
228The ~automatic-upgrades~ package, if installed, should automatically
229install security patches to packages installed via ~apt~.
170f63ba 230*** Normal Shutdown
27a8996a
SBS
231The system may be shutdown via SSH by running:
232
233: $ sudo shutdown -r 0
234
170f63ba 235*** Unscheduled Shutdown
27a8996a
SBS
236Ninfacyzga-01 as described and setup should tolerate unscheduled power
237loss. Log files being written every 60 seconds means, at most, 60
238seconds worth of location data may be lost.
170f63ba 239*** End of Life Disposal
7b09912b 240See [[file:../setup/README.org][Main Setup]] procedures.