BTW — if you intend to use wspr-decoded, I’ve been using the following script with some success. Just run "wspr-decoded wspr-pcm.local &” (assuming you’ve made the [wspr] definition active in
). That will decode wspr signals in each frequency and store them in a separate subdirectory of ~/recordings/wspr. The following script (change your call and grid square) will parse the files and upload them. I put it on a cron job to run every 10 min.
import os
import subprocess
import requests
def process_and_upload_wspr(directory, call, grid):
print(f"Processing and uploading in directory: {directory}")
# Change to the target directory
os.chdir(directory)
# Input and output file names
ALL_WSPR_FILE = "ALL_WSPR.TXT"
ALLMEPT_FILE = "ALLMEPT.TXT"
# Remove lines that contain the value of CALL from ALL_WSPR.TXT
with open(ALL_WSPR_FILE, 'r') as input_file:
lines = input_file.readlines()
with open(ALL_WSPR_FILE, 'w') as output_file:
for line in lines:
if call not in line:
output_file.write(line)
# Sort the data by highest SNR, print unique date/time/band/call combinations,
# and then sort them by date/time/frequency
sort_cmd = f"sort -nr -k 4,4 {ALL_WSPR_FILE} | awk '!seen[$1\"_\"$2\"_\"int($6)\"_\"$7] {{print}} {{++seen[$1\"_\"$2\"_\"int($6)\"_\"$7]}}' | sort -n -k 1,1 -k 2,2 -k 6,6 -o {ALLMEPT_FILE}"
subprocess.run(sort_cmd, shell=True)
# Upload the processed data using curl
files = {'allmept': open(ALLMEPT_FILE, 'rb')}
data = {'call': call, 'grid': grid}
if response.status_code == 200:
print("Upload successful.")
# Empty the ALL_WSPR.TXT file after a successful upload
open(ALL_WSPR_FILE, 'w').close()
else:
print("Upload failed.")
# Clean up the temporary file
os.remove(ALLMEPT_FILE)
if __name__ == "__main__":
# Directory where the subdirectories are located
base_directory = os.path.join(os.path.expanduser("~"), "recordings", "wspr")
# Common values for call and grid
CALL = "AC0G"
GRID = "EM38ww"
# Iterate through all subdirectories under ~/recordings/wspr
for subdirectory in os.listdir(base_directory):
full_directory_path = os.path.join(base_directory, subdirectory)
if os.path.isdir(full_directory_path):
process_and_upload_wspr(full_directory_path, CALL, GRID)