OP-25 Boatbod RPi Autostart on Bootup from a Python program

Status
Not open for further replies.

Carter911

Member
Joined
Aug 17, 2021
Messages
59
I apologize if my questions are trivial or aggravating, I'm still a total newbie to Linux, RPi's, and OP-25's numerous arguments.
I have OP-25 Boatbod up and running, on an RPi 3B+, with an RTL-SDR, with both the Terminal interface and the Web interface.
These work great and I am very appreciative of the developers and all of their time and effort!

My current goal is to run a Python program, (Program #1), on RPi Boot-up, using crontab, and then use that program to start OP-25 (rx.py...).
Eventually, Program #1 will use RPi I/O pins to determine which of several OP-25 configurations to start.
I can currently automatically start Program #1, through crontab, and select which of several simple Python LED flasher programs to run.
This works fine.

When I use:
proc = subprocess.Popen('python3 /home/pi/Documents/JCRPiFlashV6.py', shell=True)
I can spin off the LED flasher Python program / task / thread / process (? correct term) to run on its own and return control to Program #1.

I can run the Python Program #1 program during the RPi bootup, the LED flasher Python program runs, (forever), and the RPi boots up to its GUI, as per usual.

That was the simple test program, with the Python LED flasher program, and it all worked as desired.

I then tried to swap out the simple Python LED flasher program, (The secondary, or called program), to instead start OP-25 Boatbod, (rx.py...).
Again, this was to be called by Python program #1, that runs via crontab during the RPi bootup.

I have not yet been able to make this work, and I am hoping that I am missing something easy to fix this.

I've been trying to read the Python documentation, and on line examples, but truth be known much of it is still above my level of comprehension.

Side note:
This set of OP-25 arguments could use some more tweaking and cleanup, but this configuration works when entered through a Terminal,
or when called by a shortcut shell command. This configuration doesn't have a whitelist, it just plays all repeater traffic for testing.
Please ignore optimization of the OP-25 parameters for now.

I've tried a few different formats for having Program #1 initiate Program #2, (OP-25).
None have succeeded in getting OP-25 up and running and playing audio.

I suspect the process that I am looking for isn't much different than setups that run OP-25, on startup, on a headless RPi.
My Googling around, however, didn't yield an example of that.

A few, of many, formats tinkered with:
import subprocess #This is to run Shell commands, as spin offs, and return to Main
import os #This is to run Shell Command from Python
import RPi.GPIO as GPIO
import time

proc = subprocess.Popen('python3 /home/pi/op25/op25/gr-op25_repeater/apps/rx.py --args 'rtl' -N 'LNA:35' -S 1000000 -x 2 -f 858.5125e6 -o 25000 -q -1 -d -300 -T trunkJC1.tsv -V -2 -U 2>stderr-stream0.2', shell=True) (Note: This version's core: python3 /home... works from the terminal)

# proc = subprocess.Popen(['python3 /home/pi/op25/op25/gr-op25_repeater/apps/rx.py', '--args', 'rtl', '-N', 'LNA:35', '-S', '1000000', '-x', '2', '-f', '858.5125e6', '-o', '25000', '-q', '-1', '-d', '-300', '-T', 'trunkJC1.tsv', '-V', '-2', '-U', '2>stderr-stream0.2'], shell=True)

proc = subprocess.Popen(["python3", "/home/pi/op25/op25/gr-op25_repeater/apps/rx.py" "--args" "rtl" "-N" "LNA:35" "-S" "1000000" "-x" "2" "-f" "858.5125e6" "-o" "25000" "-q" "-1" "-d" "-300" "-T" "trunkJC1.tsv" "-V" "-2" "-U" "2>stderr-stream0.2"], shell=True)

I can insert a full (non) working Python program if that would be helpful, but I suspect the key to the issue is with the above subprocess.Popen() command usage.

Thoughts, feedback, guidance, a push in the right direction, etc., would all be appreciated.

I appreciate your time and patience in helping with this!

Jay
 

rjdj2000

Gone Cuckoo
Feed Provider
Joined
Jan 24, 2011
Messages
347
Location
Central NY
I kind of just went through this installing the other version of OP25 on a Pi 4B.

I basically created a .sh file doing:

Code:
sudo nano op25start.sh

In the editor that opens is where I put:

Code:
cd ~/Downloads/op25/op25/gr-op25repeater/apps/
./rx.py --args 'rtl' --gains 'lna:40' -X -T trunk.tsv -q 40 -S 1000000 -U -l 'http:0.0.0.0:8080' -2 -v 10 2>stderr.2

CTRL+X, then yes to save

Then in the directory you are in and created the .sh file:

Code:
chmod u+x op25start.sh

That gives you, the user permissions to execute the file and makes it available to run.

You should be then able to just enter ./op25start.sh and it should run. Mind you that the code above is for the Max branch of OP25 and not the boatbod version but I do believe that running rx.py is realativly the same for both. It has been awhile since I have messed with it and have just recently got back into it to try to work on my project of reviving an old Bearcat III. I have yet to figure out how to pause on a led when there is audio out of the 1/8" jack but will get it figured out somewhere.

After creating the .sh file, I too, was trying to get it to start @ boot of the Pi. I tried all different ways that I could find online either by crontab or what not. The only way I could get the Max branch of op25 to start @ boot was to do it as a service. Link here to web page: Creating a Raspberry Pi Service with systemd I changed basically what they had on there and was able to get it to work. I am not sure if it will help you or not as I am also a total newb with linux and it's commands. But maybe just making the shell script and making it excuteable, it might help you in your situation.
 

Carter911

Member
Joined
Aug 17, 2021
Messages
59
Hello rjdj,

Thank you for your reply!

I'll look into your link on Creating an RPi Service with systemd.
With a little luck we can make it work!

Other input and suggestions are also always welcomed!

Jay
 

rjdj2000

Gone Cuckoo
Feed Provider
Joined
Jan 24, 2011
Messages
347
Location
Central NY
I will try to get my Pi back up and running this evening and will look at the systemd file to get you how I did it.

This is from the link:
Code:
vi /home/dani/scripts/tempMonitor/tempMonitor.service

[Unit]
Description=Raspberry Temperature Monitor
After=network-online.target

[Service]
ExecStart=/bin/bash /home/dani/scripts/tempMonitor/tempMonitor.sh
WorkingDirectory=/home/dani/scripts/tempMonitor/
StandardOutput=inherit
StandardError=inherit
Restart=always
User=dani

[Install]
WantedBy=multi-user.target

Here is how I think I set mine up (not 100% sure without looking)

Code:
vi /home/pi/Downloads/op25/op25/gr-op25_repeater/apps/op25start.service

[Unit]
Description=OP25 Startup
After=network-online.target

[Service]
ExecStart=/bin/bash /home/pi/Downloads/op25/op25/gr-op25_repeater/apps/op25start.sh
WorkingDirectory=/home/pi/Downloads/op25/op25/gr-op25_repeater/apps/
StandardOutput=inherit
StandardError=inherit
Restart=always
User=pi

[Install]
WantedBy=multi-user.target

Pretty much just needed to change directory where the files reside and then run the other commands in terminal to make sure it worked. Now this don't let anything come on the screen. Change the directory to match yours and the User and you should be set to try the other commands to see if it will run.

You may have to add the following just after the [Service] and before the ExecStart line:

Code:
Environment="DISPLAY=:0"
Environment="XAUTHORITY=/home/<USERNAME>/.Xauthority"

Then at the end add:
Code:
WantedBy=default.target
WantedBy=graphical.target

This I just got in an email from another group but it may apply to you as you would see op25 on the screen. This may let that happen as the person who posted this in the group was for SDRTrunk which has a GUI for the program and by adding those lines, it would show up on screen.

RJ
 

boatbod

Member
Joined
Mar 3, 2007
Messages
3,339
Location
Talbot Co, MD
My op25 repo includes example scripts for running op25 at boot time using systemd (systemctl). I'm not sure this is quite going to do what you want, but you could define some systemd services with different configurations and then have your python script enable/disable the one you want to run. The command line interface to systemd is pretty easy.... "sudo systemctl start <servicename>", "sudo systemctl stop <servicename"
 

wgbecks

Active Member
Joined
Jan 17, 2005
Messages
922
Location
NE Wisconsin
Jay,

I may have posted this before but if you're moving about a P25 zone system as in operating op25 mobile then there is another option
available to you. Simply configure your trunk.tsv with the known control channel frequencies of the adjacent areas in your route of
travel and set the NAC field to 0x0 whereby the Boatbod version of op25 will accept the first NAC it sees when syncing up with an active
control channel.

I have been using this option for a few years now and it works quite well. Be sure when roaming to include the desired TGID's in your
whitelist if using one. Keep in mind that as your drive out of radio range of one site and into the coverage of another that it will take several seconds for the CC expiry to time out and begin searching the list of CC's populated in trunk.tsv and to resume trunk tracking.

Bill
 

Carter911

Member
Joined
Aug 17, 2021
Messages
59
Hello RJ, Boatbod, and Bill,
Thank you for your assistance!

I'll have to study both RJ's and Boatbod's approaches carefully and see what I can get up and running.
I appreciate the examples.
As a beginner what is obvious to a more experienced user, who says: "Well that's simple, you just do X, Y, & Z", can still be incomprehensible.
Examples help to solidify the descriptions!

Bill, my Kenwood, for my Summit County work, still picks up Summit County when I'm in Lake County.
My Motorola, for my Lake County work, still picks up Lake County when I'm in Summit County.
Although I've not yet tried it, it isn't clear to me that I'll actually lose the county A's control channel when I'm in county B, and vice versa.
That said, sometimes one just has to give something a try to see what actually happens.
I guess one could back down the RF gain and use a crummy antenna, but that seems counter-intuitive and like a real hack to make it work.

Who'd of thought auto-starting on boot up and real time / pseudo-real time mode switching would prove to be challenging, above the normal learning curve challenges!

Thanks again!

Jay
 

rjdj2000

Gone Cuckoo
Feed Provider
Joined
Jan 24, 2011
Messages
347
Location
Central NY
No worries and trust me I am also a beginner when it comes to linux and it's commands. I did a lot of searching online and trial and error to get it to work, had to nuke the sd card a couple times actually to get not only op25 installed but to get the start @ boot portion to work.

I try to help when I can and always somehow learn something new or a new way of doing something by someone else who has more knowlledge chiming in on it.

RJ
 

Carter911

Member
Joined
Aug 17, 2021
Messages
59
Hello Everyone,

I’ve been working on having OP-25 Boatbod run on Boot-up using the system service as mentioned above.

I have two script files.sh that call my rx.py … parameters… command.

One with the Terminal Interface.

One with the web interface.

Both work if I call my script.sh file from a command line in a terminal.

One shows the talk groups in the terminal, the other shows them in the web interface.

Both play the audio through the USB Audio.

I have a system service set up to run my above script files, (one or the other, depending upon the test being done).

I can see that the Service starts.

On the web interface version, the web interface is alive, and shows the talk groups as expected.

Neither version, terminal or web interface, however, will play the USB Audio when started through the system service method.

I saw in Boatbod’s example several After=…

After=syslog.target network.target nss-lookup.target network-online.target

Requires=network-online.target


I wondered if there is something else I needed to add to make sure that the RPi’s USB Audio driver is installed before the rest of the OP-25 program loads?


Rjdj2000, above, used User=dani

Boatbod has User=1000, Group=1000

I’ve tried both ways, (With my default pi user, and with the 1000).

That change made no difference.

I’m open to any further suggestions regarding auto-startup of OP-25 Boadbod and figuring out why the USB audio isn’t working.


Thank you!

Jay
 

wgbecks

Active Member
Joined
Jan 17, 2005
Messages
922
Location
NE Wisconsin
Jay,

Just a shot in the dark, but I am going to assume for the moment that you're running one of the Desktop (GUI) versions of Raspbian OS that is packaged with pulseaudio (PA), or that you have installed PA intentionally in support your USB sound device? Either way, PA usually works
fine so long as you're logged in but fails to run when starting applications using it as a system service.

Depending upon the specific Raspbian OS, I've had good success starting PA with a simple entry placed in the crontab that runs at boot time
that works as a workaround to start PA without actually having to be logged in.

crontab -e
@reboot pulseaudio --start [Add this line at the end of the existing file, save, and reboot your Pi]


Bill
 
Last edited:

rjdj2000

Gone Cuckoo
Feed Provider
Joined
Jan 24, 2011
Messages
347
Location
Central NY
Jay,

Not sure on the user part as the user on my pi is pi. I changed things to what I needed and it worked. Now I have changed things and went to the multi_rx.py on mine and once again I am trying to figure it all out as nothing I am doing is working. I have tried crontab, systemd, .rc.local and I have yet to get it to start at boot. I just need to get away from it for a bit and then come back to it as I am missing something somewhere and can't figure it out. I even looked at boatbod's examples of the systemd files, put that in using what I needed to run it and still couldn't get it to run.
 

Carter911

Member
Joined
Aug 17, 2021
Messages
59
Bill,

Yes, I am running the "recommended" RPi OS from the installer, 32 bit, with a GUI.
Sorry, I don't know its name, I downloaded this as a fresh build a couple weeks ago.

Eventually I will likely want to run this project as a headless system, in which I might give Rasp Lite (?) a try.
For now, however, I like having the KB/Mouse/Monitor available.
I also wanted to make sure that any difficulties were from my end, and not from missing any required support files.

I will give the Pulse Audio in crontab a try later to day!
Thank you!

rjdj,

Thank you for your interest and support. Sorry to hear that you, also, are having trouble with the auto start on bootup.
I've not (yet / ever ?) switched to the multi-rx version. Thus far I've not needed its capabilities.

JC
 

rjdj2000

Gone Cuckoo
Feed Provider
Joined
Jan 24, 2011
Messages
347
Location
Central NY
Jay,

Yeah it is weird that I got the rx.py to work just fine through systemd setup but not the multi_rx. I messed with the systemd files that boatbod has in his repro this morning but with talking to someone else on it I might not have a flag in the command as my situation would not have keyboard, mouse attached. So I am going to go through his files on the repro tonight and see if I can just duplicate things but using my information that I need. If you like, send me a PM with the command you start rx.py and I can create what goes into the file(s) for you (will need to know the username on the Pi and the complete directory of rx.py (I am thinking it is this: /home/<your username>/Downloads/op25/op25/gr_op25_repeater/apps/) As I was sucessful in getting rx.py to run @ boot.

BTW, what is your LED flasher program? I am doing what I am to eventually put the PI into an old Bearcat III scanner chassis and use it for nostalgia with the LED's scanning away and the Pi controlling the LED as well as running OP25 to listen to the local P25 system.
 

wgbecks

Active Member
Joined
Jan 17, 2005
Messages
922
Location
NE Wisconsin
rjdj2000,

I believe that I might be able to steer you in the right direction to get multi_rx.py to run from a system service. I've not seen your
JSON file but will have to assume that you have the "teminal_type":"curses" set that works perfectly well so long as you are logged in
and are executing your startup script from the command line (local terminal).

However, that option is not valid when executing a script from a system service that calls your multi_rx.py JSON as there is no longer
a terminal attached to op25. In this instance you'll need to comment out the curses terminal option and enable the http terminal
option and should have been evident in the logfile entry that would have been written prior to the abort of execution.

Keep in mind the http terminal defaults to using the internal network loopback IP of 127.0.0.1 that only supports connection from
a browser on the local machine. You'd to configure the IP to 0.0.0.0 before you would be able to open the http terminal form a browser
on another machine across your network while observing that there is no login security in place.

Here's how I have my JSON files configured when running them from a script under control of a system service. Be sure to restore the
original example op25-rx.service that @boatbod provided in his op25 distribution.

},
"terminal": {
"module": "terminal.py",
"#terminal_type": "curses",
"terminal_type": "http:0.0.0.0:8080",

"curses_plot_interval": 0.1,
"http_plot_interval": 1.0,
"http_plot_directory": "../www/images",
"tuning_step_large": 1200,
"tuning_step_small": 100
}

Bill
 
Last edited:

rjdj2000

Gone Cuckoo
Feed Provider
Joined
Jan 24, 2011
Messages
347
Location
Central NY
rjdj2000,

I believe that I might be able to steer you in the right direction to get multi_rx.py to run from a system service. I've not seen your
JSON file but will have to assume that you have the "teminal_type":"curses" set that works perfectly well so long as you are logged in
and are executing your startup script from the command line (local terminal).

However, that option is not valid when executing a script from a system service that calls your multi_rx.py JSON as there is no longer
a terminal attached to op25. In this instance you'll need to comment out the curses terminal option and enable the http terminal
option and should have been evident in the logfile entry that would have been written prior to the abort of execution.

Keep in mind the http terminal defaults to using the internal network loopback IP of 127.0.0.1 that only supports connection from
a browser on the local machine. You'd to configure the IP to 0.0.0.0 before you would be able to open the http terminal form a browser
on another machine across your network while observing that there is no login security in place.

Here's how I have my JSON files configured when running them from a script under control of a system service. Be sure to restore the
original example op25-rx.service that @boatbod provided in his op25 distribution.

},
"terminal": {
"module": "terminal.py",
"#terminal_type": "curses",
"terminal_type": "http:0.0.0.0:8080",

"curses_plot_interval": 0.1,
"http_plot_interval": 1.0,
"http_plot_directory": "../www/images",
"tuning_step_large": 1200,
"tuning_step_small": 100
}

Bill

Bill,

Thanks for the reply. If I can, may I PM you on it? I hate to take over Jay's thread for my issue. Can send you the json file tonight on it.

RJ
 

Carter911

Member
Joined
Aug 17, 2021
Messages
59
Sigh...

I put the pulseaudio in the crontab, as per above, rebooted, but unfortunately although the OP-25 Boatbod web interface is alive and showing the TG's, there is no audio when I start the OP-25 calling script file through system service.
From the Terminal I "start" the service, and then I check its "status", and this looks good, (to me).

The OP-25 script works fine when it is run from a terminal's command line.
The web interface is alive and shows the TG's, the audio plays through the USB audio option, all as expected and desired.

I plugged in an HDMI display that includes speakers, changed the audio via the RPi icon, started the service, and again the web interface is fine, but no audio plays.

So, for completeness, I plugged a speaker into the RPi's Audio Jack and THERE IS AUDIO.
The RPi speaker icon still says that the audio is routed to the USB.
The RPi speaker icon volume control doesn't change the volume coming out of the Audio jack.

But, interestingly, OP-25 is alive!
Web interface is active, showing the TG's.
The audio is being routed to the RPi's audio jack, (regardless of the RPi icon settings).

So, one step forward!
(But very confusing, to me)

rjdj, I'd be glad to share my LED flasher.
It's a little "off topic", but hey, it's my thread!

I'll post it shortly.

Bill, any other thoughts on the Linux / OP-25 audio systems?

I was Googling for ways to access the pulseaudio status, but although I see many threads on it, none that really demonstrate how to pop up a status report.

Jay
 

Carter911

Member
Joined
Aug 17, 2021
Messages
59
rjdj,

All is good, I share my Threads!
Besides, its all about OP-25 related issues.

JC
 

rjdj2000

Gone Cuckoo
Feed Provider
Joined
Jan 24, 2011
Messages
347
Location
Central NY
rjdj,

All is good, I share my Threads!
Besides, its all about OP-25 related issues.

JC
LOL Ok... Just hate hijacking threads is all and yes it is all OP25 related but when everyone gets going it can get confusing as to what you should be doing... Then you end up getting more lost... trust me I know.... I've gotten lost in linux on more than one occasion...LOL
 

Carter911

Member
Joined
Aug 17, 2021
Messages
59
RPi Breakout TB V2.jpg

I'll deviate for a minute from my OP-25 audio on start up via system services issue.

rjdj,
The above is the testbed hardware for the RPi, (3 B+), that I am using to learn Python, (as well as Linux, and the OP-25 parameters, and, and, and...).

The overall project is to put an OP-25 Boatbod scanner in my car.
The "issue" is that an RPi runs Linux, and one ought not just pull power without shutting it down gracefully.
Remembering to shut it down, nicely, is a hassle, and I wish to automate the process.

The project will, (eventually), have a small LiPo battery and an AVR microcontroller to watch when the car's power to the RPi is lost, (power is turned off, vehicle turned off, etc.).
The RPi will continue running on the battery, and the AVR micro will trigger the RPi to shut down via one of the RPi's I/O pins.

I still need to measure the RPI and RTL-SDR's current draw when the RPi is "off", following its shutdown.
If it is too high, then the circuit can have a "high side driver" to turn the power totally off to the RPI + RTL, or even go old school and use a small relay. One would like to minimize the "stand-by" current drawn by the system so as not to drain the car's battery if the car sits unused for a few days, especially in cold weather.

Anyway, the two LED flasher programs are my 2nd and 3rd(-ish) Python programs, following the mandatory "Hello World".
The first literally just configures the RPI's I/O and flashes the LEDs.
The second one is the interesting one.
It sets up an Interrupt that fires when the push button switch is pressed.
It then tells the RPi to shut down, now.
The RPi can then close its running programs and go through its desired shut down sequence.
The push button shut down uses essentially no RPi processing power when not in use due to its being interrupt driven.

The program also reads a couple of on/off slide switches to select 1 of four states, (both off, 1 on, other on, both on).
It then can execute whatever command is desired, based upon the "Mode" selected.

This LED flasher program is loaded to run on boot-up through the crontab file.
So every time the RPi boots up, the system is up and running.

I envision this program using the system service capabilities to auto-start various configurations of the OP-25 program, based upon the Mode setting, (the two slide switches, for now, but could be a front panel rotary Mode switch, or a push button toggle through the modes, etc.).

Thus far, I have OP-25 Boatbod up and running when I manually start the program through the command line on a terminal.
(Thank you, again, to the various OP-25 programmers, you guys are amazing!)

The project is slowly coming along, one (painful) step at a time!

I'll post the LED Flasher programs when I am back on the other computer.

Jay
 

lwvmobile

DSD-FME
Joined
Apr 26, 2020
Messages
1,272
Location
Lafayette County, FL
I've shared this before, but I'll share it again. You can use the GPIO pins and a momentary switch to signal the Raspberry Pi to gracefully shutdown.

 
Status
Not open for further replies.
Top