From a8ebf389fbdb1081900dbd4ba2483e95bc23e22c Mon Sep 17 00:00:00 2001 From: Satu Koskinen Date: Tue, 4 Oct 2022 21:12:00 +0300 Subject: [PATCH] Fix configuration and scripts --- configuration/hydrophonitor-config.txt | 14 +++++++------- configuration/setup-raspberry-pi.sh | 4 +--- gps-logger/record-gps.py | 2 +- scripts/export-config-values.sh | 2 +- scripts/setup-audio.sh | 5 +++-- scripts/start-all.sh | 12 ++++++++---- scripts/start-audio.sh | 6 ++++-- scripts/start-gps.sh | 2 ++ 8 files changed, 27 insertions(+), 20 deletions(-) diff --git a/configuration/hydrophonitor-config.txt b/configuration/hydrophonitor-config.txt index a5fd070..008aa7f 100644 --- a/configuration/hydrophonitor-config.txt +++ b/configuration/hydrophonitor-config.txt @@ -1,21 +1,21 @@ # Audio -SAMPLE_RATE="44100" -CHANNELS="2" +SAMPLE_RATE=44100 +CHANNELS=2 BITRATE="192k" -BATCH_RECORD_LENGTH="60" +BATCH_RECORD_LENGTH=60 # GPS -GPS_INTERVAL="5" +GPS_INTERVAL=5 # Depth -DEPTH_INTERVAL="5" +DEPTH_INTERVAL=5 # Output location TRY_MOUNT_SSD="true" -DEFAULT_BASE_DIR_PATH="/home/pi/recordings" -BASE_DIR_PATH="/home/pi/data" +DEFAULT_BASE_DIR_PATH=/home/pi/recordings +BASE_DIR_PATH=/home/pi/data diff --git a/configuration/setup-raspberry-pi.sh b/configuration/setup-raspberry-pi.sh index 3c02223..a6e82f7 100644 --- a/configuration/setup-raspberry-pi.sh +++ b/configuration/setup-raspberry-pi.sh @@ -1,7 +1,5 @@ #!/bin/sh -set -euo pipefail - # Copy the files to /home/pi cd /home/pi cp -R /boot/hydrophonitor . @@ -21,7 +19,7 @@ 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 +echo "@reboot root /home/pi/hydrophonitor/scripts/start-all.sh" | sudo tee -a $CRON_FILE # Reboot sudo reboot diff --git a/gps-logger/record-gps.py b/gps-logger/record-gps.py index 4b0c5d1..1b1d629 100644 --- a/gps-logger/record-gps.py +++ b/gps-logger/record-gps.py @@ -10,7 +10,7 @@ parser.add_argument('-i', '--interval', help='Interval in seconds', required=Fal args = parser.parse_args() -filename = args.output + time.strftime("%Y-%m-%dT%H-%M-%S") + "_GPS_data.csv" +filename = args.output + "/" + time.strftime("%Y-%m-%dT%H-%M-%S") + "_GPS_data.csv" with open(filename, "w", 1) as f: gpsd = gps(mode=WATCH_ENABLE|WATCH_NEWSTYLE) diff --git a/scripts/export-config-values.sh b/scripts/export-config-values.sh index 483f3dd..d85f8c8 100644 --- a/scripts/export-config-values.sh +++ b/scripts/export-config-values.sh @@ -1,5 +1,5 @@ #!/bin/sh -CONFIG_FILE=/boot/hydrophonitor/hydrophonitor-config.txt +CONFIG_FILE=/boot/hydrophonitor/configuration/hydrophonitor-config.txt export $(grep -v '^#' $CONFIG_FILE | xargs -d '\n') diff --git a/scripts/setup-audio.sh b/scripts/setup-audio.sh index 0aa73f1..1b1e3b7 100755 --- a/scripts/setup-audio.sh +++ b/scripts/setup-audio.sh @@ -1,11 +1,12 @@ #!/bin/sh -# Get ID and number of the USB audio device +# Install packages +sudo apt-get update && sudo apt-get install -y libasound2-dev libjack-dev jackd2 +# Get ID and number of the USB audio device card_number=$(aplay -l | grep -i usb | grep -i audio | cut -d ' ' -f 2 | cut -d ':' -f 1) # Change default audio device - sudo touch /etc/asound.conf sudo cat << EOF | sudo tee -a /etc/asound.conf diff --git a/scripts/start-all.sh b/scripts/start-all.sh index f642cba..04a5905 100755 --- a/scripts/start-all.sh +++ b/scripts/start-all.sh @@ -1,13 +1,17 @@ #!/bin/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 +mkdir -p $OUTPUT_DIR/audio -(export OUTPUT_DIR=$OUTPUT_DIR; trap 'kill 0' SIGINT; ./scripts/start-gps.sh & ./scripts/start-audio.sh & ./scripts/start-pressure-depth.sh) +sleep 10 + +# (export OUTPUT_DIR=$OUTPUT_DIR; trap 'kill 0' SIGINT; /home/pi/hydrophonitor/scripts/scripts/start-gps.sh & /home/pi/hydrophonitor/scripts/start-audio.sh & /home/pi/hydrophonitor/scripts/start-pressure-depth.sh) + +echo "(export OUTPUT_DIR=$OUTPUT_DIR; /home/pi/hydrophonitor/scripts/start-audio.sh & /home/pi/hydrophonitor/scripts/start-gps.sh)" >> $OUTPUT_DIR/log.txt 2>&1 + +(export OUTPUT_DIR=$OUTPUT_DIR; /home/pi/hydrophonitor/scripts/start-audio.sh & /home/pi/hydrophonitor/scripts/start-gps.sh) >> $OUTPUT_DIR/log.txt 2>&1 diff --git a/scripts/start-audio.sh b/scripts/start-audio.sh index 6a1b825..4107bc0 100755 --- a/scripts/start-audio.sh +++ b/scripts/start-audio.sh @@ -8,11 +8,13 @@ AUDIO_TARGET_EXECUTABLE="audio" OPTIONS="rec \ --name audio_data \ ---output $OUTPUT_DIR \ +--output $OUTPUT_DIR/audio \ --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 +echo "cd $AUDIO_TARGET_LOCATION && ./$AUDIO_TARGET_EXECUTABLE $OPTIONS" + +cd $AUDIO_TARGET_LOCATION && ./$AUDIO_TARGET_EXECUTABLE $OPTIONS diff --git a/scripts/start-gps.sh b/scripts/start-gps.sh index 7b1bf5e..e392daf 100755 --- a/scripts/start-gps.sh +++ b/scripts/start-gps.sh @@ -6,4 +6,6 @@ GPS_EXECUTABLE_LOCATION="/home/pi/hydrophonitor/gps-logger" OPTIONS="--output $OUTPUT_DIR --interval $GPS_INTERVAL" +echo "cd $GPS_EXECUTABLE_LOCATION && python record-gps.py $OPTIONS" + cd $GPS_EXECUTABLE_LOCATION && python record-gps.py $OPTIONS