Friday, October 27, 2023

Automagically Switch an Idle FlexRadio to WSPR

 

-----

When our FlexRadio is not being used it really should do 'something'.   We typically put it in a WSPR spotting mode via WSJT-X, but sometimes we forget.  This short simple Python script takes care of that.

----

FlexRadio has an open API and we could have just used it to accomplish the project.  However, there are two wonderful (and free) programs that are always open on the PC running the FlexRadio SmartSDR software that make things easier; FRStack and Slice Master.  In this project we use FRStack for API calls and Slice Master to automatically launch WSJT-XNOTE: We use FRStack and Slice Master for other features as well.  IMO they are must have programs to make your Flex more flexible. 

-----

The Python script listed below looks at user defined intervals (in the example it is every 30 minutes) to see if any settings on the rig have changed.  If a setting has changed (frequency, band, mode, volume, filters, etc. etc. etc...) the program assumes the rig is in use and just waits for the next check interval. 

-----

If the time interval expires and no settings have been changed the program assumes the rig is idle and switches it to DIGU mode.

 Slice Master takes that switch to DIGU mode as a trigger to launch WSJT-X and start doing WSPR stuff.

-----

# auto_wspr.py  OCT2023
#
# Python script to make the Flex Radio switch to WSPR mode when idle.
#
# Written by:  WhiskeyTangoHotel.Com
#
# Leverages the auto LAUNCH feature of "Slice Master".
# https://github.com/K1DBO/slice-master-6000
#
# Leverages WSJT-X for TX/Rx spotting
# https://wsjt.sourceforge.io/wsjtx.html
#
# Leverages FRStack
# https://www.mkcmsoftware.com/download/FRStackWebApiReadme.html#apis

import requests
import urllib.request
import time

# Set idle_max to the number of minutes between checks to see if any rig settings have changed.
# If idle rig then switch to DIGU mode.  DIGU mode will trigger Slice Master to start WSJT-X.

idle_max = 60    # in minutes,  How ofen to check to see if the rig is idle.

last_status = 'First_run'
mode = ' '

#print ( 'Entering endless loop.....' )
while True:    
    print ('Checking for rig activity every' , idle_max , 'minutes.')
    print ('---------------------------------------------------')

    # If rig is in DIGU mode then do nothing.  We are already running WXJT
    response = requests.get('http://localhost:13522/api/ActiveSlice/MODE?')
    response = response.text
    mode = response
    #print ('MODE is:' , response)
    
    if response == '"DIGU"':
        print ('Rig in DIGU mode.  Do nothing.')
    else:  # not in DIGU mode.  Have rig settings changed or is it idle?
        response = requests.get('http://localhost:13522/api/ActiveSlice/INFO?')
        current_status = response.text
        if last_status != current_status:   
            print ('Rig in use.  Do not change to DIGU.  Do not launch WSJT')

            #print(last_status)
            print (' ')
            #print (current_status)

            last_status = current_status   
        else: 
            print ('Rig has been idle for' , idle_max , 'minutes.')
            print ('Switch to DIGU mode. Slice Master will launch WSJT.')

            #print(last_status)
            print (' ')
            #print (current_status)
           
            # DIGU modes can be LOUD.  Adjust the volume to low
            urllib.request.urlopen('http://localhost:13522/api/ActiveSlice/AUDIOGAIN?=+1')

            # Switch rig to DIGU mode
            urllib.request.urlopen('http://localhost:13522/api/ActiveSlice/MODE?=DIGU')

    for nextcheck in range(idle_max, 0, -1):
        response = requests.get('http://localhost:13522/api/ActiveSlice/MODE?')
        response = response.text
        mode = response
        print ('MODE is', mode, '-', int(nextcheck) , "minutes until next idle rig check...")
        time.sleep(60)
       
    print (' ')   
       
    # end endless while loop
-----