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!
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.
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.
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.
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.
#!/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
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:
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.
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.
Comments
thanks!
Ill get the script working on a VM first before launching it on my kiwi.
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 ;)
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!
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.
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.
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.Brill, thanks. Really appreciate the guidance.
This is what I originally had:
Ok this test works
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
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 sayantennas
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:Thank you very much! Ill patch it and see what occurs!
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:
Will check those lines.
Debug output isnt all that helpful
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
The buttons still seem to be non responsive. I cant even get any console or debug output in the browser dev tools.