sonda 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #!/bin/bash
  2. instance=asd
  3. auth='-u user:pass'
  4. curl="curl $auth"
  5. remote='https://push.example.net/'
  6. snrduration=10
  7. if ! lsusb -d '0bda:2838' > /dev/null; then
  8. echo "no RTL-SDR found" 2> /dev/null
  9. exit 0
  10. fi
  11. mkdir -p /tmp/samples/
  12. get_power() {
  13. rtl_power -f $1:$2:20k -c 0.3 -1 -i 3 2> /dev/null| \
  14. cut -d, -f7-|tr , '\n'|awk '{sum += $1; lines+=1; } END {print sum/lines }'
  15. }
  16. do_station() {
  17. freq=$1
  18. station=$2
  19. start=$((freq - 100000))
  20. end=$((freq + 100000))
  21. shortfreq=$(bc <<< "scale=1; $freq/1000000")
  22. power=$(get_power $start $end)
  23. cat <<EOF | $curl --data-binary @- "$remote/metrics/job/radio/instance/$instance/freq/$shortfreq/modulation/fm/station/$station"
  24. #TYPE radio_power gauge
  25. #HELP radio_power valore assoluto
  26. radio_power $power
  27. EOF
  28. }
  29. snr() {
  30. freq=$1
  31. station=$2
  32. shortfreq=$(bc <<< "scale=1; $freq/1000000")
  33. timeout -s INT $snrduration rtl_fm -g 50 -f "$freq" -M wfm -s 180k -E deemp | \
  34. sox -traw -r180k -es -b16 -c1 -V1 - -t ogg - | \
  35. pee "sponge /tmp/samples/$station.ogg" "sox - -n stats" "sox - -n stat" 2>&1 | \
  36. grep -vw -e Bit-depth -e NaN | grep -E '[0-9]$' |
  37. sed -e 's/\([^ ]\) *\([-0-9]\)/\1=\2/;s/ */ /;s/^/radio_sox_/'| \
  38. tr ' ' _|tr -d '():' | \
  39. tr = ' ' | \
  40. while read line
  41. do
  42. echo $line | $curl --data-binary @- "$remote/metrics/job/radio/instance/$instance/freq/$shortfreq/modulation/fm/station/$station"
  43. done
  44. }
  45. #(
  46. # if ! flock -n 9 ; then
  47. #echo 'Error: sdr locked'
  48. #exit 1
  49. #fi
  50. do_station 87900000 ror
  51. do_station 87600000 rai1
  52. do_station 98400000 rai3
  53. do_station 102100000 freccia
  54. do_station 88100000 elle
  55. snr 87900000 ror
  56. snr 102100000 freccia
  57. snr 98400000 rai3
  58. # flock -u 9
  59. #) 9> /var/lock/sdr.lock
  60. # rds_out=$(./rds_check)
  61. # ret=$?
  62. # if [[ "$ret" -ne 3 ]]; then
  63. # echo -e "$(date +%s)\\t$ret\t$rds_out" >> "$datadir/rds.csv"
  64. # fi