Modified "upload IQ files to Dropbox script" selecting satellites with linear transponders

I modified the script that @mfalkvidd made for uploading IQ files to dropbox, to allow me to save IQ files in a way that SDRsharp could play them back. I also didn’t want the files compressed, since only certain satellites were going to be saved in raw format. I really wish Satnogs would let you select which satellite passes you want IQ saved for, but until then, here is the script.

I am not a programmer, and would appreciate any help to streamline this script.
I posted it here for others to comment on, use, and improve. Please post any optimizations here.

#!/bin/bash
#############################################
#          KK4YEL                           #
# script to upload raw IQ files to proper   #
# format for use with SDRSharp program      #
# modified script based on one from user    #
# mfalkvidd https://bit.ly/3d12Hvl          # 
# thanks to skaflux and Mobilinkd           # 
#                                           #
#############################################
# remote is the name of the rclone remote instance 
RC_REMOTE=remote
# IQ_files is the name of the directory on Dropbox I want rclone to copy the raw IQ files to
DB_DIR=IQ_files
# the arguments passed into the post-observation script by satnogs are
# $1 is ID, $2 is FREQ, $3 is TLE, which is in JSON
# $4 is TIMESTAMP, $5 is BAUD, $6 is SCRIPT_NAME
# below are the NORAD IDs for the current (as of April 2020) satellites with linear transonders 
# found at https://www.amsat.org/linear-satellite-frequency-summary/
AO07="7530"
AO73="39444"
FO29="24278"
XW2A="40903"
XW2B="40911"
XW2D="40907"
XW2F="40910"
LO87="41557"
EO88="42017"
CAS4A="42761"
CAS4B="42759"
JO97="43803"
FO99="43937"
JAISAT1="44419"
CAS6="99823"
HUSKYSAT1="45119"
if [ -n "$IQ_DUMP_FILENAME" ] && [ -f "$IQ_DUMP_FILENAME" ]
then
   # this command gets the satellite name from the JSON TLE Object, replaces spaces with an underscore, and then 
   # gets rid of any character that is not alphanumeric a period or underscore or dash	
   SATNAME=$(echo "$3" | jq .tle0 | sed -e 's/ /_/g' | sed -e 's/[^A-Za-z0-9._-]//g')
   # this command gets the NORAD ID for the sat 
   NORAD_ID=$(echo "$3" | jq .tle1 | awk '{printf "%d", $2;}')
   # this command looks for a match. I am sure there is a more elegant way to do this
   if [[ $NORAD_ID -eq $AO07 ]] || [[ $NORAD_ID -eq $CAS6 ]] || [[ $NORAD_ID -eq $AO73 ]] || [[ $NORAD_ID -eq $FO29 ]] || [[ $NORAD_ID -eq $XW2A ]] || [[ $NORAD_ID -eq 
$XW2B ]] || [[ $NORAD_ID -eq $XW2D ]] || [[ $NORAD_ID -eq $XW2F ]] || [[ $NORAD_ID -eq $LO87 ]] || [[ $NORAD_ID -eq $EO88 ]] || [[ $NORAD_ID -eq $CAS4A ]] || [[ $NORAD_
ID -eq $CAS4B ]] || [[ $NORAD_ID -eq $JO97 ]] || [[ $NORAD_ID -eq $FO99 ]] || [[ $NORAD_ID -eq $JAISAT1 ]] || [[ $NORAD_ID -eq $HUSKYSAT1 ]]
   then 
   	IQ_DIR=$(dirname "${IQ_DUMP_FILENAME}")
   	IQ_NAME="$1"_"$SATNAME".wav
   	IQ_FILE="$IQ_DIR"/"$IQ_NAME"
	# sox complains unless the file ends in .wav
   	TEMPFILE=$(mktemp -p /tmp/.satnogs/ XXXXXXXX.wav)
	# the sox command formats the raw IQ file in the proper way for playback in SDRsharp
   	sox -t raw -b16 -e signed-integer -r 48000 -c 2 $IQ_DUMP_FILENAME $TEMPFILE
	mv "$TEMPFILE" "$IQ_FILE"
	# move the file from the RasPi SD card to Dropbox using rclone
   	rclone move "$IQ_FILE" "$RC_REMOTE:$DB_DIR"
   fi
fi
# next line turns off the bias T in the RTL-SDR UNO
/home/pi/rtl-sdr-blog/build/src/rtl_biast -b 0
2 Likes

Nice work.

Here is a slight modification, if you want a “cleaner” way to check the list of interesting satellites:

#!/bin/bash
#############################################
#          KK4YEL                           #
# script to upload raw IQ files to proper   #
# format for use with SDRSharp program      #
# modified script based on one from user    #
# mfalkvidd https://bit.ly/3d12Hvl          #
# thanks to skaflux and Mobilinkd           #
#                                           #
#############################################
# remote is the name of the rclone remote instance
RC_REMOTE=remote
# IQ_files is the name of the directory on Dropbox I want rclone to copy the raw IQ files to
DB_DIR=IQ_files
# the arguments passed into the post-observation script by satnogs are
# $1 is ID, $2 is FREQ, $3 is TLE, which is in JSON
# $4 is TIMESTAMP, $5 is BAUD, $6 is SCRIPT_NAME
# below are the NORAD IDs for the current (as of April 2020) satellites with linear transponders
# found at https://www.amsat.org/linear-satellite-frequency-summary/
if [ -n "$IQ_DUMP_FILENAME" ] && [ -f "$IQ_DUMP_FILENAME" ]
then
   # this command gets the satellite name from the JSON TLE Object, replaces spaces with an underscore, and then
   # gets rid of any character that is not alphanumeric a period or underscore or dash
   SATNAME=$(echo "$3" | jq .tle0 | sed -e 's/ /_/g' | sed -e 's/[^A-Za-z0-9._-]//g')
   # this command gets the NORAD ID for the sat
   NORAD_ID=$(echo "$3" | jq .tle1 | awk '{printf "%d", $2;}')
   # this command looks for a match.
   for SAT in $(cut -f1 -d'#' < /home/pi/interesting_satellites)
   do
      if [ "$NORAD_ID" == "$SAT" ]; then
         INTERESTING=true
         break
      fi
   done
   if [ "$INTERESTING" = true ]
   then
        IQ_DIR=$(dirname "${IQ_DUMP_FILENAME}")
        IQ_NAME="$1"_"$SATNAME".wav
        IQ_FILE="$IQ_DIR"/"$IQ_NAME"
        # sox complains unless the file ends in .wav
        TEMPFILE=$(mktemp -p /tmp/.satnogs/ XXXXXXXX.wav)
        # the sox command formats the raw IQ file in the proper way for playback in SDRsharp
        sox -t raw -b16 -e signed-integer -r 48000 -c 2 "$IQ_DUMP_FILENAME" "$TEMPFILE"
        mv "$TEMPFILE" "$IQ_FILE"
        # move the file from the RasPi SD card to Dropbox using rclone
        rclone move "$IQ_FILE" "$RC_REMOTE:$DB_DIR"
   fi
fi
# next line turns off the bias T in the RTL-SDR UNO
/home/pi/rtl-sdr-blog/build/src/rtl_biast -b 0

/home/pi/interesting_satellites could look like this:

7530 # AO07
39444 # AO73
24278 # FO29
40903 # XW2A
40911 # XW2B
40907 # XW2D
40910 # XW2F
41557 # LO87
42017 # EO88
42761 # CAS4A
42759 # CAS4B
43803 # JO97
43937 # FO99
44419 # JAISAT1
99823 # CAS6
45119 # HUSKYSAT1

(The # and the comment is not required, but might be useful when updating the file in the future)

I find the shellcheck tool (apt-get install shellcheck or www.shellcheck.net) useful when writing scripts.

3 Likes

Awesome!
Thank you very much.

1 Like