Merge pull request #7 from nordic-dev-net/add-shutdown-button

Merging, pending technical test.
This commit is contained in:
Julius Koskela 2023-02-21 18:54:25 +02:00 committed by GitHub
commit bc658ac06c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 99 additions and 59 deletions

View File

@ -5,4 +5,4 @@ build-audio:
cd audio-logger && cargo build --release
start-all:
cd scripts && start-all.sh
cd scripts && start-all.sh

View File

@ -1,3 +1,3 @@
taget
target
*.wav
recordings

View File

@ -7,4 +7,4 @@ target/release/audio rec \
--sample-rate 44100 \
--channels 2 \
--buffer-size 1024 \
alsa \
alsa \

View File

@ -7,7 +7,6 @@ import busio
import adafruit_ads1x15.ads1015 as ADS
from adafruit_extended_bus import ExtendedI2C as I2C
from adafruit_ads1x15.analog_in import AnalogIn
# from rpi_lcd import LCD
parser = argparse.ArgumentParser(description='GPS Logger')
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()
# try:
# lcd = LCD(bus=2)
# except OSError:
# lcd = None
# Create the I2C bus
if args.bus:
i2c_bus = args.bus
@ -64,10 +58,6 @@ with open(filename, "w", 1) as f:
# roundtemp = round(temperatureC, 2)
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")

BIN
docs/pi4wiring.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 MiB

View File

@ -2,21 +2,26 @@
SAMPLE_RATE=44100
CHANNELS=2
BITRATE="192k"
BITRATE=192k
# in seconds
BATCH_RECORD_LENGTH=60
# GPS
# in seconds
GPS_INTERVAL=5
# Depth
# in seconds
DEPTH_INTERVAL=5
# Output location
TRY_MOUNT_SSD=true
# TODO
#TRY_MOUNT_SSD=true
OUTPUT_PATH=/home/pi/data
HOME_PATH=/home/pi
DEFAULT_OUTPUT_PATH=/home/pi/recordings
OUTPUT_PATH=/home/pi/data

View File

@ -1,13 +0,0 @@
from rpi_lcd import LCD
from time import sleep
lcd = LCD(bus=2)
lcd.text('Hello World!', 1)
lcd.text('Raspberry Pi', 2)
lcd.text('is really', 3, 'center')
lcd.text('awesome', 4, 'right')
sleep(5)
lcd.clear()

View File

@ -13,18 +13,20 @@ card_number=$(aplay -l | grep -i usb | grep -i audio | cut -d ' ' -f 2 | cut -d
# Change default audio device
sudo touch /etc/asound.conf
sudo cat << EOF | sudo tee /etc/asound.conf
pcm.!default {
config="pcm.!default {
type plug
slave {
pcm "hw:$card_number,0"
pcm \"hw:$card_number,0\"
}
}
ctl.!default {
type hw
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

View File

@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/bash
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 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

View File

@ -1,16 +1,22 @@
#!/bin/sh
#!/bin/bash
set -ex
SDA_GPIO_PIN=10
SCL_GPIO_PIN=11
I2C_BUS=3
echo "Setting up depth recording"
# Enable i2c
sudo raspi-config nonint do_i2c 0
# Enable i2c on bus 3 and GPIO pins sda=23 and scl=24
sudo cat << EOF | sudo tee -a /boot/config.txt
dtoverlay=i2c-gpio,bus=3,i2c_gpio_sda=23,i2c_gpio_scl=24
EOF
config="dtoverlay=i2c-gpio,bus=$I2C_BUS,i2c_gpio_sda=$SDA_GPIO_PIN,i2c_gpio_scl=$SCL_GPIO_PIN"
if ! grep -q "$config" /boot/config.txt; then
echo "$config" | sudo tee -a /boot/config.txt
fi
# Install packages
sudo apt-get update && sudo apt-get install -y i2c-tools python3-pip

View File

@ -2,8 +2,17 @@
set -ex
DIR_PATH=$HOME
BOOT_DIR_PATH=/boot/hydrophonitor
LOG_FILE=$BOOT_DIR_PATH/$(date +"%Y-%m-%dT%H-%M-%S")-setup-log.txt
# Output from commands within the curly braces is written
# to $LOG_FILE
{
DIR_PATH=$HOME
echo
echo "Starting setup, writing logs to $LOG_FILE"
echo
echo
echo "### Update file paths in config and start script files"
@ -25,6 +34,7 @@ echo
mkdir -p "$DIR_PATH"
cd "$DIR_PATH"
rm -rf hydrophonitor
cp -R $BOOT_DIR_PATH/ .
# Install some development tools
@ -63,19 +73,29 @@ echo
cd "$DIR_PATH" && ./hydrophonitor/scripts/setup-pressure-depth.sh
# Setup shutdown button
echo
echo "### Setup shutdown button"
echo
cd "$DIR_PATH" && ./hydrophonitor/scripts/setup-shutdown-button.sh
# Set up cron job to start the recordings at boot
echo
echo "### Set up a cron job to start the recordings at boot"
echo
# USER=$(whoami)
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_LOG_FILE="$BOOT_DIR_PATH/\$(date +\"%Y-%m-%dT%H-%M-%S\")-cron-log.txt"
CRON_COMMAND="@reboot root $DIR_PATH/hydrophonitor/scripts/start-all.sh 2>&1 > $CRON_LOG_FILE"
# 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
echo
echo "### Setup ready, run 'sudo reboot' to apply all changes"
echo
} 2>&1 | sudo tee $LOG_FILE

View File

@ -8,9 +8,11 @@ echo "Setting up the real time clock module, part 1"
sudo raspi-config nonint do_i2c 0
# Enable i2c rtc on the default i2c pins
sudo cat << EOF | sudo tee -a /boot/config.txt
dtoverlay=i2c-rtc,ds3231
EOF
config="dtoverlay=i2c-rtc,ds3231"
if ! grep -q "$config" /boot/config.txt; then
echo "$config" | sudo tee -a /boot/config.txt
fi
# Disable 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
# Load needed modules at boot
sudo cat << EOF | sudo tee -a /etc/modules
i2c-bcm2708
config="i2c-bcm2708
i2c-dev
rtc-ds1307
EOF
rtc-ds1307"
if ! grep -q "$config" /etc/modules; then
echo "$config" | sudo tee -a /etc/modules
fi
# Remove some lines from /lib/udev/hwclock-set
sudo sed -i '/^if \[ \-e \/run\/systemd\/system \] ; then$/,/^fi$/d' /lib/udev/hwclock-set

View File

@ -4,15 +4,19 @@ set -x
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
sudo sed -i "s/^exit 0$//" /etc/rc.local
sudo cat << EOF | sudo tee -a /etc/rc.local
echo ds1307 0x68 | sudo tee /sys/class/i2c-adapter/i2c-1/new_device
config="echo ds1307 0x68 | sudo tee /sys/class/i2c-adapter/i2c-$I2C_BUS/new_device
sudo hwclock -s
exit 0
EOF
exit 0"
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
echo "Restarting systmd-timesyncd to update system time"

View File

@ -0,0 +1,11 @@
#!/bin/bash
set -ex
echo "Setting up shutdown button"
config="dtoverlay=gpio-shutdown,gpio_pin=21,gpio_pull=up,active_low=1"
if ! grep -q "$config" /boot/config.txt; then
echo "$config" | sudo tee -a /boot/config.txt
fi

View File

@ -3,6 +3,10 @@
# Print all commands to standard output
set -x
BOOT_DIR_PATH=/boot/hydrophonitor
LOG_FILE=$BOOT_DIR_PATH/$(date +"%Y-%m-%dT%H-%M-%S")-startup-log.txt
{
SCRIPT_PATH=/home/pi/hydrophonitor/scripts
# Export the configuration values
@ -16,4 +20,5 @@ mkdir -p "$OUTPUT_DIR"/audio
# Sleep for a little to wait for GPS and sound card to be ready
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 $LOG_FILE

View File

@ -2,10 +2,12 @@
set -x
I2C_BUS=3
# Export the configuration values
SCRIPT_PATH=/home/pi/hydrophonitor/scripts
. $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