From a1eccc0c3d09d08c4ed1b18b64ee05fcb1212c20 Mon Sep 17 00:00:00 2001 From: Satu Koskinen Date: Sat, 22 Oct 2022 14:39:10 +0300 Subject: [PATCH 1/4] Fix datetime prefix setting to pad one-digit values with a zero in audio recording --- audio-logger/src/getters.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/audio-logger/src/getters.rs b/audio-logger/src/getters.rs index 72b250c..e417977 100644 --- a/audio-logger/src/getters.rs +++ b/audio-logger/src/getters.rs @@ -97,7 +97,7 @@ pub fn get_wav_spec(default_config: &SupportedStreamConfig, user_config: &Stream pub fn get_date_time_string() -> String { let now: DateTime = Local::now(); format!( - "{}-{}-{}_{}:{}:{:02}", + "{:02}-{:02}-{:02}_{:02}:{:02}:{:02}", now.year(), now.month(), now.day(), now.hour(), now.minute(), now.second(), ) From 98909ff51fb1477aa35ca8a9c8d98c1c3f2e9505 Mon Sep 17 00:00:00 2001 From: Satu Koskinen Date: Sat, 22 Oct 2022 14:40:41 +0300 Subject: [PATCH 2/4] Fix exporting config values, exit on error & print all commands in setup scripts --- configuration/setup-raspberry-pi.sh | 2 +- scripts/export-config-values.sh | 2 +- scripts/setup-audio.sh | 2 ++ scripts/setup-gps.sh | 5 +++-- scripts/setup-pressure-depth.sh | 2 ++ 5 files changed, 9 insertions(+), 4 deletions(-) diff --git a/configuration/setup-raspberry-pi.sh b/configuration/setup-raspberry-pi.sh index 85e71f6..d9c0867 100644 --- a/configuration/setup-raspberry-pi.sh +++ b/configuration/setup-raspberry-pi.sh @@ -27,7 +27,7 @@ echo echo "### Install some developer tools" echo -sudo apt-get update && sudo apt-get install -y build-essential +sudo apt-get update && sudo apt-get install -y build-essential python3-pip # Setup audio echo diff --git a/scripts/export-config-values.sh b/scripts/export-config-values.sh index 8b397a8..9b7b58a 100644 --- a/scripts/export-config-values.sh +++ b/scripts/export-config-values.sh @@ -1,5 +1,5 @@ #!/bin/bash -CONFIG_FILE=$1 +CONFIG_FILE=/boot/hydrophonitor/configuration/hydrophonitor-config.txt export $(grep -v '^#' $CONFIG_FILE | tr -d '[:space:]' | xargs -d '\n') diff --git a/scripts/setup-audio.sh b/scripts/setup-audio.sh index 7fea15c..99d41f1 100755 --- a/scripts/setup-audio.sh +++ b/scripts/setup-audio.sh @@ -1,5 +1,7 @@ #!/bin/bash +set -ex + echo "Setting up audio recording" # Install packages diff --git a/scripts/setup-gps.sh b/scripts/setup-gps.sh index 81258d9..af7bff2 100755 --- a/scripts/setup-gps.sh +++ b/scripts/setup-gps.sh @@ -1,9 +1,10 @@ #!/bin/sh +set -ex + echo "Setting up GPS recording" -sudo apt-get update && sudo apt-get install -y \ - gpsd gpsd-clients +sudo apt-get update && sudo apt-get install -y gpsd gpsd-clients sudo pip install -r /home/pi/hydrophonitor/gps-logger/requirements.txt diff --git a/scripts/setup-pressure-depth.sh b/scripts/setup-pressure-depth.sh index eeacb8e..fb71a78 100644 --- a/scripts/setup-pressure-depth.sh +++ b/scripts/setup-pressure-depth.sh @@ -1,5 +1,7 @@ #!/bin/sh +set -ex + echo "Setting up depth recording" # Enable i2c bus on Raspberry Pi From acb215966492addad8df871e29cf8989ee241530 Mon Sep 17 00:00:00 2001 From: Satu Koskinen Date: Sat, 22 Oct 2022 14:41:10 +0300 Subject: [PATCH 3/4] Add scripts for setting up RTC module --- scripts/setup-rtc-1.sh | 28 ++++++++++++++++++++++++++++ scripts/setup-rtc-2.sh | 35 +++++++++++++++++++++++++++++++++++ setup.md | 25 +++++++++++++++++++++++-- 3 files changed, 86 insertions(+), 2 deletions(-) create mode 100644 scripts/setup-rtc-1.sh create mode 100644 scripts/setup-rtc-2.sh diff --git a/scripts/setup-rtc-1.sh b/scripts/setup-rtc-1.sh new file mode 100644 index 0000000..3969dc4 --- /dev/null +++ b/scripts/setup-rtc-1.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +set -x + +echo "Setting up the real time clock module, part 1" + +# Enable i2c rtc on bus 3, set GPIO pins sda=23 and sdl=24 +sudo cat << EOF | sudo tee -a /boot/config.txt +dtoverlay=i2c-gpio,bus=3,i2c_gpio_delay_us=1,i2c_gpio_sda=23,i2c_gpio_scl=24 +dtoverlay=i2c-rtc,ds3231 +EOF + +# Disable fake-hwclock +sudo apt-get remove fake-hwclock +sudo update-rc.d -f fake-hwclock remove +sudo systemctl disable fake-hwclock + +# Load modules at boot +sudo cat << EOF | sudo tee -a /etc/modules +i2c-bcm2708 +i2c-dev +rtc-ds1307 +EOF + +# Remove some lines from /lib/udev/hwclock-set +sudo sed -i '/^if \[ \-e \/run\/systemd\/system \] ; then$/,/^fi$/d' /lib/udev/hwclock-set + +echo "Setup RTC part 1 done, reboot and run setup-rtc-2.sh" \ No newline at end of file diff --git a/scripts/setup-rtc-2.sh b/scripts/setup-rtc-2.sh new file mode 100644 index 0000000..767636b --- /dev/null +++ b/scripts/setup-rtc-2.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +set -x + +echo "Setting up the real time clock module, part 2" + +echo ds1307 0x68 | sudo tee /sys/class/i2c-adapter/i2c-3/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-3/new_device +sudo hwclock -s +exit 0 +EOF + +# Set system time to Internet time + +echo "Restarting systmd-timesyncd to update system time" + +sudo systemctl restart systemd-timesyncd + +echo "System time now:" +date + +# Write system time to the RTC module + +echo "Hardware clock time now:" +sudo hwclock -r + +echo "Writing system time to hardware clock" +sudo hwclock -w + +echo "Hardware clock time now:" +sudo hwclock -r diff --git a/setup.md b/setup.md index d6ac351..821697c 100755 --- a/setup.md +++ b/setup.md @@ -123,11 +123,32 @@ sudo reboot This will restart the Raspberry Pi and apply the changes made in the setup. On startup, it should now start recording audio, GPS and depth data. -### 3. Configuration options +### 3. Set up the real time clock module + +There are two scripts that configure the Raspberry Pi to read its system time from the RTC module. + +The first part enables the i2c interface (bus 3 with SDA at GPIO pin 23 and SCL at GPIO pin 24) and loads the needed hardware modules at boot. After that, a reboot is needed to enable the hardware interface. The second part updates the hardware clock module time and configures the Raspberry Pi to set the hardware clock time as the system time on startup. + +Connect to the Raspberry Pi over ssh and navigate to the home directory: + +``` +ssh pi@ +cd $HOME +sh hydrophonitor/scripts/setup-rtc-1.sh +sudo reboot +``` + +``` +ssh pi@ +cd $HOME +sh hydrophonitor/scripts/setup-rtc-2.sh +``` + +### 4. Configuration options todo -### 4. Mount SSD +### 5. Mount SSD todo From d38fd87f1744b87afd752fd4cd9c09d487dac594 Mon Sep 17 00:00:00 2001 From: Satu Koskinen Date: Sat, 22 Oct 2022 14:41:27 +0300 Subject: [PATCH 4/4] Print all executed commands in start scripts --- scripts/start-audio.sh | 2 ++ scripts/start-gps.sh | 2 ++ scripts/start-pressure-depth.sh | 2 ++ 3 files changed, 6 insertions(+) diff --git a/scripts/start-audio.sh b/scripts/start-audio.sh index 4af6078..8484151 100755 --- a/scripts/start-audio.sh +++ b/scripts/start-audio.sh @@ -1,5 +1,7 @@ #!/bin/bash +set -x + # Export the configuration values /home/pi/hydrophonitor/scripts/export-config-values.sh diff --git a/scripts/start-gps.sh b/scripts/start-gps.sh index f8a4a19..34c4ec0 100755 --- a/scripts/start-gps.sh +++ b/scripts/start-gps.sh @@ -1,5 +1,7 @@ #!/bin/bash +set -x + # Export the configuration values /home/pi/hydrophonitor/scripts/export-config-values.sh diff --git a/scripts/start-pressure-depth.sh b/scripts/start-pressure-depth.sh index 5c29960..72feb75 100644 --- a/scripts/start-pressure-depth.sh +++ b/scripts/start-pressure-depth.sh @@ -1,5 +1,7 @@ #!/bin/bash +set -x + # Export the configuration values /home/pi/hydrophonitor/scripts/export-config-values.sh