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 DMR MARC 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/marc
Then reconfigure PiStar for Brandmeister using the configuration screen (again), then once the Brandmeister configuration has been installed by PiStar, make a backup of this profile as well
sudo cp /etc/mmdvmhost configs/bm
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 > 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
Robert
Thanks for your work Roger, I am looking at applying this to a jumbo spot, but I am not able to do so, what is the chip number. I am assuming its the same on a duplex board as is on a simplex board
Roger Clark
Robert
It should work on a JumboSpot. I checked the schematic and its connections to the RPi are the same as far as I can tell.
Pin 7 seems to be free and available on the top of the hotspot
Robert
Thanks, but what is the chip number ? is it the RF chip ?
Roger Clark
It doesnt matter what RF chip they use, but AFIK they all use the ADF7021
Anonymous
Thanks Roger, it was not clear to me that it was the RF chip.
Robert
ADF7021 is 48 pin
Your Chip is 40 Pin
https://www.google.com.au/search?q=adf7021&rlz=1C1AVNG_enAU611AU612&tbm=isch&source=iu&ictx=1&fir=nGuYBYGhpO0gIM%253A%252Cg0tu_rqZNLZimM%252C_&usg=AI4_-kQEk4fbzHldKKxNmqwxLcOID4cXUA&sa=X&ved=2ahUKEwjjxp6D3bLeAhUJRY8KHWi7BXcQ9QEwAnoECAUQBA#imgrc=nGuYBYGhpO0gIM:
Roger Clark
Looking under the microscope they are marked as
ADF7021 BCPZ #1733 3949267.1
I’m not sure what chip you are looking at, but mine are 48 pin,
ken
wow
Roger Clark
LOL… I’m not sure it deserves a “wow” 😉 but the technique may come in handy …
Robert
I worked it out, its the header pins not an IC on your diagram… Thanks
Roger Clark
OK
Robert
Roger, I am getting :Could not resolve host errors
when running the netswitcher script
Roger Clark
Strange..
That command worked for me the other day
Try this instead
curl http://www.rogerclark.net/wp-content/uploads/2018/11/net-switcher.sh_.txt > net-switcher.sh
Or
curl -O http://www.rogerclark.net/wp-content/uploads/2018/11/net-switcher.sh_.txt
and then rename the file to remove
mv net-switcher.sh_.tx net-switcher.sh
make sure the SD card is writeable first by doing rpi-rw
Robert
Thanks, that worked and the script is also working
Anonymous
All done and dusted, works good Roger
Thank you
Robert
All working, Thank you Roger
Roger Clark
Excellent
Roger Clark
OK
I’ll update the post with the ammendment to the curl command
Thanks..
Robert
VK7HSE will send you all the changes to your instruction that made things work.
Thanks
Roger Clark
That would be great.
Thanks
ALex VK2PSF
You may need to move dmrgateway as well for some configs
Roger Clark
Yes.
I totally agree.
I’m now working on a revised script which does this.
Edit
I just tried this, but it looks like dmrgateway is only running if its needed, so attempts to restart it, if its not running give a warning / error message
I’m not sure if its better / quicker to use ps to find if the service is running, and then only restart it if it is running, or simply try to restart it regardless of whether its running or not
I suppose the latter would result in the log files getting messy 🙁
Alex VK2PSF
I suspect mmdvmhost will look after it by inspecting the enable flags in each section and starting as needed will investigate.
Alex VK2PSF
OK, so the configure scripts action is to stop all services (including cron) make changes then start all services using sudo systemctl start dmrgateway.service > /dev/null 2>/dev/null & try and ignore any return values, the start script for dmrgateway looks for 127.0.0.1 to decide if it should execute. most have been installed to systemctl as disabled so there is no automated restarting so just start the services anyway.
Roger Clark
I think PiStar dashboard has code to handle when DMR Gateway is selected as DMR Master; but I’d need to look in the source code to confirm
Roger Clark
OK
For mmdvmhost I copied the restart code from the dashboard code, but it looks like things are different for DMR Gateway
BTW. I just tried running
sudo systemctl restart dmrgateway.service
Edit.
I think you already got past this point, and decided it best to try to start it, regardless and then hide the errors
Did you check if the errors get logged ?
and this doesn’t return any errors if the service is already running, but I don’t know if the command actually restarted it or not.
running
sudo systemctl start dmrgateway.service
even if the service is already running, doesn’t seem to show any errors
However, if I change the configuration in the dashboard and remove DMR Gateway as DMR Master and then try to start the service, it fails.
I’m not sure why this is, because the dmrgateway config file is present in /etc
Bevan VK5BD
Good work Roger, have you considered adding some scripting to the Pi-Star remote commands so that the swapping on modes could be done remotely by private calling 9999991 or 9999992 (examples only) that way there are no hardware mods, I do understand it will be harder for the user to know what mode there hotspot is in and have to rely on memory to know the mode they have left it in if they cant see the dashboard
Roger Clark
Several people have suggested this, and I’ll probably have a go at implementing it when I get chance.
Robert Alford
Did you ever manage a Open GD77 Implementation so I can use both my Open GD77 Radios to switch from 1 to the Other ?
Roger Clark
I only wrote a system to copy the mmdvmhost config files for us with hotspots connected via GPIO to the RPi.
It may work to switch between 2 USB based hotspots (like the GD-77) but I’ve never tried that, as I can’t see a use case for that.