Improve logging on setup and startup, make setup scripts idempotent
This commit is contained in:
parent
559e449ed1
commit
296e8c245b
@ -7,7 +7,6 @@ import busio
|
|||||||
import adafruit_ads1x15.ads1015 as ADS
|
import adafruit_ads1x15.ads1015 as ADS
|
||||||
from adafruit_extended_bus import ExtendedI2C as I2C
|
from adafruit_extended_bus import ExtendedI2C as I2C
|
||||||
from adafruit_ads1x15.analog_in import AnalogIn
|
from adafruit_ads1x15.analog_in import AnalogIn
|
||||||
# from rpi_lcd import LCD
|
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(description='GPS Logger')
|
parser = argparse.ArgumentParser(description='GPS Logger')
|
||||||
parser.add_argument('-o', '--output', help='Output directory', required=True)
|
parser.add_argument('-o', '--output', help='Output directory', required=True)
|
||||||
@ -16,11 +15,6 @@ parser.add_argument('-b', '--bus', help='Custom i2c bus to use', required=False)
|
|||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
# try:
|
|
||||||
# lcd = LCD(bus=2)
|
|
||||||
# except OSError:
|
|
||||||
# lcd = None
|
|
||||||
|
|
||||||
# Create the I2C bus
|
# Create the I2C bus
|
||||||
if args.bus:
|
if args.bus:
|
||||||
i2c_bus = args.bus
|
i2c_bus = args.bus
|
||||||
@ -64,10 +58,6 @@ with open(filename, "w", 1) as f:
|
|||||||
# roundtemp = round(temperatureC, 2)
|
# roundtemp = round(temperatureC, 2)
|
||||||
|
|
||||||
print((str(voltage) + " V ") + (str(depthM) + " m ") + (str(roundvolts) + " V ") + (str(rounddepth) + " m"), flush=True)
|
print((str(voltage) + " V ") + (str(depthM) + " m ") + (str(roundvolts) + " V ") + (str(rounddepth) + " m"), flush=True)
|
||||||
|
|
||||||
# if lcd:
|
|
||||||
# lcd.clear()
|
|
||||||
# lcd.text((str(roundvolts) + " V ") + (str(rounddepth) + " m"), 1)
|
|
||||||
|
|
||||||
f.write(time.strftime("%Y-%m-%dT%H:%M:%S") + "," + str(roundvolts) + "," + str(rounddepth) + "\n")
|
f.write(time.strftime("%Y-%m-%dT%H:%M:%S") + "," + str(roundvolts) + "," + str(rounddepth) + "\n")
|
||||||
|
|
||||||
|
@ -2,21 +2,26 @@
|
|||||||
|
|
||||||
SAMPLE_RATE=44100
|
SAMPLE_RATE=44100
|
||||||
CHANNELS=2
|
CHANNELS=2
|
||||||
BITRATE="192k"
|
BITRATE=192k
|
||||||
|
|
||||||
|
# in seconds
|
||||||
BATCH_RECORD_LENGTH=60
|
BATCH_RECORD_LENGTH=60
|
||||||
|
|
||||||
# GPS
|
# GPS
|
||||||
|
|
||||||
|
# in seconds
|
||||||
GPS_INTERVAL=5
|
GPS_INTERVAL=5
|
||||||
|
|
||||||
# Depth
|
# Depth
|
||||||
|
|
||||||
|
# in seconds
|
||||||
DEPTH_INTERVAL=5
|
DEPTH_INTERVAL=5
|
||||||
|
|
||||||
# Output location
|
# Output location
|
||||||
|
|
||||||
TRY_MOUNT_SSD=true
|
# TODO
|
||||||
|
#TRY_MOUNT_SSD=true
|
||||||
|
OUTPUT_PATH=/home/pi/data
|
||||||
|
|
||||||
HOME_PATH=/home/pi
|
HOME_PATH=/home/pi
|
||||||
DEFAULT_OUTPUT_PATH=/home/pi/recordings
|
DEFAULT_OUTPUT_PATH=/home/pi/recordings
|
||||||
OUTPUT_PATH=/home/pi/data
|
|
||||||
|
@ -13,18 +13,21 @@ card_number=$(aplay -l | grep -i usb | grep -i audio | cut -d ' ' -f 2 | cut -d
|
|||||||
# Change default audio device
|
# Change default audio device
|
||||||
sudo touch /etc/asound.conf
|
sudo touch /etc/asound.conf
|
||||||
|
|
||||||
sudo cat << EOF | sudo tee /etc/asound.conf
|
config="pcm.!default {
|
||||||
pcm.!default {
|
|
||||||
type plug
|
type plug
|
||||||
slave {
|
slave {
|
||||||
pcm "hw:$card_number,0"
|
pcm \"hw:$card_number,0\"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ctl.!default {
|
ctl.!default {
|
||||||
type hw
|
type hw
|
||||||
card $card_number
|
card $card_number
|
||||||
}
|
}"
|
||||||
EOF
|
|
||||||
|
if ! grep -q "$config" /etc/asound.conf; then
|
||||||
|
echo "$config" | sudo tee -a /etc/asound.conf
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
cd $HOME/hydrophonitor/audio-logger && cargo build --release
|
cd $HOME/hydrophonitor/audio-logger && cargo build --release
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#!/bin/sh
|
#!/bin/bash
|
||||||
|
|
||||||
set -ex
|
set -ex
|
||||||
|
|
||||||
@ -17,4 +17,8 @@ sudo gpsd ${device} -F /var/run/gpsd.sock
|
|||||||
|
|
||||||
sudo sed -i "s|DEVICES=\"\"|DEVICES=\"${device}\"|g" /etc/default/gpsd
|
sudo sed -i "s|DEVICES=\"\"|DEVICES=\"${device}\"|g" /etc/default/gpsd
|
||||||
|
|
||||||
sudo grep -qxF "START_DAEMON=\"true\"" /etc/default/gpsd || echo "START_DAEMON=\"true\"" | sudo tee -a /etc/default/gpsd
|
config="START_DAEMON=\"true\""
|
||||||
|
|
||||||
|
if ! grep -q "$config" /etc/default/gpsd; then
|
||||||
|
echo "$config" | sudo tee -a /etc/default/gpsd
|
||||||
|
fi
|
||||||
|
@ -1,16 +1,22 @@
|
|||||||
#!/bin/sh
|
#!/bin/bash
|
||||||
|
|
||||||
set -ex
|
set -ex
|
||||||
|
|
||||||
|
SDA_GPIO_PIN=10
|
||||||
|
SCL_GPIO_PIN=11
|
||||||
|
I2C_BUS=3
|
||||||
|
|
||||||
echo "Setting up depth recording"
|
echo "Setting up depth recording"
|
||||||
|
|
||||||
# Enable i2c
|
# Enable i2c
|
||||||
sudo raspi-config nonint do_i2c 0
|
sudo raspi-config nonint do_i2c 0
|
||||||
|
|
||||||
# Enable i2c on bus 3 and GPIO pins sda=23 and scl=24
|
# Enable i2c on bus 3 and GPIO pins sda=23 and scl=24
|
||||||
sudo cat << EOF | sudo tee -a /boot/config.txt
|
config="dtoverlay=i2c-gpio,bus=$I2C_BUS,i2c_gpio_sda=$SDA_GPIO_PIN,i2c_gpio_scl=$SCL_GPIO_PIN"
|
||||||
dtoverlay=i2c-gpio,bus=3,i2c_gpio_sda=23,i2c_gpio_scl=24
|
|
||||||
EOF
|
if ! grep -q "$config" /boot/config.txt; then
|
||||||
|
echo "$config" | sudo tee -a /boot/config.txt
|
||||||
|
fi
|
||||||
|
|
||||||
# Install packages
|
# Install packages
|
||||||
sudo apt-get update && sudo apt-get install -y i2c-tools python3-pip
|
sudo apt-get update && sudo apt-get install -y i2c-tools python3-pip
|
||||||
|
@ -2,9 +2,13 @@
|
|||||||
|
|
||||||
set -ex
|
set -ex
|
||||||
|
|
||||||
DIR_PATH=$HOME
|
|
||||||
BOOT_DIR_PATH=/boot/hydrophonitor
|
BOOT_DIR_PATH=/boot/hydrophonitor
|
||||||
|
|
||||||
|
# Output from commands within the curly braces is written
|
||||||
|
# to a log file in $BOOT_DIR_PATH
|
||||||
|
{
|
||||||
|
DIR_PATH=$HOME
|
||||||
|
|
||||||
echo
|
echo
|
||||||
echo "### Update file paths in config and start script files"
|
echo "### Update file paths in config and start script files"
|
||||||
echo
|
echo
|
||||||
@ -25,6 +29,7 @@ echo
|
|||||||
|
|
||||||
mkdir -p "$DIR_PATH"
|
mkdir -p "$DIR_PATH"
|
||||||
cd "$DIR_PATH"
|
cd "$DIR_PATH"
|
||||||
|
rm -rf hydrophonitor
|
||||||
cp -R $BOOT_DIR_PATH/ .
|
cp -R $BOOT_DIR_PATH/ .
|
||||||
|
|
||||||
# Install some development tools
|
# Install some development tools
|
||||||
@ -80,9 +85,12 @@ CRON_FILE=/etc/crontab
|
|||||||
CRON_COMMAND="@reboot root $DIR_PATH/hydrophonitor/scripts/start-all.sh 2>&1 > $BOOT_DIR_PATH/$(date +"%Y-%m-%dT%H-%M-%S")-log.txt"
|
CRON_COMMAND="@reboot root $DIR_PATH/hydrophonitor/scripts/start-all.sh 2>&1 > $BOOT_DIR_PATH/$(date +"%Y-%m-%dT%H-%M-%S")-log.txt"
|
||||||
|
|
||||||
# Append command to cron file only if it's not there yet
|
# Append command to cron file only if it's not there yet
|
||||||
sudo grep -qxF "$CRON_COMMAND" $CRON_FILE || echo "$CRON_COMMAND" | sudo tee -a $CRON_FILE
|
if ! grep -q "$CRON_COMMAND" "$CRON_FILE"; then
|
||||||
|
echo "$CRON_COMMAND" | sudo tee -a "$CRON_FILE"
|
||||||
|
fi
|
||||||
|
|
||||||
# Reboot
|
# Reboot
|
||||||
echo
|
echo
|
||||||
echo "### Setup ready, run 'sudo reboot' to apply all changes"
|
echo "### Setup ready, run 'sudo reboot' to apply all changes"
|
||||||
echo
|
echo
|
||||||
|
} 2>&1 | sudo tee $BOOT_DIR_PATH/$(date +"%Y-%m-%dT%H-%M-%S")-setup-log.txt
|
@ -8,9 +8,11 @@ echo "Setting up the real time clock module, part 1"
|
|||||||
sudo raspi-config nonint do_i2c 0
|
sudo raspi-config nonint do_i2c 0
|
||||||
|
|
||||||
# Enable i2c rtc on the default i2c pins
|
# Enable i2c rtc on the default i2c pins
|
||||||
sudo cat << EOF | sudo tee -a /boot/config.txt
|
config="dtoverlay=i2c-rtc,ds3231"
|
||||||
dtoverlay=i2c-rtc,ds3231
|
|
||||||
EOF
|
if ! grep -q "$config" /boot/config.txt; then
|
||||||
|
echo "$config" | sudo tee -a /boot/config.txt
|
||||||
|
fi
|
||||||
|
|
||||||
# Disable fake-hwclock
|
# Disable fake-hwclock
|
||||||
sudo apt-get remove -y fake-hwclock
|
sudo apt-get remove -y fake-hwclock
|
||||||
@ -18,11 +20,13 @@ sudo update-rc.d -f fake-hwclock remove
|
|||||||
sudo systemctl disable fake-hwclock
|
sudo systemctl disable fake-hwclock
|
||||||
|
|
||||||
# Load needed modules at boot
|
# Load needed modules at boot
|
||||||
sudo cat << EOF | sudo tee -a /etc/modules
|
config="i2c-bcm2708
|
||||||
i2c-bcm2708
|
|
||||||
i2c-dev
|
i2c-dev
|
||||||
rtc-ds1307
|
rtc-ds1307"
|
||||||
EOF
|
|
||||||
|
if ! grep -q "$config" /etc/modules; then
|
||||||
|
echo "$config" | sudo tee -a /etc/modules
|
||||||
|
fi
|
||||||
|
|
||||||
# Remove some lines from /lib/udev/hwclock-set
|
# Remove some lines from /lib/udev/hwclock-set
|
||||||
sudo sed -i '/^if \[ \-e \/run\/systemd\/system \] ; then$/,/^fi$/d' /lib/udev/hwclock-set
|
sudo sed -i '/^if \[ \-e \/run\/systemd\/system \] ; then$/,/^fi$/d' /lib/udev/hwclock-set
|
||||||
|
@ -4,15 +4,19 @@ set -x
|
|||||||
|
|
||||||
echo "Setting up the real time clock module, part 2"
|
echo "Setting up the real time clock module, part 2"
|
||||||
|
|
||||||
echo ds1307 0x68 | sudo tee /sys/class/i2c-adapter/i2c-1/new_device
|
I2C_BUS=1
|
||||||
|
|
||||||
|
echo ds1307 0x68 | sudo tee /sys/class/i2c-adapter/i2c-$I2C_BUS/new_device
|
||||||
|
|
||||||
# Load RTC clock at boot
|
# Load RTC clock at boot
|
||||||
sudo sed -i "s/^exit 0$//" /etc/rc.local
|
config="echo ds1307 0x68 | sudo tee /sys/class/i2c-adapter/i2c-$I2C_BUS/new_device
|
||||||
sudo cat << EOF | sudo tee -a /etc/rc.local
|
|
||||||
echo ds1307 0x68 | sudo tee /sys/class/i2c-adapter/i2c-1/new_device
|
|
||||||
sudo hwclock -s
|
sudo hwclock -s
|
||||||
exit 0
|
exit 0"
|
||||||
EOF
|
|
||||||
|
if ! grep -q "$config" /etc/rc.local; then
|
||||||
|
sudo sed -i "s/^exit 0$//" /etc/rc.local
|
||||||
|
echo "$config" | sudo tee -a /etc/rc.local
|
||||||
|
fi
|
||||||
|
|
||||||
# Set system time to Internet time
|
# Set system time to Internet time
|
||||||
echo "Restarting systmd-timesyncd to update system time"
|
echo "Restarting systmd-timesyncd to update system time"
|
||||||
|
@ -3,6 +3,9 @@
|
|||||||
# Print all commands to standard output
|
# Print all commands to standard output
|
||||||
set -x
|
set -x
|
||||||
|
|
||||||
|
BOOT_DIR_PATH=/boot/hydrophonitor
|
||||||
|
|
||||||
|
{
|
||||||
SCRIPT_PATH=/home/pi/hydrophonitor/scripts
|
SCRIPT_PATH=/home/pi/hydrophonitor/scripts
|
||||||
|
|
||||||
# Export the configuration values
|
# Export the configuration values
|
||||||
@ -16,4 +19,5 @@ mkdir -p "$OUTPUT_DIR"/audio
|
|||||||
# Sleep for a little to wait for GPS and sound card to be ready
|
# Sleep for a little to wait for GPS and sound card to be ready
|
||||||
sleep 10
|
sleep 10
|
||||||
|
|
||||||
(export OUTPUT_DIR=$OUTPUT_DIR; $SCRIPT_PATH/start-audio.sh & $SCRIPT_PATH/start-gps.sh & $SCRIPT_PATH/start-pressure-depth.sh) >> "$OUTPUT_DIR"/log.txt 2>&1
|
(export OUTPUT_DIR=$OUTPUT_DIR; $SCRIPT_PATH/start-audio.sh & $SCRIPT_PATH/start-gps.sh & $SCRIPT_PATH/start-pressure-depth.sh) 2>&1 | tee "$OUTPUT_DIR"/log.txt
|
||||||
|
} 2>&1 | tee $BOOT_DIR_PATH/$(date +"%Y-%m-%dT%H-%M-%S")-startup-log.txt
|
||||||
|
@ -2,10 +2,12 @@
|
|||||||
|
|
||||||
set -x
|
set -x
|
||||||
|
|
||||||
|
I2C_BUS=3
|
||||||
|
|
||||||
# Export the configuration values
|
# Export the configuration values
|
||||||
SCRIPT_PATH=/home/pi/hydrophonitor/scripts
|
SCRIPT_PATH=/home/pi/hydrophonitor/scripts
|
||||||
. $SCRIPT_PATH/export-config-values.sh
|
. $SCRIPT_PATH/export-config-values.sh
|
||||||
|
|
||||||
OPTIONS="--output $OUTPUT_DIR --interval $DEPTH_INTERVAL --bus 3"
|
OPTIONS="--output $OUTPUT_DIR --interval $DEPTH_INTERVAL --bus $I2C_BUS"
|
||||||
|
|
||||||
cd $HOME_PATH/hydrophonitor/depth-logger && python record-depth.py $OPTIONS
|
cd $HOME_PATH/hydrophonitor/depth-logger && python record-depth.py $OPTIONS
|
||||||
|
Loading…
Reference in New Issue
Block a user