ultrarunner2018
Posts: 38
Joined: Sat Aug 04, 2018 1:59 pm

Start SoundWire Server on boot?

Thu Aug 16, 2018 5:22 pm

Hi;
I am trying to start SoundWire Server at boot on a pi 3 b+ running stretch.
I have done a lot of Googling, and found that there are several methods of running a program at startup. The one I am trying now is to add the command line to rc.local.

I have the following line in rc.local:

/home/fw2019/soundwire/SoundWireServer &

I also tried it with "./" at the start of the path, but it doesn't do anything different than it does without the "."

I believe that SoundWireServer is starting, but it is not connecting to the network (and internet). I know this because when I try to run it again, I get the error that the port is busy; another instance of SoundWireServer may be running.

But I am unable to connect to SoundWire from my Android phone when it is started from rc.local.
If I kill the process, then start it manually, it works fine.

So, I think what I need to do is have SoundWireServer wait until the network is up and connected to the internet before starting.
I don't have a lot of experience with scripts, or with using rc.local, but I know enough about programming to understand how it might work.

Thanks for your help

Ultrarunner

klricks
Posts: 5778
Joined: Sat Jan 12, 2013 3:01 am
Location: Grants Pass, OR, USA
Contact: Website

Re: Start SoundWire Server on boot?

Thu Aug 16, 2018 11:57 pm

There is an option to wait for network at boot in sudo raspi-config
If that does not work then you could start your program with a simple bash script in rc.local .
This will delay 3 seconds then start your program:

Code: Select all

#!/bin/bash
sleep 3  # Adjust time as needed.
/home/fw2019/soundwire/SoundWireServer
Be sure to use the full path everywhere.
Unless specified otherwise my response is based on the latest and fully updated Raspbian Stretch w/ Desktop OS.

ultrarunner2018
Posts: 38
Joined: Sat Aug 04, 2018 1:59 pm

Re: Start SoundWire Server on boot?

Sat Aug 18, 2018 10:21 pm

klricks wrote:
Thu Aug 16, 2018 11:57 pm
There is an option to wait for network at boot in sudo raspi-config
If that does not work then you could start your program with a simple bash script in rc.local .
This will delay 3 seconds then start your program:

Code: Select all

#!/bin/bash
sleep 3  # Adjust time as needed.
/home/fw2019/soundwire/SoundWireServer
Be sure to use the full path everywhere.
Thanks!
I also realized that I need to be logged into the pi in order for the audio stream to reach the SoundWire Server.
I am using an Audio Injector Stereo Soundcard.
If I log into the pi using SSH from my Ubuntu box, I can start SoundWire Server (manually), but I get no audio until I go to the pi console (either directly or using Real VNC) and log in. I should be able to do that in the bash script as well, right?

I think with the info you have provided me, I can make this work.

klricks
Posts: 5778
Joined: Sat Jan 12, 2013 3:01 am
Location: Grants Pass, OR, USA
Contact: Website

Re: Start SoundWire Server on boot?

Sat Aug 18, 2018 10:52 pm

ultrarunner2018 wrote:
Sat Aug 18, 2018 10:21 pm
klricks wrote:
Thu Aug 16, 2018 11:57 pm
There is an option to wait for network at boot in sudo raspi-config
If that does not work then you could start your program with a simple bash script in rc.local .
This will delay 3 seconds then start your program:

Code: Select all

#!/bin/bash
sleep 3  # Adjust time as needed.
/home/fw2019/soundwire/SoundWireServer
Be sure to use the full path everywhere.
Thanks!
I also realized that I need to be logged into the pi in order for the audio stream to reach the SoundWire Server.
I am using an Audio Injector Stereo Soundcard.
If I log into the pi using SSH from my Ubuntu box, I can start SoundWire Server (manually), but I get no audio until I go to the pi console (either directly or using Real VNC) and log in. I should be able to do that in the bash script as well, right?

I think with the info you have provided me, I can make this work.
Do you have auto login to user pi enabled?
Try a longer sleep time.
Try using sudo -u pi

Code: Select all

#!/bin/bash
sleep 3  # Adjust time as needed.
sudo -u pi /home/fw2019/soundwire/SoundWireServer
Unless specified otherwise my response is based on the latest and fully updated Raspbian Stretch w/ Desktop OS.

ultrarunner2018
Posts: 38
Joined: Sat Aug 04, 2018 1:59 pm

Re: Start SoundWire Server on boot?

Sun Aug 19, 2018 12:14 am

I don't think SoundWireServer is going to start properly from rc.local. When I add the line to start it, I cannot connect to the SW server. But when I attempt to start it (again) either from a terminal open on the pi console, or by SSH from Ubuntu, I get a message that SoundWireServer is already running.
I need to kill the process before restarting it, and only then can I make a connection from my phone.
But even if I do manage to get SW started at boot, it appears that something else needs me to be logged into the pi desktop before audio will stream from the Audio Injector Stereo Soundcard to SoundWire.
I thought it might be PulseAudio (required by SoundWire), but when I had the Behringer UMC202HD Audio Interface connected to the USB port on the pi, I could just start SoundWireServer from SSH; no need to login to the pi desktop. So it must be something to do with the sound card I am using now.

In the end, it is not critical that I have SoundWireServer starting on boot. I normally leave the pi running all day (and sometimes all night too), and have it powered from an Uninterruptable Power Supply, so even if the power fails for a few minutes, the pi won't reboot and it should continue to stream audio. Even if the pi should shut down, this is not a "mission-critical" application.

That said, the whole thing is a good learning process. I need to become familiar with Linux scripts, and the OS in general.

BTW: I think that I need to add the & to the end of the line to start SoundWireServer in rc.local (assuming it will start from there), as it is an infinite loop that will never return control to the script. I believe that without the &, the pi would hang forever on boot. But I could be wrong. I'm just not willing to try it right now.

Code: Select all

#!/bin/bash
sleep 3
/home/fw2019/soundwire/SoundWireServer &
exit 0
Edit: It's not pulseaudio that isn't starting until desktop login. When I kill that process, it automatically starts up again.

klricks
Posts: 5778
Joined: Sat Jan 12, 2013 3:01 am
Location: Grants Pass, OR, USA
Contact: Website

Re: Start SoundWire Server on boot?

Sun Aug 19, 2018 1:51 am

ultrarunner2018 wrote:
Sun Aug 19, 2018 12:14 am
.........

Code: Select all

#!/bin/bash
sleep 3
/home/fw2019/soundwire/SoundWireServer &
exit 0
Edit: It's not pulseaudio that isn't starting until desktop login. When I kill that process, it automatically starts up again.
I am not sure you understood that the above code needs to be put into a bash script file then the bash script is called in rc.local
The script must be put before the exit0

Code: Select all

bash /path_to_your_script/your_script
exit 0
If those commands are put directly into rc.local then it will not work as each line is executed in near parallel or the system does not wait for the sleep command to finish before starting the next command........ Do not put exit 0 in the script.

An alternate way to start a program at boot, (if you boot to desktop), is to use autostart. The autostart is executed way later in the boot process.

Code: Select all

nano /home/pi/.config/lxsession/LXDE-pi/autostart
Put your command at the end or if needed use a bash script file as explained above.
Unless specified otherwise my response is based on the latest and fully updated Raspbian Stretch w/ Desktop OS.

ultrarunner2018
Posts: 38
Joined: Sat Aug 04, 2018 1:59 pm

Re: Start SoundWire Server on boot?

Sun Aug 19, 2018 2:32 am

I got it to work by setting Autologin, as you suggested.
I didn't need the sleep command, as I decided to set wait for network in raspi-config.
So I just entered the line in rc.local, but I added the & at the end of that line so boot will continue while SWS is running.

I was a bit confused by your code

Code: Select all

#!/bin/bash
in the script. Isn't the # character used to comment a line?

In any case, I do need to do a lot of studying on this.

klricks
Posts: 5778
Joined: Sat Jan 12, 2013 3:01 am
Location: Grants Pass, OR, USA
Contact: Website

Re: Start SoundWire Server on boot?

Sun Aug 19, 2018 3:46 am

ultrarunner2018 wrote:
Sun Aug 19, 2018 2:32 am
I got it to work by setting Autologin, as you suggested.
I didn't need the sleep command, as I decided to set wait for network in raspi-config.
So I just entered the line in rc.local, but I added the & at the end of that line so boot will continue while SWS is running.

I was a bit confused by your code

Code: Select all

#!/bin/bash
in the script. Isn't the # character used to comment a line?

In any case, I do need to do a lot of studying on this.
You put what in rc.local?
If you are using autostart then put rc.local back to default. Use either rc.local or autostart, not both.

Code: Select all

#!/bin/bash
This is called a 'shebang'
It has special meaning when it appears as the 1st line in a script. It tells the command interpreter which program to use to execute the script.
If using python then the 'shebang' would be:

Code: Select all

#!/usr/bin/python
etc etc
If you have the 'shebang' line AND the file permissions of your script is set to execute, then you can start your script from the command line like this:

Code: Select all

/path/your_script
If the 'shebang' is missing and/or file permissions are not set to execute then you must start like this:

Code: Select all

bash /path/your_script
or for python:

Code: Select all

python /path/your_script
Unless specified otherwise my response is based on the latest and fully updated Raspbian Stretch w/ Desktop OS.

ultrarunner2018
Posts: 38
Joined: Sat Aug 04, 2018 1:59 pm

Re: Start SoundWire Server on boot?

Sun Aug 19, 2018 12:52 pm

This is what I added to rc.local:

Code: Select all

# start SoundWireServer
/home/fw2019/sws &
Note: I copied the file SoundWireServer to a file called sws and put that file in /home/fw2019 so that if I need to start it from the console, I don't have to type the longer filename.

In raspi-config, I set boot option to autologin to desktop, and I selected "wait for network to boot".

ultrarunner2018
Posts: 38
Joined: Sat Aug 04, 2018 1:59 pm

Re: Start SoundWire Server on boot?

Mon Aug 20, 2018 12:56 pm

I just found a caveat to having SoundWireServer starting at boot:
Although the Audio Injector Stereo Soundcard is capable of duplex operation; whereas two signals from two sources can be routed to two outputs, I found that when I have SoundWireServer starting at boot, I am unable to play audio from LXMusic player to the RCA or headphone outputs.
No error message is thrown, but the music just will not play, despite the player is actually playing the music (I can see the track time advancing).
When I kill the SoundWireServer's process, I can then play the music, and once the music is playing, I can restart SoundWireServer.

Seems to be a driver issue.

Return to “Advanced users”

Who is online

Users browsing this forum: No registered users and 6 guests