Auto Scanning With SDR

Sieradelta

Newbie
Joined
Nov 12, 2023
Messages
2
I have raspberry pi with raspbian os. i also have Noo elec E4000 NESDR and XTR software defined radio. I have written a bash code that should scan the frequencies from 90MHz to 95MHz and note down the frequencies having transmission peaks with in a txt file that is saved on the desktop with real time update. the time of detection should also be mentioned against each detected frequencies along with its power level. the output txt file should also show that which frequency is being currently scanned by the sdr and any transmission is detected against the same or not. The script is as follows:

#!/bin/bash

# Output file on the desktop
output_file="$HOME/Desktop/frequency_scan.txt"

# Frequency range and step size
start_freq=90000000 # 90 MHz
end_freq=95000000 # 95 MHz
step_size=25000 # 25 KHz

# SDR parameters
sample_rate=0.025M
gain=0
scan_duration=5 # 60 seconds per frequency (adjust as needed)

# Create the output file (or clear it) at the beginning
echo -n > "$output_file"

# Continuously scan the frequency range
while true; do
for ((freq = start_freq; freq <= end_freq; freq += step_size)); do
timestamp=$(date +'%Y-%m-%d %H:%M:%S')
printf "Scanning %d Hz at %s... " "$freq" "$timestamp"

# Scan frequency for the specified duration and log the result
scan_result=$(timeout "$scan_duration" rtl_power -f "$freq":"$freq" -g "$gain" -s "$sample_rate" -c 0 -q -)

# Check if power level is above a certain threshold (adjust as needed)
if [ -n "$scan_result" ]; then
power=$(echo "$scan_result" | awk '{print $2}')

if [ "$power" -ge 0 ]; then
signal_status="Signal Detected"
else
signal_status="No Signal"
fi
else
signal_status="No Signal"
fi

# Log the time, scanned frequency, power, and signal status to the output file
echo "$timestamp, $freq Hz, Power: $power dB, $signal_status" >> "$output_file"
done
done

the script is creating the ouput files with all details but not recording the peak frequencies with transmission and their power levels. every time its showing " No Signal Detected" even if the FM radio channels are working in this range of frequencies.

Can somone please help?
 
Last edited:

belvdr

No longer interested in living
Joined
Aug 2, 2013
Messages
2,567
Next time, either upload the script or insert as code.

I see lots of issues in your script. For example, in your comparison for $power, you're comparing a string to an integer.

To troubleshoot, I suggest echoing out variables to see their values right after your capture them, such as $power and $scan_result.
 

Sieradelta

Newbie
Joined
Nov 12, 2023
Messages
2
Next time, either upload the script or insert as code.

I see lots of issues in your script. For example, in your comparison for $power, you're comparing a string to an integer.

To troubleshoot, I suggest echoing out variables to see their values right after your capture them, such as $power and $scan_result.
I am really thankful for your response. I am not that great in coding. I have shared the code as an attachment. can you please help?
 

belvdr

No longer interested in living
Joined
Aug 2, 2013
Messages
2,567
I am really thankful for your response. I am not that great in coding. I have shared the code as an attachment. can you please help?
Looks like it didn't upload. Anyhow, echo out the variables as I stated above. If they are as you expect, then your "if" statements need work. For example, if you expect $power to be > 0, and it is 50, then we simply need to modify your "if" statement. However, if you echo $power and it is 0, then something is wrong with $scan_result.
 
Top