[arm-allstar] Completed - Radioless Node - push button switch to run connect to hub/node script - Restarting shell script from within a shell script.

Rob Seaman vk6ld at outlook.com.au
Wed Aug 9 22:49:47 EDT 2023


Hi All,

Posting another follow-up to my radioless node - push button connect to hub/node project, with a slight issue I'm having.

I can see the shell script is starting and waiting when the node starts up by checking with ps -ax.

After executing the shell script once, it then seems to drop off the ps -ax list and is not restarting waiting for the next button push.

I tried including the name & path of the shell script itself within the script to run, but it then seems to have two instances of the shell script running when doing a ps -ax.

Eg:
      # code to execute when holdtime is exceeded goes here
      /usr/bin/asterisk -rx "rpt fun $NODE1 *76*7347323"
      sleep 5
      /etc/asterisk/local/connect-vk6rhf.sh

I tried searching for an answer, how to restart a shell script from within a shell script, but didn't come up with much to help.  I had thought about running it periodically from crontab, but this is probably even more of a hack than my script within a script above. 😁

So just wondering if any one the shell script experts out there could tell me how to do this more elegantly please?

Many thanks,

Rob...
VK6LD



________________________________
From: Rob Seaman <vk6ld at outlook.com.au>
Sent: 12 July 2023 11:06 AM
To: arm-allstar at hamvoip.org <arm-allstar at hamvoip.org>
Subject: Completed - Radioless Node - push button switch to run connect to hub/node script

Hi All,

I posted the question in the Subject: line back in March 2023.  It's taken me a little time to get completed and follow up with the mailing list, but thanks to the answers & support from this group, I managed to get this hack working.

So much like the Allstar Halt Button/Switch (https://hamvoip.org/hamradio/RPi2_halt_switch/), I now also have a push button to initiate a connection to a selected node or hub, without the need for a DTMF mic or phone/tablet or computer.

First thing I did was get a working shell script (connect-vk6rhf.sh), shamelessly borrowed from the HamVOIP GPIO how to.  For my script, I am using GPIO pin 22 (GPIO-GEN6) and connecting to VK6RHF repeater, Allstar node 47323.

(connect-vk6rhf.sh):

#!/bin/bash
# Required button hold down seconds
PIN=6
HOLDTIME=5
# set mode to in and pullup pin 6 (Physical pin 22, GPIO25)
gpio mode 6 in
gpio mode 6 up
TIME1=1
while [ 1=1 ]
# wait in interrupt for pin to go low
gpio wfi $PIN falling
do
# Got the low now poll to see if it stays low for holdtime
while [ `gpio read $PIN` -eq "0" ];
do
sleep 1
let TIME1+=1
if [ $TIME1 -gt $HOLDTIME ]; then
# if greater than holdtime then exit past done
break 3;
fi
done
TIME1=1
continue
done
# code to execute when holdtime is exceeded goes here
/usr/bin/asterisk -rx "rpt fun $NODE1 *76*7347323"

2. Save script to /etc/asterisk/local and set to executable - chmod +x connect-vk6rhf.sh

3.  At this point you can test the script with gpio commands.  Run the script ./etc/asterisk/local/connect-vk6rhf.sh

      In a second window, run the following:      
      gpio read 6 -> should return 1.
      gpio mode 6 down -> should pull the input low.
      gpio read 6 -> should now return 0.
      By this point 5 seconds should've expired and your script can execute the connect to node command.
      gpio mode 6 up -> should return the input high.
      Check Allstarlink and your node should be connected to your desired node/hub.

3.  Modify /usr/local/etc/allstar.env - Just under export SHUTDOWN_MONITOR="enabled"

# defines the VK6RHF Connect switch to the RPi2 (enabled or disabled)
# default="enabled"
export CONNECT_VK6RHF="enabled"

Ctrl-X and save.

4.  Modify /usr/local/etc/allstar.env - Just under "Shutdown Monitor, RPi 2/3 Only" paragraph.

# Connect VK6RHF Button, RP2/3 Only
if [ "$HWTYPE" = "RPi2" ] && [ "$CONNECT_VK6RHF" = "enabled" ] ; then
    /etc/asterisk/local/connect-vk6rhf.sh & > /dev/null
fi

Ctrl-X, save & reboot.

Connect a push button or momentary switch between pins 20 & 22 on the GPIO of your RPi and now you have a shortcut "Connect to" for your radioless node.

So I hope this all makes sense, is informative and useful to others in the group.

73,

Rob...
VK6LD


Rob,

Did you get this all working?

To me it would not be much different than the Shutdown function example
as pointed out by others.

The main difference is to create different macros for each function and
instead of running the shutdown function point it to a script that runs
the proper macro for the function you want it to perform, The push and
hold time can be lowered to your preference

Referring to
<https://www.crompton.com/hamradio/hamvoip-howto/GPIO_how-to.pdf>

Example Script to read a bit
Another very useful 'gpio' command is 'wfi'This command waits for an
interrupt based on a rising or falling
level at a pin. It takes no processor time unlike polling. The command
syntax is:
gpio wfi 1 falling|rising
This example is from the shutdown monitor code I written for the RPi2
#!/bin/bash
# Required button hold down seconds
HOLDTIME=6
# set mode to in and pullup pin 0 (Physical pin 11, GPIO17)
gpio mode 0 in
gpio mode 0 up
TIME1=1
while [ 1=1 ]
# wait in interrupt for pin to go low
gpio wfi $PIN falling
do
# Got the low now poll to see if it stays low for holdtime
while [ `gpio read $PIN` -eq "0" ];
do
sleep 1
let TIME1+=1
if [ $TIME1 -gt $HOLDTIME ]; then
# if greater than holdtime then exit past done
break 3;
fi
done
TIME1=1
continue
done
# code to execute when holdtime is exceeded goes here


Larry - N7FM


On 3/6/23 7:32 AM, wrhowell amphibiansolutions.us via ARM-allstar wrote:
> How are you going to interface that box to a Pi in order to use the mic & speaker?
>
> Wil/Can you provide your setup afterwards for others to share, please?
>
>
> Thank you,
>
> William KI5PHN
> ________________________________
> From: ARM-allstar<arm-allstar-bounces at hamvoip.org<http://lists.hamvoip.org/cgi-bin/mailman/listinfo/arm-allstar>>  on behalf of Rob Seaman via ARM-allstar<arm-allstar at hamvoip.org<http://lists.hamvoip.org/cgi-bin/mailman/listinfo/arm-allstar>>
> Sent: Sunday, March 5, 2023 5:06 PM
> To:arm-allstar at hamvoip.org<http://lists.hamvoip.org/cgi-bin/mailman/listinfo/arm-allstar>  <arm-allstar at hamvoip.org<http://lists.hamvoip.org/cgi-bin/mailman/listinfo/arm-allstar>>
> Cc: Rob Seaman<vk6ld at outlook.com.au<http://lists.hamvoip.org/cgi-bin/mailman/listinfo/arm-allstar>>
> Subject: [arm-allstar] Radioless Node - push button switch to run connect to hub/node script
>
> Hi All,
>
> I'm building a radioless node for a friend who has interest in Allstar, but little to no interest in computers.
>
> He has given me a well made box, that was previously used a radio test jig setup, so it has a mic, speaker and a row of LED's & momentary SPST push button type switches on the front panel.
>
> One idea I had was to use the momentary switches to connect to some hubs, one for discconnect all and one for a shutdown switch on GPIO pins 9 & 11.
>
> The shutdown switch is easy, as the script already exists in Hamvoip.
>
> I had a search back through the Hamvoip.org list archives and the Allstar Community chat for connect/disconnect via a momentary switch on the GPIO, while there was one or two brief mentions of wanting to do this, I wasn't able to find any other information or scripts.
>
> I read the 'Using the GPIO command with Allstar 06/11/15' found on the Hamvoip website, so have a slightly better understanding, but I'm not clear how Allstar/Hamvoip is to monitor for example, GPIO pin 13 going to ground, therefore execute disconnect all (*76) or pin 15 going to ground, therefore connect to UK Hub (*7341522).
>
> Hope the above makes sense and any tips or assistance would be aprpeciated.
>
> Regards,
>
> Rob...
> VK6LD



More information about the ARM-allstar mailing list