Quantcast
Channel: Roger Clark – Roger Clark
Viewing all articles
Browse latest Browse all 163

MMDVM hotspot – hardware network switch

$
0
0

Several months ago, John VK4JWT asked me if I knew of a way to switch his JumbSpot between Brandmeister and DMR Marc using some sort of physical switch.

John was interested in this feature, because he does a lot of mobile operation and it would be much easier to be able to flick a switch on the hotspot, when driving along in he car, than it would be to mess around with different channels and reflector codes.

 

Unfortunately at the time I had a lot of other projects on the go, and only had time to investigate the theory of how this could be done; however the recent changes to the Australian DMR MARC network , to use IPSC2 and direct talk group access to the Australian MARC network, got me thinking about this problem again, and I have finally come up with a solution, where I have an external 2 position toggle switch connected to my duplex hotspot, where one position tells PiStar to connect to DMR MARC and the other position tells PiStar to connect to Brandmeister.

 

Note.

Before I go into the details.. Although I have made this modification to my duplex hotspot, I have checked the schematic for the simplex hotspot aka JumboSpot and as far as I can see, it should work fine on the simplex hotspot, because it uses the same pins to connect from the Raspberry Pi to the hotspot – specifically Pin 7 seems to be available on the top of the hotspot, and can be soldered onto.

 

The first part of this system is the hardware switch itself.

Looking in my box of spares, and other junk, I found a toggle switch which had a central wiper and 2 other pins. In one position the wiper is connected to one pin and in the other position its connected to the other pin. The 2 “other” pins are not connected to each other at any time (This is important)

 

To connect the switch to the Raspberry Pi, I needed to find a solder pad on the duplex hotspot that was connected to an unused GPIO pin on the RPi board.

Most duplex hotspots, do not have connections to the entire Raspberry Pi pins, they only have two 10 pin headers, one at each end of the bank of pins on the Raspberry Pi, and of course some of these pins are used for the communication etc between the hotspot and the RPi

Looking on github, I found the original open source design for the duplex hotpot which was used as the basis for the duplex hotspots that are available on eBay and AliExpress from China.

This showed which pins on the RPi were actually used.

Because I also need a 3.3V supply to connect to the switch, I chose Pin 7 (aka BCM4_GPCLK0), as it was close to pin 1 which has 3.3V on it (and also right next to a ground , which I also needed)

 

In order for the RPi to sense the position of the switch, the voltage on Pin 7, needs to be 3.3V when the switch is in one position and 0V when its in the other position. Although it you could connect Pin 7 directly to the wiper, and 3.3V and 0V to the other 2 pins respectively, its normally good practice to pull up or pull down GPIO pins via a resistor.

In my case I had a 4.7k resistor on my workbench, left over from a previous project, so I decided to use that, but I think the optimum value is normally 10k (but don’t quote me), anyway 4.7k works fine 😉

So I soldered the 4.7k to Pin 7, then connected the switch via  flying lead, where I used red for 3.3V, black for 0V and brown for the switched input Pin 7

 

 

After powering up the hotspot, and making sure I’d not done any harm to the board, e.g. like shorting the power rail, I checked that Pin 7 was indeed being switched to have either 0V or 3.3V depending on the position of the switch.

 

The next step in the process is to make separate profiles for Bransmiester and DMR MARC on  PiStar and add a script to switch between them

To do this you need to login to the PiStar console , by using the “SSH Access” option in the Expert settings.

and create a folder to store the configuration files

using the commands

rpi-rw

mkdir configs

 

Note.

The command rpi-rw makes the SD card writable, and you may need to use this command again if you find that the SD card becomes non writable – because the RPi operating system seems to run a daemon which keeps changing the SD to read only

 

 

 

 

The next step is to use the PiStar configuration screen to change to Brandmeister only, e.g. on my case..

 

 

Then press the Apply Changes button

 

Then go back open the SSH Access screen again and copy the active MMDVMHost file to the configs folder

 

sudo cp /etc/mmdvmhost /configs/bm

 

Then reconfigure PiStar for DMR Marc using the configuration screen (again), then once the DMR MARC configuration has been installed by PiStar, make a backip of this profile as well

 

sudo cp /etc/mmdvmhost /configs/marc

 

 

Now that you have the 2 configurations backed up, you need to make a script file to check the status of  GPIO Pin 7 and copy the relevant mmdvmhost profile file to the master location and then restart MMDVMHost.

 

This is the script I created to do this, which can be downloaded from this link  net-switcher.sh

 

But to get it onto the RPi you can use this command from the SSH window

 

curl http://www.rogerclark.net/wp-content/uploads/2018/11/net-switcher.sh_.txt –output net-switcher.sh

 

Now that you have the scripts (in /home/pi-star) you need to make it executable using this command

chmod +x net-switcher.sh

 

The next step is to test whether the script actually works. by running it in the foreground, by typing the command to run it

 

sudo ./net-switcher.sh

 

Depending on the position of the switch , you should see the message “DMR MARC mode” or “Brandmeister mode”

 

Looking on the PiStar dashboard, you should see the “DMR Master” change (in the lower left corner of that screen).

Note. Although MMDVMHost is restarted and connects fairly quickly, I’ve noticed on IPSC2 and Brandmeister that it takes around 10 secs for the connection to the server to be fully operational.

 

Now to make this script run when the PiStar starts up.

 

NOTE THIS CHANGE COULD POTENTIALLY STOP YOUR PISTAR BOOTING IF YOU DO NOT DO IT CORRECTLY.

 

I used the method described on this page  https://www.dexterindustries.com/howto/run-a-program-on-your-raspberry-pi-at-startup/

 

Specifically “method 1” which adds the script to /etc/rc.local

 

To do this you need to edit that file e.g.

 

sudo nano /etc/rc.local

 

and add the following line to the second to last line in the file. (just above the line that reads “exit 0”

The text to add is

 

/home/pi-star/net-switcher.sh &

 

Once you have added this line and saved the file, all you need to do is reboot (or power cycle) your PiStar hotspot, and after its finished rebooting, you can confirm that the switch is still working by looking at the dashboard

 

(Note. There are other ways to run a script at boot time, but this method works for me)

 

 

 

 

 

 

For anyone who wants to read the script, here it is

 

 

# Script to allow switching of DMR network using a hardware switch
# connected to a gpio pin
# by Roger Clark VK3KYY / G4KYF

# Before using this script you need to make backup copies of your DMR Marc
# and Brandmeister mmdvmhost setting files into /home/pi-star/configs
# the script assumes the files are called marc and bm
#
# You need to make the configs folder
# e.g.
# rpi-rw
# mkdir /home/pistar/configs
#
#
# To create these files. Use the Pi-Star configuration screen to switch to
# DMR Marc, then copy /etc/mmdvmhost to /home/pi
# cp /etc/mmdvmhost /home/pistar/configs/marc
# Then reconfigure to Brandmeister and save that config
# cp /etc/mmdvmhost /home/pistar/configs/bm

#--------- Script code starts here ----------------------------------------

gpio mode 7 in
# Set the lastVal to a non binary value to force the script to copy the
# config set by the switch when the script starts, in case the switch
# was changed when the script was not running, e.g. if the Raspberry Pi was
# not powered up etc
lastVal=-1

#Loop indefinitely
while :
do
b=$(gpio read 7)
if [ $b != $lastVal ]
then
lastVal=$b
#need to mount the file system as read write
#as it defaults to read only

mount -o remount,rw /
if [ $b -eq 1 ]
then
echo "Brandmeister mode"
cp /home/pi-star/configs/bm /etc/mmdvmhost
else
echo "DMR MARC mode"
cp /home/pi-star/configs/marc /etc/mmdvmhost
fi
mount -o remount,ro /
systemctl restart mmdvmhost.service
fi
sleep 1
done

Viewing all articles
Browse latest Browse all 163

Trending Articles