Skip to content

Commit

Permalink
Move Scripts and Clean Up Calling Functions
Browse files Browse the repository at this point in the history
First step of moving a mass number of scripts in an effort to get some
order around the organization.
  • Loading branch information
jekhokie committed Jan 28, 2021
1 parent 7350ef3 commit 3d5808b
Show file tree
Hide file tree
Showing 18 changed files with 32 additions and 180 deletions.
49 changes: 0 additions & 49 deletions check.sh

This file was deleted.

File renamed without changes.
2 changes: 1 addition & 1 deletion docs/INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ sudo cp -rp templates/webpanel/* /var/www/wx/

### Setup Database
```
sqlite3 "panel.db" < "templates/webpanel_schema.sql"
sqlite3 db/panel.db < templates/webpanel_schema.sql
```

### Setup RamFS
Expand Down
2 changes: 1 addition & 1 deletion docs/METEOR.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ Currently, the satellite is using 137.1Mhz as the center frequency, Wide-FM @ 12
2. Use dbdexter's [meteor_demod](https://github.com/dbdexter-dev/meteor_demod) to convert the audio stream to QPSK symbols at a 72k rate
3. Use artlav's [medet_arm](https://github.com/artlav/meteor_decoder) to generate a decoded dump and then a false color image
4. Use dbdexter's [meteor_rectify](https://github.com/dbdexter-dev/meteor_rectify) to correct the visible deformation on Meteor images (wrong aspect ratio)
1. I made [some changes](rectify.py) to rectify to export to compressed JPG and remove some prints
1. I made [some changes](scripts/rectify.py) to rectify to export to compressed JPG and remove some prints
10 changes: 5 additions & 5 deletions docs/WORKING.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
![Raspberry NOAA](../assets/header_1600.png)

# Reception
First thing we need to test is reception. It's the way to be sure the antenna, reception line, reception hardware and software are working properly. There is a [test_reception.sh](test_reception.sh) script that makes testing easy, just tune a broadcast FM near you and listen to the audio, then make the proper adjustments to improve reception.
First thing we need to test is reception. It's the way to be sure the antenna, reception line, reception hardware and software are working properly. There is a [test_reception.sh](scripts/test_reception.sh) script that makes testing easy, just tune a broadcast FM near you and listen to the audio, then make the proper adjustments to improve reception.

Open a SSH connection to your Raspberry PI and execute `test_reception.sh <tune frequency>`.
Open a SSH connection to your Raspberry PI and execute `./scripts/test_reception.sh <tune frequency>`.

```bash
cd raspberry-noaa-v2/
./test_reception.sh 90.3
./scripts/test_reception.sh 90.3
```

Now open a terminal on your Linux/Mac/(And maybe windows?) computer and run
Expand Down Expand Up @@ -36,8 +36,8 @@ Will show the scheduled jobs for today, each job can be described using `at -c <
Images are saved in the web server's directory, so you can access your received images at http://your.raspberry.pi.ip/, where `your.raspberry.pi.ip` is your Raspberry PI IP address.

# Pruning
Run `prune.sh` to delete old images. By default it deletes the 10 oldest images from the disk and the database. If you want to schedule this task, run
Run `./scripts/prune.sh` to delete old images. By default it deletes the 10 oldest images from the disk and the database. If you want to schedule this task, run

```bash
cat <(crontab -l) <(echo "1 0 * * * /home/pi/raspberry-noaa-v2/prune.sh") | crontab -
cat <(crontab -l) <(echo "1 0 * * * /home/pi/raspberry-noaa-v2/scripts/prune.sh") | crontab -
```
4 changes: 2 additions & 2 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ sudo python3 -m pip install numpy ephem tweepy Pillow
log_done "Packages installed"

### Create the database schema
if [ -e "$HOME/raspberry-noaa-v2/panel.db" ]; then
if [ -e "$HOME/raspberry-noaa-v2/db/panel.db" ]; then
log_done "Database already created"
else
sqlite3 "panel.db" < "templates/webpanel_schema.sql"
sqlite3 db/panel.db < templates/webpanel_schema.sql
log_done "Database schema created"
fi

Expand Down
100 changes: 0 additions & 100 deletions migrate_data.sh

This file was deleted.

12 changes: 6 additions & 6 deletions migrations/20201292-iss.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ if [ -f "$NOAA_HOME/demod.py" ]; then
exit 1
fi

if [ ! -f "$NOAA_HOME/panel.db" ]; then
log "Seems like there's no panel.db database in your project folder" "ERROR"
if [ ! -f "$DB_HOME/panel.db" ]; then
log "Seems like there's no db/panel.db database in your project folder" "ERROR"
exit 1
fi

Expand All @@ -26,19 +26,19 @@ STEPS="6"
datetime=$(date +"%Y%m%d-%H%M%S")

log "1/$STEPS: Backing up database" "INFO"
cp "$NOAA_HOME/panel.db" "$NOAA_HOME/panel.db.bak-$datetime"
cp "$DB_HOME/panel.db" "$DB_HOME/panel.db.bak-$datetime"
log "1/$STEPS: Database backup done: panel.db.bak-$datetime" "INFO"

log "2/$STEPS: Creating new columns" "INFO"
set +e
sqlite3 "$NOAA_HOME/panel.db" "alter table decoded_passes add column img_count integer;"
sqlite3 "$NOAA_HOME/panel.db" "alter table decoded_passes add column sat_type integer;"
sqlite3 "$DB_HOME/panel.db" "alter table decoded_passes add column img_count integer;"
sqlite3 "$DB_HOME/panel.db" "alter table decoded_passes add column sat_type integer;"
set -e
log "2/$STEPS: img_count and sat_type columns created" "INFO"


log "3/$STEPS: Migrating is_noaa column" "INFO"
sqlite3 "$NOAA_HOME/panel.db" "update decoded_passes set sat_type = is_noaa;"
sqlite3 "$DB_HOME/panel.db" "update decoded_passes set sat_type = is_noaa;"
log "3/$STEPS: is_noaa column migration done" "INFO"


Expand Down
8 changes: 4 additions & 4 deletions receive.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ done
rm "${NOAA_HOME}/map/${3}-map.png"

if [ "${SUN_ELEV}" -gt "${SUN_MIN_ELEV}" ]; then
sqlite3 $NOAA_HOME/panel.db "insert into decoded_passes (pass_start, file_path, daylight_pass, sat_type) values ($5,\"$3\", 1,1);"
sqlite3 $DB_HOME/panel.db "insert into decoded_passes (pass_start, file_path, daylight_pass, sat_type) values ($5,\"$3\", 1,1);"
else
sqlite3 $NOAA_HOME/panel.db "insert into decoded_passes (pass_start, file_path, daylight_pass, sat_type) values ($5,\"$3\", 0,1);"
sqlite3 $DB_HOME/panel.db "insert into decoded_passes (pass_start, file_path, daylight_pass, sat_type) values ($5,\"$3\", 0,1);"
fi

pass_id=$(sqlite3 $NOAA_HOME/panel.db "select id from decoded_passes order by id desc limit 1;")
pass_id=$(sqlite3 $DB_HOME/panel.db "select id from decoded_passes order by id desc limit 1;")

if [ -n "$CONSUMER_KEY" ]; then
log "Posting to Twitter" "INFO"
Expand All @@ -69,7 +69,7 @@ if [ -n "$CONSUMER_KEY" ]; then
fi
fi

sqlite3 $NOAA_HOME/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);"
sqlite3 $DB_HOME/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);"

if [ "$DELETE_AUDIO" = true ]; then
log "Deleting audio files" "INFO"
Expand Down
6 changes: 3 additions & 3 deletions receive_iss.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ if [ -f "$NOAA_HOME/demod.py" ]; then

if [ "$img_count" -gt 0 ]; then
/usr/bin/convert -thumbnail 300 "${NOAA_OUTPUT}/images/${3}-0.png" "${NOAA_OUTPUT}/images/thumb/${3}-0.png"
sqlite3 "$NOAA_HOME/panel.db" "insert into decoded_passes (pass_start, file_path, daylight_pass, sat_type, img_count) values ($5,\"$3\",1,2,$img_count);"
pass_id=$(sqlite3 "$NOAA_HOME/panel.db" "select id from decoded_passes order by id desc limit 1;")
sqlite3 "$DB_HOME/panel.db" "insert into decoded_passes (pass_start, file_path, daylight_pass, sat_type, img_count) values ($5,\"$3\",1,2,$img_count);"
pass_id=$(sqlite3 "$DB_HOME/panel.db" "select id from decoded_passes order by id desc limit 1;")
if [ -n "$CONSUMER_KEY" ]; then
log "Posting to Twitter" "INFO"
if [ "$img_count" -eq 1 ]; then
Expand All @@ -51,6 +51,6 @@ if [ -f "$NOAA_HOME/demod.py" ]; then
python3 "${NOAA_HOME}/post.py" "$1 ${START_DATE} Mas imagenes: https://weather.reyni.co/detail.php?id=$pass_id" "$7" "${NOAA_OUTPUT}/images/${3}-0.png" "${NOAA_OUTPUT}/images/${3}-1.png"
fi
fi
sqlite3 "$NOAA_HOME/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);"
sqlite3 "$DB_HOME/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
fi
8 changes: 4 additions & 4 deletions receive_meteor.sh
Original file line number Diff line number Diff line change
Expand Up @@ -75,20 +75,20 @@ if [ -f "${METEOR_OUTPUT}/${3}.dec" ]; then
fi

log "Rectifying image to adjust aspect ratio" "INFO"
python3 "${NOAA_HOME}/rectify.py" "${NOAA_OUTPUT}/images/${3}-122.bmp"
python3 "${NOAA_HOME}/scripts/rectify.py" "${NOAA_OUTPUT}/images/${3}-122.bmp"
convert "${NOAA_OUTPUT}/images/${3}-122-rectified.jpg" -channel rgb -normalize -undercolor black -fill yellow -pointsize 60 -annotate +20+60 "${1} ${START_DATE} Elev: $7°" "${NOAA_OUTPUT}/images/${3}-122-rectified.jpg"
/usr/bin/convert -thumbnail 300 "${NOAA_OUTPUT}/images/${3}-122-rectified.jpg" "${NOAA_OUTPUT}/images/thumb/${3}-122-rectified.jpg"
rm "${NOAA_OUTPUT}/images/${3}-122.bmp"
rm "${METEOR_OUTPUT}/${3}.bmp"
rm "${METEOR_OUTPUT}/${3}.dec"

sqlite3 $NOAA_HOME/panel.db "insert into decoded_passes (pass_start, file_path, daylight_pass, sat_type) values ($5,\"$3\", 1,0);"
pass_id=$(sqlite3 $NOAA_HOME/panel.db "select id from decoded_passes order by id desc limit 1;")
sqlite3 $DB_HOME/panel.db "insert into decoded_passes (pass_start, file_path, daylight_pass, sat_type) values ($5,\"$3\", 1,0);"
pass_id=$(sqlite3 $DB_HOME/panel.db "select id from decoded_passes order by id desc limit 1;")
if [ -n "$CONSUMER_KEY" ]; then
log "Posting to Twitter" "INFO"
python3 "${NOAA_HOME}/post.py" "$1 ${START_DATE} Resolución completa: https://weather.reyni.co/detail.php?id=$pass_id" "$7" "${NOAA_OUTPUT}/images/${3}-122-rectified.jpg"
fi
sqlite3 $NOAA_HOME/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);"
sqlite3 $DB_HOME/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);"
else
log "Decoding failed, either a bad pass/low SNR or a software problem" "ERROR"
fi
2 changes: 1 addition & 1 deletion schedule_iss.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,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 $NOAA_HOME/panel.db "insert or replace into predict_passes (sat_name,pass_start,pass_end,max_elev,is_active) values (\"$SATNAME\",$var1,$var2,$MAXELEV,1);"
sqlite3 $DB_HOME/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)
Expand Down
2 changes: 1 addition & 1 deletion schedule_meteor.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ while [ "$(date --date="@${var2}" +%D)" = "$(date +%D)" ]; do
echo "${SATNAME}" "${OUTDATE}" "$MAXELEV"
echo "${NOAA_HOME}/receive_meteor.sh \"${1}\" $2 ${SATNAME}${OUTDATE} "${NOAA_HOME}"/predict/weather.tle \
${var1} ${TIMER} ${MAXELEV}" | at "$(date --date="TZ=\"UTC\" ${START_TIME}" +"%H:%M %D")"
sqlite3 $NOAA_HOME/panel.db "insert or replace into predict_passes (sat_name,pass_start,pass_end,max_elev,is_active) values (\"$SATNAME\",$var1,$var2,$MAXELEV,1);"
sqlite3 $DB_HOME/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/weather.tle -p "${1}" "${NEXTPREDICT}" | head -1)
Expand Down
2 changes: 1 addition & 1 deletion schedule_sat.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ while [ "$(date --date="@${var2}" +%D)" = "$(date +%D)" ]; do
echo "${SATNAME}" "${OUTDATE}" "$MAXELEV"
echo "${NOAA_HOME}/receive.sh \"${1}\" $2 ${SATNAME}${OUTDATE} "${NOAA_HOME}"/predict/weather.tle \
${var1} ${TIMER} ${MAXELEV}" | at "$(date --date="TZ=\"UTC\" ${START_TIME}" +"%H:%M %D")"
sqlite3 $NOAA_HOME/panel.db "insert or replace into predict_passes (sat_name,pass_start,pass_end,max_elev,is_active) values (\"$SATNAME\",$var1,$var2,$MAXELEV, 1);"
sqlite3 $DB_HOME/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/weather.tle -p "${1}" "${NEXTPREDICT}" | head -1)
Expand Down
4 changes: 2 additions & 2 deletions prune.sh → scripts/prune.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
. "$HOME/.noaa.conf"
. "$NOAA_HOME/common.sh"

for img_path in $(sqlite3 ${NOAA_HOME}/panel.db "select file_path from decoded_passes limit 10;"); do
for img_path in $(sqlite3 ${DB_HOME}/panel.db "select file_path from decoded_passes limit 10;"); do
find "${NOAA_OUTPUT}/images/" -type f -name "${IMG_NAME}*.jpg" -exec rm -f {} \;
find "${NOAA_OUTPUT}/images/thumb/" -type f -name "${IMG_NAME}*.jpg" -exec rm -f {} \;
log "${img_path} file pruned" "INFO"
sqlite3 "${NOAA_HOME}/panel.db" "delete from decoded_passes where file_path = \"$img_path\";"
sqlite3 "${DB_HOME}/panel.db" "delete from decoded_passes where file_path = \"$img_path\";"
log "Database entry pruned" "INFO"
done
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions templates/noaa.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
NOAA_HOME=/home/pi/raspberry-noaa-v2
DB_HOME=$NOAA_HOME/db
NOAA_OUTPUT=/var/www/wx-new/public
METEOR_OUTPUT=/var/www/wx-new/public/meteor
RAMFS_AUDIO=/var/ramfs
Expand Down

0 comments on commit 3d5808b

Please sign in to comment.