From 8f398e90de0c34d84db0f2c178f04a292d4b5f6f Mon Sep 17 00:00:00 2001 From: Satu Koskinen Date: Mon, 3 Oct 2022 19:37:15 +0300 Subject: [PATCH] Update start scripts, add scripts for setup and config value exports --- configuration/setup-raspberry-pi.sh | 27 +++++++++++++++++++++++++++ scripts/export-config-values.sh | 5 +++++ scripts/start-all.sh | 12 +++++++++++- scripts/start-audio.sh | 19 +++++++++++++++---- scripts/start-gps.sh | 9 ++++++--- scripts/start-pressure-depth.sh | 8 ++++++-- 6 files changed, 70 insertions(+), 10 deletions(-) create mode 100644 configuration/setup-raspberry-pi.sh create mode 100644 scripts/export-config-values.sh diff --git a/configuration/setup-raspberry-pi.sh b/configuration/setup-raspberry-pi.sh new file mode 100644 index 0000000..3c02223 --- /dev/null +++ b/configuration/setup-raspberry-pi.sh @@ -0,0 +1,27 @@ +#!/bin/sh + +set -euo pipefail + +# Copy the files to /home/pi +cd /home/pi +cp -R /boot/hydrophonitor . +cd hydrophonitor + +# Install the Rust toolchain +curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y + +# Setup audio +sh scripts/setup-audio.sh + +# Setup GPS +sh scripts/setup-gps.sh + +# Setup depth sensor +sh scripts/setup-pressure-depth.sh + +# Setup cron job to start the recordings at boot +CRON_FILE=/etc/crontab +echo "@reboot root /home/pi/hydrophonitor/scripts/start-all.sh" >> $CRON_FILE + +# Reboot +sudo reboot diff --git a/scripts/export-config-values.sh b/scripts/export-config-values.sh new file mode 100644 index 0000000..483f3dd --- /dev/null +++ b/scripts/export-config-values.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +CONFIG_FILE=/boot/hydrophonitor/hydrophonitor-config.txt + +export $(grep -v '^#' $CONFIG_FILE | xargs -d '\n') diff --git a/scripts/start-all.sh b/scripts/start-all.sh index 8630d40..f642cba 100755 --- a/scripts/start-all.sh +++ b/scripts/start-all.sh @@ -1,3 +1,13 @@ #!/bin/sh -(trap 'kill 0' SIGINT; ./scripts/start-gps.sh & ./scripts/start-audio.sh & ./scripts/start-pressure-depth.sh) +set -euo pipefail + +# Export the configuration values +. /home/pi/hydrophonitor/scripts/export-config-values.sh + +# Create output directory +OUTPUT_DIR=$BASE_DIR_PATH/$(date +"%Y-%m-%d_%H-%M-%S_output") + +mkdir -p $OUTPUT_DIR + +(export OUTPUT_DIR=$OUTPUT_DIR; trap 'kill 0' SIGINT; ./scripts/start-gps.sh & ./scripts/start-audio.sh & ./scripts/start-pressure-depth.sh) diff --git a/scripts/start-audio.sh b/scripts/start-audio.sh index cfc0680..6a1b825 100755 --- a/scripts/start-audio.sh +++ b/scripts/start-audio.sh @@ -1,7 +1,18 @@ #!/bin/sh -AUDIO_TARGET_LOCATION="/home/shared/hydrophonitor/audio-logger/target/release" -AUDIO_TARGET_EXECUTABLE="audio" -OPTIONS="" +# Export the configuration values +. /home/pi/hydrophonitor/scripts/export-config-values.sh -cd $AUDIO_TARGET_LOCATION && ./AUDIO_TARGET_EXECUTABLE $OPTIONS \ No newline at end of file +AUDIO_TARGET_LOCATION="/home/pi/hydrophonitor/audio-logger/target/release" +AUDIO_TARGET_EXECUTABLE="audio" + +OPTIONS="rec \ +--name audio_data \ +--output $OUTPUT_DIR \ +--batch-recording $BATCH_RECORD_LENGTH \ +--sample-rate $SAMPLE_RATE \ +--channels $CHANNELS \ +--buffer-size 1024 \ +alsa" + +cd $AUDIO_TARGET_LOCATION && ./$AUDIO_TARGET_EXECUTABLE $OPTIONS \ No newline at end of file diff --git a/scripts/start-gps.sh b/scripts/start-gps.sh index 08ba09d..7b1bf5e 100755 --- a/scripts/start-gps.sh +++ b/scripts/start-gps.sh @@ -1,6 +1,9 @@ #!/usr/bin/sh -GPS_TARGET_LOCATION="/home/shared/hydrophonitor/gps-logger" -OPTIONS="" +# Export the configuration values +. /home/pi/hydrophonitor/scripts/export-config-values.sh -cd $GPS_TARGET_LOCATION && python record-gps.py $OPTIONS +GPS_EXECUTABLE_LOCATION="/home/pi/hydrophonitor/gps-logger" +OPTIONS="--output $OUTPUT_DIR --interval $GPS_INTERVAL" + +cd $GPS_EXECUTABLE_LOCATION && python record-gps.py $OPTIONS diff --git a/scripts/start-pressure-depth.sh b/scripts/start-pressure-depth.sh index f7ff23a..ac344c9 100644 --- a/scripts/start-pressure-depth.sh +++ b/scripts/start-pressure-depth.sh @@ -1,6 +1,10 @@ #!/usr/bin/sh -DEPTH_TARGET_LOCATION="/home/shared/hydrophonitor/depth-logger" -OPTIONS="" +# Export the configuration values +. /home/pi/hydrophonitor/scripts/export-config-values.sh + +DEPTH_EXECUTABLE_LOCATION="/home/pi/hydrophonitor/depth-logger" + +OPTIONS="--output $OUTPUT_DIR --interval $DEPTH_INTERVAL" cd $DEPTH_TARGET_LOCATION && python record-depth.py $OPTIONS