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