From 5a807d58e485eafe12c5ea8724d42dfcaad93a1f Mon Sep 17 00:00:00 2001 From: Nico Rey Date: Tue, 29 Dec 2020 17:43:07 -0300 Subject: [PATCH 01/23] add migrations --- migrations/20201292-iss.sh | 46 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 migrations/20201292-iss.sh diff --git a/migrations/20201292-iss.sh b/migrations/20201292-iss.sh new file mode 100644 index 0000000..df48f31 --- /dev/null +++ b/migrations/20201292-iss.sh @@ -0,0 +1,46 @@ +#!/bin/bash +set -e + +### Run as a normal user +if [ $EUID -eq 0 ]; then + echo "This script shouldn't be run as root." + exit 1 +fi + +## import common lib +. "$HOME/.noaa.conf" +. "$NOAA_HOME/common.sh" + +datetime=$(date +"%Y%m%d-%H%M%S") + +log "1/3: Backing up database" "INFO" +cp "/home/pi/raspberry-noaa/panel.db" "/home/pi/raspberry-noaa/panel.db.bak-$datetime" +log "1/3: Database backup done: panel.db.bak-$datetime" "INFO" + +log "2/3: Creating new columns" "INFO" +set +e +sqlite3 /home/pi/raspberry-noaa/panel.db "alter table decoded_passes add column img_count integer;" +sqlite3 /home/pi/raspberry-noaa/panel.db "alter table decoded_passes add column sat_type integer;" +set -e +log "2/3: img_count and sat_type columns created" "INFO" + + +log "3/3: Migrating is_noaa column" "INFO" +sqlite3 /home/pi/raspberry-noaa/panel.db "update decoded_passes set sat_type = is_noaa;" +log "3/3: is_noaa column migration done" "INFO" + + +log "4/3: Setting up SCHEDULE_ISS on .noaa.conf" "INFO" +set +e +if ! grep -q SCHEDULE_ISS /home/pi/.noaa.conf; then + echo "SCHEDULE_ISS=\"false\"" >> /home/pi/.noaa.conf + log "4/3: SCHEDULE_ISS is set now on .noaa.conf" "INFO" +else + log "4/3: SCHEDULE_ISS was already set on .noaa.conf" "INFO" +fi +set -e + +log "3/3: Updating PHP files" "INFO" +sudo cp templates/webpanel/Model/Conn.php /var/www/wx/Model/Conn.php +sudo cp templates/webpanel/Views/V_viewLastImages.php /var/www/wx/Views/V_viewLastImages.php +log "3/3: PHP files updated" "INFO" From d60e7bfaf0041d6ce8da875bf19207bc75233483 Mon Sep 17 00:00:00 2001 From: Nico Rey Date: Tue, 29 Dec 2020 17:43:37 -0300 Subject: [PATCH 02/23] add receive iss --- receive.sh | 4 +- receive_iss.sh | 45 +++++++++++++++++-- receive_meteor.sh | 2 +- schedule.sh | 13 +++--- schedule_iss.sh | 1 + templates/noaa.conf | 1 + templates/webpanel/Model/Conn.php | 21 ++++----- templates/webpanel/Views/V_viewLastImages.php | 9 ++-- templates/webpanel_schema.sql | 2 +- 9 files changed, 70 insertions(+), 28 deletions(-) diff --git a/receive.sh b/receive.sh index 3ae1d01..2b23d4b 100755 --- a/receive.sh +++ b/receive.sh @@ -53,9 +53,9 @@ done rm "${NOAA_HOME}/map/${3}-map.png" if [ "${SUN_ELEV}" -gt "${SUN_MIN_ELEV}" ]; then - sqlite3 /home/pi/raspberry-noaa/panel.db "insert into decoded_passes (pass_start, file_path, daylight_pass, is_noaa) values ($5,\"$3\", 1,1);" + sqlite3 /home/pi/raspberry-noaa/panel.db "insert into decoded_passes (pass_start, file_path, daylight_pass, sat_type) values ($5,\"$3\", 1,1);" else - sqlite3 /home/pi/raspberry-noaa/panel.db "insert into decoded_passes (pass_start, file_path, daylight_pass, is_noaa) values ($5,\"$3\", 0,1);" + sqlite3 /home/pi/raspberry-noaa/panel.db "insert into decoded_passes (pass_start, file_path, daylight_pass, sat_type) values ($5,\"$3\", 0,1);" fi pass_id=$(sqlite3 /home/pi/raspberry-noaa/panel.db "select id from decoded_passes order by id desc limit 1;") diff --git a/receive_iss.sh b/receive_iss.sh index f384b48..922c919 100755 --- a/receive_iss.sh +++ b/receive_iss.sh @@ -1,3 +1,42 @@ -#!/bin/sh -datetime=$(date +"%Y%m%d-%H%M%S") -timeout 660 /usr/local/bin/rtl_fm -M fm -f 145.8M -s 48k -g $GAIN -p 55 -E wav -E deemp -F 9 - | /usr/bin/sox -t raw -e signed -c 1 -b 16 -r 48000 - /usr/share/html/iss/iss-$datetime.wav rate 11025 +#!/bin/bash + +### Run as a normal user +if [ $EUID -eq 0 ]; then + echo "This script shouldn't be run as root." + exit 1 +fi + +## import common lib +. "$HOME/.noaa.conf" +. "$HOME/.tweepy.conf" +. "$NOAA_HOME/common.sh" + +if pgrep "rtl_fm" > /dev/null +then + log "There is an already running rtl_fm instance but I dont care for now, I prefer this pass" "INFO" + pkill -9 -f rtl_fm +fi + +# $1 = Satellite Name +# $2 = Frequency +# $3 = FileName base +# $4 = TLE File +# $5 = EPOC start time +# $6 = Time to capture +# $7 = Satellite max elevation + +log "Starting rtl_fm record" "INFO" +timeout "${6}" /usr/local/bin/rtl_fm ${BIAS_TEE} -M fm -f 145.8M -s 48k -g $GAIN -E dc -E wav -E deemp -F 9 - | sox -t raw -r 48k -c 1 -b 16 -e s - -t wav "${NOAA_OUTPUT}/audio/${3}.wav" rate 11025 + +if [ -f "/home/pi/raspberry-noaa/demod.py" ]; then + log "Decoding ISS pass" "INFO" + python3 /home/pi/raspberry-noaa/demod.py "${NOAA_OUTPUT}/audio/${3}.wav" "${NOAA_OUTPUT}/images/" + decoded_pictures="$(find ${NOAA_OUTPUT}/images/ -iname "${3}*png")" + img_count=0 + for image in $decoded_pictures; do + ((img_count++)) + done + sqlite3 /home/pi/raspberry-noaa/panel.db "insert into decoded_passes (pass_start, file_path, daylight_pass, sat_type, img_count) values ($5,\"$3\", 1,0, 2, $img_count);" + pass_id=$(sqlite3 /home/pi/raspberry-noaa/panel.db "select id from decoded_passes order by id desc limit 1;") + sqlite3 /home/pi/raspberry-noaa/panel.db "update predict_passes set is_active = 0 where (predict_passes.pass_start) in (select predict_passes.pass_start from predict_passes inner join decoded_passes on predict_passes.pass_start = decoded_passes.pass_start where decoded_passes.id = $pass_id);" +fi diff --git a/receive_meteor.sh b/receive_meteor.sh index 626a4d6..a6dbb11 100755 --- a/receive_meteor.sh +++ b/receive_meteor.sh @@ -82,7 +82,7 @@ if [ -f "${METEOR_OUTPUT}/${3}.dec" ]; then rm "${METEOR_OUTPUT}/${3}.bmp" rm "${METEOR_OUTPUT}/${3}.dec" - sqlite3 /home/pi/raspberry-noaa/panel.db "insert into decoded_passes (pass_start, file_path, daylight_pass, is_noaa) values ($5,\"$3\", 1,0);" + sqlite3 /home/pi/raspberry-noaa/panel.db "insert into decoded_passes (pass_start, file_path, daylight_pass, sat_type) values ($5,\"$3\", 1,0);" pass_id=$(sqlite3 /home/pi/raspberry-noaa/panel.db "select id from decoded_passes order by id desc limit 1;") if [ -n "$CONSUMER_KEY" ]; then log "Posting to Twitter" "INFO" diff --git a/schedule.sh b/schedule.sh index ed957fe..c078f42 100755 --- a/schedule.sh +++ b/schedule.sh @@ -10,24 +10,23 @@ fi . "$HOME/.noaa.conf" . "$NOAA_HOME/common.sh" -### Run as a normal user -if [ $EUID -eq 0 ]; then - die "This script shouldn't be run as root." -fi - wget -qr http://www.celestrak.com/NORAD/elements/weather.txt -O "${NOAA_HOME}"/predict/weather.txt wget -qr http://www.celestrak.com/NORAD/elements/amateur.txt -O "${NOAA_HOME}"/predict/amateur.txt grep "NOAA 15" "${NOAA_HOME}"/predict/weather.txt -A 2 > "${NOAA_HOME}"/predict/weather.tle grep "NOAA 18" "${NOAA_HOME}"/predict/weather.txt -A 2 >> "${NOAA_HOME}"/predict/weather.tle grep "NOAA 19" "${NOAA_HOME}"/predict/weather.txt -A 2 >> "${NOAA_HOME}"/predict/weather.tle grep "METEOR-M 2" "${NOAA_HOME}"/predict/weather.txt -A 2 >> "${NOAA_HOME}"/predict/weather.tle -# grep "ZARYA" "${NOAA_HOME}"/predict/amateur.txt -A 2 > "${NOAA_HOME}"/predict/amateur.tle +if [ "$SCHEDULE_ISS" == "true" ]; then + grep "ZARYA" "${NOAA_HOME}"/predict/amateur.txt -A 2 > "${NOAA_HOME}"/predict/amateur.tle +fi #Remove all AT jobs for i in $(atq | awk '{print $1}');do atrm "$i";done #Schedule Satellite Passes: -#"${NOAA_HOME}"/schedule_iss.sh "ISS (ZARYA)" 145.8000 +if [ "$SCHEDULE_ISS" == "true" ]; then + "${NOAA_HOME}"/schedule_iss.sh "ISS (ZARYA)" 145.8000 +fi "${NOAA_HOME}"/schedule_meteor.sh "METEOR-M 2" 137.1000 "${NOAA_HOME}"/schedule_sat.sh "NOAA 19" 137.1000 "${NOAA_HOME}"/schedule_sat.sh "NOAA 18" 137.9125 diff --git a/schedule_iss.sh b/schedule_iss.sh index 9e7bb16..e42a6fa 100755 --- a/schedule_iss.sh +++ b/schedule_iss.sh @@ -33,6 +33,7 @@ while [ "$(date --date="@${var2}" +%D)" = "$(date +%D)" ]; do echo ${SATNAME} "${OUTDATE}" "$MAXELEV" echo "${NOAA_HOME}/receive_iss.sh \"${1}\" $2 ISS${OUTDATE} "${NOAA_HOME}"/predict/amateur.tle \ ${var1} ${TIMER} ${MAXELEV}" | at "$(date --date="TZ=\"UTC\" ${START_TIME}" +"%H:%M %D")" + sqlite3 /home/pi/raspberry-noaa/panel.db "insert or replace into predict_passes (sat_name,pass_start,pass_end,max_elev,is_active) values (\"$SATNAME\",$var1,$var2,$MAXELEV,1);" fi NEXTPREDICT=$(expr "${var2}" + 60) PREDICTION_START=$(/usr/bin/predict -t "${NOAA_HOME}"/predict/amateur.tle -p "${1}" "${NEXTPREDICT}" | head -1) diff --git a/templates/noaa.conf b/templates/noaa.conf index 0aca872..2e1618b 100644 --- a/templates/noaa.conf +++ b/templates/noaa.conf @@ -12,3 +12,4 @@ BIAS_TEE="enable_bias_tee" DELETE_AUDIO="true" FLIP_METEOR_IMG="true" GAIN=50 +SCHEDULE_ISS="true" diff --git a/templates/webpanel/Model/Conn.php b/templates/webpanel/Model/Conn.php index b60fb51..f6c522e 100644 --- a/templates/webpanel/Model/Conn.php +++ b/templates/webpanel/Model/Conn.php @@ -28,7 +28,7 @@ public function getImages($page, $img_per_page) { $query = $this->con->prepare("SELECT decoded_passes.id, predict_passes.pass_start, - file_path, is_noaa, predict_passes.sat_name, predict_passes.max_elev + file_path, sat_type, predict_passes.sat_name, predict_passes.max_elev FROM decoded_passes INNER JOIN predict_passes ON predict_passes.pass_start = decoded_passes.pass_start ORDER BY decoded_passes.pass_start DESC LIMIT ? OFFSET ?;"); @@ -45,19 +45,20 @@ } public function getEnhacements($id) { - $query = $this->con->prepare('SELECT daylight_pass, is_noaa + $query = $this->con->prepare('SELECT daylight_pass, sat_type FROM decoded_passes WHERE id = ?;'); $query->bindValue(1, $id); $result = $query->execute(); $pass = $result->fetchArray(); - if ($pass['is_noaa'] == 0) { - $enhacements = ['-122-rectified.jpg']; - } else { - if ($pass['daylight_pass'] == 1) { - $enhacements = ['-ZA.jpg','-MCIR.jpg','-MCIR-precip.jpg','-MSA.jpg','-MSA-precip.jpg','-HVC.jpg','-HVC-precip.jpg','-HVCT.jpg','-HVCT-precip.jpg']; - } else { - $enhacements = ['-ZA.jpg','-MCIR.jpg','-MCIR-precip.jpg']; - } + switch($pass['sat_type']) { + case 0: + $ending = "-122-rectified.jpg"; + case 1: + if ($pass['daylight_pass'] == 1) { + $enhacements = ['-ZA.jpg','-MCIR.jpg','-MCIR-precip.jpg','-MSA.jpg','-MSA-precip.jpg','-HVC.jpg','-HVC-precip.jpg','-HVCT.jpg','-HVCT-precip.jpg']; + } else { + $enhacements = ['-ZA.jpg','-MCIR.jpg','-MCIR-precip.jpg']; + } } return $enhacements; } diff --git a/templates/webpanel/Views/V_viewLastImages.php b/templates/webpanel/Views/V_viewLastImages.php index c17d4bb..08a5a90 100644 --- a/templates/webpanel/Views/V_viewLastImages.php +++ b/templates/webpanel/Views/V_viewLastImages.php @@ -20,10 +20,11 @@ echo ""; $col_count=1; } - if ($image['is_noaa'] == true) { - $ending = "-MCIR.jpg"; - } else { - $ending = "-122-rectified.jpg"; + switch($image['sat_type']) { + case 0: + $ending = "-122-rectified.jpg"; + case 1: + $ending = "-MCIR.jpg"; } echo "
"; echo "