Antenna switch | Kits | Commercially available?

2»

Comments

  • thanks!

    Ill get the script working on a VM first before launching it on my kiwi.

  • edited May 13

    Never trust VM! The best way is to buy another KiwiSDR (or better two, just in case). This is the only way you can safely check

    bash: echo -n "A1" > /dev/ttyUSB0 ;)

  • smgsmg
    edited May 13

    I think I have spent enough on kit recently. I would be a dead man walking if I bought another Kiwi - and hate to think what my life would be like if I got two more!

  • smgsmg
    edited May 18

    Well, I have a debian VM :-P connected to my RAAS-4a and I can change each position. It does however seem limited to 9600 Baud. I have reached out to Don from wa4mcmkits to see if 115200 baud is possible - and if there is a way to increase it from 9600.

    https://share.icloud.com/photos/05bo06oxB_L5Wy93En9dA_WSQ

  • If it's really only two characters it might be that operating at 9600 baud will be okay. You'd just have to try it and see what happens as far as any realtime impact.

    smg
  • smgsmg
    edited May 25

    Slow progress here.

    Don replied, and 9600 baud is all the PIC will do. Since it's only 2 bytes, there shouldn't be any performance related issues - ill take the punt.

    However, I am not a coder, and I am currently vibe coding. Apologies @jks :-)

    I have the basics working in a VM, however the backend script is more of a challenge with my limited knowledge.


    I have two scripts uploaded to the kiwi - one for testing, which as a very basic output, however I cant get past this error: "Backend script raas4a-test function AntSW_ShowBackend() sent bad configuration data!" when I try to enable the script.

    Testing:

    I can see what we are trying to achieve, however the extension doesn't like it at all.

    #!/bin/bash
    
    AntSW_ShowBackend() {
        echo "RAAS-4a 4 /dev/ttyUSB0"
    }
    
    AntSW_GetAddress() { echo "/dev/ttyUSB0"; }
    AntSW_SetAddress() { echo "/dev/ttyUSB0"; }
    AntSW_Initialize() { :; }
    AntSW_GroundAll() { :; }
    AntSW_SelectAntenna() { :; }
    AntSW_AddAntenna() { :; }
    AntSW_RemoveAntenna() { :; }
    AntSW_ToggleAntenna() { :; }
    AntSW_ReportSelected() { echo "Selected antenna: 1"; }
    AntSW_ShowSelected() { AntSW_ReportSelected; }
    
    case "${1,,}" in
        show) AntSW_ShowBackend ;;
        status) AntSW_ShowSelected ;;
    esac
    
    
    
    

    My vibe code is here:


    https://github.com/smegoff/RAAS-4-Scripts/blob/main/ant-switch-backend-raas4a

  • What happened to your previous script? It was much closer to being correct. That vibe thing is crap.

    Your AntSW_ShowBackend function needs to return info in the exact format as shown below (example from the beagle-gpio backend). A version number as second parameter is missing. The number of channels 3rd parameter is missing the "ch" directly after the number. A "mix" or "nomix" 4th parameter needs to indicate if the switch can mix antenna selections.

    Get rid of that case ... esac stuff at the end.

    AntSW_ShowBackend() {
      ...
      echo "beagle-gpio v2.0 10ch mix not-applicable"
      ...
    }
    


    smg
  • This is what I originally had:

    #!/usr/bin/env bash
    # ant-switch-backend-usb.sh
    # A KiwiSDR antenna‐switch backend for USB-serial relay boards
    # Copy this into /root/pkgs/ant_switch/, then in your Kiwi admin UI select “usb” as the backend.
    
    
    N_CH=8
    VERSION=1.0
    
    
    # Adjust to your USB-serial device and serial speed:
    TTY="/dev/ttyUSB0"
    BAUD=9600
    
    
    # Initialize serial port:
    configure_port() {
        stty -F "$TTY" "$BAUD" cs8 -cstopb -parenb -ixon -ixoff -echo
    }
    
    
    # Send a raw command (with CR) down the serial port:
    .send() {
        printf "%s\r" "$1" > "$TTY"
    }
    
    
    AntSW_ShowBackend() {
        echo "usb‐serial relay v$VERSION  $N_CH channels  $TTY@$BAUD"
        echo "More info: adapt this script to your board’s protocol"
    }
    
    
    AntSW_GetAddress() {
        # not used for USB backends, but Kiwi expects something:
        echo "$TTY"
    }
    
    
    AntSW_SetAddress() {
        echo "Serial port set to: $1"
        TTY="$1"
    }
    
    
    AntSW_Initialize() {
        configure_port
    }
    
    
    AntSW_GroundAll() {
        # turn ALL channels off
        for i in $(seq 1 $N_CH); do
            .send "OFF $i"
        done
    }
    
    
    AntSW_SelectAntenna() {
        # deselect all then enable one
        AntSW_GroundAll
        .send "ON $1"
    }
    
    
    AntSW_AddAntenna() {
        # leave existing + add this one
        .send "ON $1"
    }
    
    
    AntSW_RemoveAntenna() {
        .send "OFF $1"
    }
    
    
    AntSW_ToggleAntenna() {
        .send "TOGGLE $1"
    }
    
    
    AntSW_ReportSelected() {
        # (boards vary—some can report state; many don’t)
        echo "Selected antenna state reporting not supported."
    }
    
    
    # If you need Kiwi to know “status”:
    AntSW_ShowSelected() {
        AntSW_ReportSelected
    }
    
    
    # allow the script itself to be queried from the command line:
    if [[ "${1,,}" == "show" ]]; then
        AntSW_ShowBackend
    elif [[ "${1,,}" == "status" ]]; then
        AntSW_ShowSelected
    else
        # nothing
        :
    fi
    
    
    
    
  • Ok this test works

    #!/bin/bash
    
    AntSW_ShowBackend() {
        echo "raas4a-usb v1.0 4ch nomix /dev/ttyUSB0"
    }
    AntSW_GetAddress() { echo "/dev/ttyUSB0"; }
    AntSW_SetAddress() { echo "/dev/ttyUSB0"; }
    AntSW_Initialize() { :; }
    AntSW_GroundAll() { :; }
    AntSW_SelectAntenna() { :; }
    AntSW_AddAntenna() { :; }
    AntSW_RemoveAntenna() { :; }
    AntSW_ToggleAntenna() { :; }
    AntSW_ReportSelected() { echo "Selected antenna: 1"; }
    AntSW_ShowSelected() { AntSW_ReportSelected; }
    
    
    
  • Updated the code in Github - will plug the device in when I get home tonight and see if it works!

  • Ok so I am tantalisingly close to having this working, however the buttons in the front end extension GUI don't appear to fire the relevant antenna.

    I have enabled some logging and can see the script initialises and set the default antenna when I restart the Kiwi

     tail -f /tmp/raas4a-debug.log
    FUNCTION FunctionName
    2025-05-26 22:55:24 AntSW_ShowBackend
    2025-05-26 22:55:47 AntSW_Initialize
    2025-05-26 22:55:47 configure_port called
    2025-05-26 22:55:47 AntSW_SelectAntenna 1
    2025-05-26 22:55:47 send_cmd: A1 (EOL='\r')
    2025-05-26 22:55:47 AntSW_ReportSelected
    2025-05-26 22:55:47 send_cmd: A? (EOL='\r')
    2025-05-26 22:55:47 recv_resp called
    

    However when I hit Antenna 1 or 2 there is nothing in the output.

    My script (including debugging)

    https://github.com/smegoff/RAAS-4-Scripts/blob/main/ant-switch-backend-raas4a-usb-debugging

    A fresh set of eye would be great! :-)

  • Hold on, I'm looking at it..

  • Okay, the bug is that where you say echo "Selected antenna: $sel" you need to say antennas i.e. plural. This is because most of the backends have the possibility of mixing antennas and hence returning multiple antennas selected at the same time. The parsing of the response is fixed and looks for "antennas" specifically.

    Your script is very good. I had the impression you didn't quite know what to do. But it's absolutely fine. Here's a version with a simulation mode (SIM=1) I used to find the problem without actually having the raas4 hardware:


    smg
  • Thank you very much! Ill patch it and see what occurs!

  • smgsmg
    edited May 27

    In hindsight, I pulled the trigger too soon getting the raas4 and should have got the MS-S3A or @studentkra elegant cheap solution!

    Never mind. Its been a good experience and I enjoyed learning something new, and I also forgot how much I enjoy building kits.

    I might check with the local HAM club as I think the switching on this is too limiting, to just one or the other and no mixing and matching depending on who is using the radio.

  • Ok - I'm going to give it a rest for a while, the GUI buttons still don't issue "send_cmd: A1 or A2"

    There is no debug output so it would seem the button press isn't being registered.

    I've tried a fresh browser in privacy mode.

  • What happens if you use the manual front end script? I.e. “cda”, "aah" and use those aliases for an easier time running the script. "a1", "a2" to set ant 1&2, "as" to query status etc.

  • Ill give it a go tonight.

  • ah Ok, i have done this:

    ./ant-switch-frontend bs raas4a-usb # Select the backend script.
    Selected backend: raas4a-usb
    
    ./ant-switch-frontend bi
    raas4a-usb v1.0 4ch nomix /dev/ttyUSB0
    
    ./ant-switch-frontend 1
    throws up:
    
    root@kiwisdr:~/KiwiSDR/pkgs/ant_switch# ./ant-switch-frontend 1
    /root/kiwi.config/ant-switch-backend: line 21: [: ==: unary operator expected
    /root/kiwi.config/ant-switch-backend: line 30: [: ==: unary operator expected
    /root/kiwi.config/ant-switch-backend: line 30: [: ==: unary operator expected
    /root/kiwi.config/ant-switch-backend: line 42: [: ==: unary operator expected
    

    Will check those lines.

    Debug output isnt all that helpful

    2025-05-27 07:02:39 AntSW_Initialize
    2025-05-27 07:02:39 configure_port called
    2025-05-27 07:02:39 AntSW_SelectAntenna 1
    2025-05-27 07:02:39 send_cmd: A1 (EOL='\r')
    2025-05-27 07:02:39 AntSW_ReportSelected
    2025-05-27 07:02:39 send_cmd: A? (EOL='\r')
    2025-05-27 07:02:39 recv_resp called
    
  • Never mind = I used your script with SIM=1 and removed it from the top of the script. doh.

  • Righto

    Set SIM=0

    Manual switch setting works

    root@kiwisdr:~/KiwiSDR/pkgs/ant_switch# ./ant-switch-frontend bs raas4a-usb
    Selected backend: raas4a-usb
    ./ant-switch-frontend 1
    Debug output:
    
    2025-05-27 07:14:03 configure_port called
    2025-05-27 07:14:04 AntSW_SelectAntenna 1
    2025-05-27 07:14:04 send_cmd: A1 (EOL='\r')
    
    Same for selecting 2
    


  • The buttons still seem to be non responsive. I cant even get any console or debug output in the browser dev tools.

Sign In or Register to comment.