|
@@ -0,0 +1,76 @@
|
|
|
+#!/bin/bash
|
|
|
+
|
|
|
+instance=asd
|
|
|
+auth='-u user:pass'
|
|
|
+curl="curl $auth"
|
|
|
+remote='https://push.example.net/'
|
|
|
+snrduration=10
|
|
|
+
|
|
|
+if ! lsusb -d '0bda:2838' > /dev/null; then
|
|
|
+ echo "no RTL-SDR found" 2> /dev/null
|
|
|
+ exit 0
|
|
|
+fi
|
|
|
+
|
|
|
+mkdir -p /tmp/samples/
|
|
|
+
|
|
|
+get_power() {
|
|
|
+ rtl_power -f $1:$2:20k -c 0.3 -1 -i 3 2> /dev/null| \
|
|
|
+ cut -d, -f7-|tr , '\n'|awk '{sum += $1; lines+=1; } END {print sum/lines }'
|
|
|
+}
|
|
|
+
|
|
|
+do_station() {
|
|
|
+ freq=$1
|
|
|
+ station=$2
|
|
|
+ start=$((freq - 100000))
|
|
|
+ end=$((freq + 100000))
|
|
|
+ shortfreq=$(bc <<< "scale=1; $freq/1000000")
|
|
|
+
|
|
|
+ power=$(get_power $start $end)
|
|
|
+ cat <<EOF | $curl --data-binary @- "$remote/metrics/job/radio/instance/$instance/freq/$shortfreq/modulation/fm/station/$station"
|
|
|
+#TYPE radio_power gauge
|
|
|
+#HELP radio_power valore assoluto
|
|
|
+radio_power $power
|
|
|
+EOF
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+snr() {
|
|
|
+ freq=$1
|
|
|
+ station=$2
|
|
|
+ shortfreq=$(bc <<< "scale=1; $freq/1000000")
|
|
|
+ timeout -s INT $snrduration rtl_fm -g 50 -f "$freq" -M wfm -s 180k -E deemp | \
|
|
|
+ sox -traw -r180k -es -b16 -c1 -V1 - -t ogg - | \
|
|
|
+ pee "sponge /tmp/samples/$station.ogg" "sox - -n stats" "sox - -n stat" 2>&1 | \
|
|
|
+ grep -vw -e Bit-depth -e NaN | grep -E '[0-9]$' |
|
|
|
+ sed -e 's/\([^ ]\) *\([-0-9]\)/\1=\2/;s/ */ /;s/^/radio_sox_/'| \
|
|
|
+ tr ' ' _|tr -d '():' | \
|
|
|
+ tr = ' ' | \
|
|
|
+ while read line
|
|
|
+ do
|
|
|
+ echo $line | $curl --data-binary @- "$remote/metrics/job/radio/instance/$instance/freq/$shortfreq/modulation/fm/station/$station"
|
|
|
+ done
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+#(
|
|
|
+# if ! flock -n 9 ; then
|
|
|
+#echo 'Error: sdr locked'
|
|
|
+#exit 1
|
|
|
+#fi
|
|
|
+
|
|
|
+ do_station 87900000 ror
|
|
|
+ do_station 87600000 rai1
|
|
|
+ do_station 98400000 rai3
|
|
|
+ do_station 102100000 freccia
|
|
|
+ do_station 88100000 elle
|
|
|
+ snr 87900000 ror
|
|
|
+ snr 102100000 freccia
|
|
|
+ snr 98400000 rai3
|
|
|
+# flock -u 9
|
|
|
+#) 9> /var/lock/sdr.lock
|
|
|
+
|
|
|
+# rds_out=$(./rds_check)
|
|
|
+# ret=$?
|
|
|
+# if [[ "$ret" -ne 3 ]]; then
|
|
|
+# echo -e "$(date +%s)\\t$ret\t$rds_out" >> "$datadir/rds.csv"
|
|
|
+# fi
|