Weather satellites reception - first steps on Linux

Some years ago I had wxtoimg running on a Windows machine and receiving NOAA images automatically with an analogue receiver.

I found this interesting post on Instructables using a Raspberry Pi3 and an cheap RTL-SDR.

As I have still an old RaspberryB sitting on my workbench with an older Debian Linux, I give it a try.

Linux DEV-RASP 4.1.7-v7+ #817 SMP PREEMPT Sat Sep 19 15:32:00 BST 2015 armv7l GNU/Linux

In the mean time the SD card went to heaven ... and the RPi needed a reinstall.

Linux dev-rasp 4.14.71-v7+ #1145 SMP Fri Sep 21 15:38:35 BST 2018 armv7l GNU/Linux

Now I have to wait for some satellite passes :-)

Prerequisites

sudo dpkg -i /mnt/backup/Nodes/dev-rasp/various/wxtoimg/wxtoimg-armhf-2.11.2-beta.deb
sudo apt-get update
sudo apt-get install sox
sudo apt-get install predict
sudo apt-get install libxft-dev
sudo apt-get install imagemagick

User

I've changed the scripts a little bit. Please remember to add the user (in my case wxtoimg) to the sudoers and allow this user to sudo without entering a password. One way is to copy the line for the user pi and change the first field in the file /etc/sudoers:

pi ALL=(ALL) NOPASSWD: ALL
wxtoimg ALL=(ALL) NOPASSWD: ALL

schedule_all.sh

#!/bin/bash
# Update Satellite Information
wget -qr https://www.celestrak.com/NORAD/elements/weather.txt -O /home/wxtoimg/weather/predict/weather.txt
grep "NOAA 15" /home/wxtoimg/weather/predict/weather.txt -A 2 > /home/wxtoimg/weather/predict/weather.tle
grep "NOAA 18" /home/wxtoimg/weather/predict/weather.txt -A 2 >> /home/wxtoimg/weather/predict/weather.tle
grep "NOAA 19" /home/wxtoimg/weather/predict/weather.txt -A 2 >> /home/wxtoimg/weather/predict/weather.tle

#Remove all AT jobs
for i in `atq | awk '{print $1}'`;do atrm $i;done

#Schedule Satellite Passes:
/home/wxtoimg/weather/predict/schedule_satellite.sh "NOAA 19" 137.1000
/home/wxtoimg/weather/predict/schedule_satellite.sh "NOAA 18" 137.9125
/home/wxtoimg/weather/predict/schedule_satellite.sh "NOAA 15" 137.6200

schedule_satellite.sh

 

#!/bin/bash
PREDICTION_RESULT='predictionResult.txt'
/usr/bin/predict -t /home/wxtoimg/weather/predict/weather.tle -p "${1}" > $PREDICTION_RESULT
PREDICTION_START=`head -1 $PREDICTION_RESULT`
PREDICTION_END=`tail -1 $PREDICTION_RESULT`
var2=`echo $PREDICTION_END | cut -d " " -f 1`
MAXELEV=`cat $PREDICTION_RESULT | awk -v max=0 '{if($5>max){max=$5}}END{print max}'`
while [ `date --date="TZ=\"UTC\" @${var2}" +%D` == `date +%D` ]; do
START_TIME=`echo $PREDICTION_START | cut -d " " -f 3-4`
var1=`echo $PREDICTION_START | cut -d " " -f 1`
var3=`echo $START_TIME | cut -d " " -f 2 | cut -d ":" -f 3`
TIMER=`expr $var2 - $var1 + $var3`
OUTDATE=`date --date="TZ=\"UTC\" $START_TIME" +%Y%m%d-%H%M%S`
if [ $MAXELEV -gt 10 ]
then
echo ${1//" "}${OUTDATE} $MAXELEV
echo "/home/wxtoimg/weather/predict/receive_and_process_satellite.sh \"${1}\" $2 ${1//" "}${OUTDATE} /home/wxtoimg/weather/predict/weather.tle $var1 $TIMER" | at `date --date="TZ=\"UTC\" $START_TIME" +"%H:%M %D"`
fi
nextpredict=`expr $var2 + 60`
/usr/bin/predict -t /home/wxtoimg/weather/predict/weather.tle -p "${1}" $nextpredict > $PREDICTION_RESULT
PREDICTION_START=`head -1 $PREDICTION_RESULT`
PREDICTION_END=`tail -1 $PREDICTION_RESULT`
MAXELEV=`cat $PREDICTION_RESULT | awk -v max=0 '{if($5>max){max=$5}}END{print max}'`
var2=`echo $PREDICTION_END | cut -d " " -f 1`
done

receive_and_process_satellite.sh

#!/bin/bash
# $1 = Satellite Name
# $2 = Frequency
# $3 = FileName base
# $4 = TLE File
# $5 = EPOC start time
# $6 = Time to capture

IMAGE_PATH="/mnt/images"
WAV_PATH="/tmp"
WAV_FILE="$WAV_PATH/$3.wav"
MAP_FILE="$WAV_PATH/$3.map.png"

AMP_GAIN=45
PPM_CORR=0
PREVIEW_WIDTH=200

sudo timeout $6 rtl_fm -f ${2}M -s 60k -g $AMP_GAIN -p $PPM_CORR -E wav -E deemp -F 9 - | sox -t wav - "$WAV_FILE" rate 11025

PassStart=`expr $5 + 90`
#
# convert the wav file into png and thumbnail
#
# $1 wav file
# $2 basefilename
# $3 enhancement type
# $4 map file
#
processImage () {
local file_large = "$IMAGE_PATH/$2.$3.png"
local file_small = "$IMAGE_PATH/$2.$3.small.png"
/usr/local/bin/wxtoimg -m $4 -e $3 $1 $file_large
convert $file_large -resize $PREVIEW_WIDTH $file_small
}
#
#
#
#
if [ -e "$WAV_FILE" ]
then
echo "Soundfile created " %WAV_FILE
/usr/local/bin/wxmap -T "${1}" -H $4 -p 0 -l 0 -o $PassStart $MAP_FILE
echo "Map file created " $MAP_FILE

processImage $WAV_FILE $3 "ZA" $MAP_FILE
processImage $WAV_FILE $3 "MCIR" $MAP_FILE
processImage $WAV_FILE $3 "HVCT" $MAP_FILE
processImage $WAV_FILE $3 "MSA" $MAP_FILE
# rm -f $WAV_FILE
rm -f $MAP_FILE
echo "cleanup done"
fi