cbkn76
Posts: 9
Joined: Wed Mar 20, 2019 3:40 pm

Bluetooth issue when python script run from boot console

Fri Jul 12, 2019 8:38 pm

First off, my apologies for any confusing details I post, I am new to raspbian and all the nomenclature. I have searched for a few days online, but unable to find a solution as most of the search results refer to all the general Bluetooth issues, which i have had and fixed. I wouldn’t be asking now if I wasn’t at the end of my rope.
Pi 3b+


I have a python script on raspberry pi. The script has a function that plays a wav/mp3 over Bluetooth speaker and worked fine.
when the script is set to run on boot from console the Bluetooth speaker connects, but will not play sound. The full path to the wav/MP3’s are in the python script.

Any and all help is appreciated.

User avatar
neilgl
Posts: 621
Joined: Sun Jan 26, 2014 8:36 pm
Location: Near Aston Martin factory

Re: Bluetooth issue when python script run from boot console

Fri Jul 12, 2019 9:07 pm

Ah, how are you setting the script to run on boot?

Andyroo
Posts: 3756
Joined: Sat Jun 16, 2018 12:49 am
Location: Lincs U.K.

Re: Bluetooth issue when python script run from boot console

Fri Jul 12, 2019 9:31 pm

My guess is a user / path issue

This may help https://www.dexterindustries.com/howto/ ... t-startup/ but please do not let that stop you posting details as requested above :lol:
Need Pi spray - these things are breeding in my house...

cbkn76
Posts: 9
Joined: Wed Mar 20, 2019 3:40 pm

Re: Bluetooth issue when python script run from boot console

Fri Jul 12, 2019 9:40 pm

Thanks for responding,

Using .bashrc

Code: Select all

sudo python3 /home/pi/keypad_rpi/test_rfid.py

Just to be clear the code runs on boot and performs other functions , but does not play the sound. No errors appear and the code keeps running.

User avatar
Douglas6
Posts: 4710
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

Re: Bluetooth issue when python script run from boot console

Fri Jul 12, 2019 9:44 pm

My guess is that the Bluetooth stack is not established, or the speaker is not connected when the program needs them. Try adding a 20-second pause to the start of your script.

cbkn76
Posts: 9
Joined: Wed Mar 20, 2019 3:40 pm

Re: Bluetooth issue when python script run from boot console

Fri Jul 12, 2019 9:46 pm

Andyroo wrote:
Fri Jul 12, 2019 9:31 pm
My guess is a user / path issue

This may help https://www.dexterindustries.com/howto/ ... t-startup/ but please do not let that stop you posting details as requested above :lol:
I was going to add that the user/ permissions may be an issue as my developer had several of these issues when starting the script on boot.

Also wondered if pulse audio is running at boot, but no idea on how to check.

cbkn76
Posts: 9
Joined: Wed Mar 20, 2019 3:40 pm

Re: Bluetooth issue when python script run from boot console

Fri Jul 12, 2019 10:02 pm

Douglas6 wrote:
Fri Jul 12, 2019 9:44 pm
My guess is that the Bluetooth stack is not established, or the speaker is not connected when the program needs them. Try adding a 20-second pause to the start of your script.
Would that look like this?

Code: Select all

sleep 20 sudo python3 /home/pi/keypad_rpi/test_rfid.py 

User avatar
Douglas6
Posts: 4710
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

Re: Bluetooth issue when python script run from boot console

Fri Jul 12, 2019 10:20 pm

No, I believe it's

Code: Select all

sleep 20; sudo python3 /home/pi/keypad_rpi/test_rfid.py 
with a semicolon between commands. Or you can put a sleep() at the top of the Python script.

Andyroo
Posts: 3756
Joined: Sat Jun 16, 2018 12:49 am
Location: Lincs U.K.

Re: Bluetooth issue when python script run from boot console

Fri Jul 12, 2019 10:30 pm

Any reason you need to run under SUDO?

It’s never good practise as a mistake can access all files etc :lol:
Need Pi spray - these things are breeding in my house...

cbkn76
Posts: 9
Joined: Wed Mar 20, 2019 3:40 pm

Re: Bluetooth issue when python script run from boot console

Fri Jul 12, 2019 10:30 pm

Added the sleep 20 and it still doesn’t work,

Also added echo Running at boot just above that, no dice.


Any other ideas???

User avatar
neilgl
Posts: 621
Joined: Sun Jan 26, 2014 8:36 pm
Location: Near Aston Martin factory

Re: Bluetooth issue when python script run from boot console

Sat Jul 13, 2019 7:43 pm

Can you post the script in full so we can test it. Thanks.

fbe
Posts: 483
Joined: Thu Aug 17, 2017 9:08 pm

Re: Bluetooth issue when python script run from boot console

Sat Jul 13, 2019 8:08 pm

Andyroo wrote:
Fri Jul 12, 2019 10:30 pm
Any reason you need to run under SUDO?
Your recommended help.
Andyroo wrote:
Fri Jul 12, 2019 9:31 pm
...
This may help https://www.dexterindustries.com/howto/ ... t-startup/
...
...
Sudo, sudo, sudo, lovely sudo
Wonderful sudo, lovely sudo
...
cbkn76 wrote:
Fri Jul 12, 2019 10:30 pm
Any other ideas???
Is the sound coming over the audio jack or HDMI instead?

cbkn76
Posts: 9
Joined: Wed Mar 20, 2019 3:40 pm

Re: Bluetooth issue when python script run from boot console

Tue Jul 16, 2019 5:01 am

I can get sound through hdmi, and its finicky, but I can occasionally get Bluetooth sound, but never when the script is run at boot from console.

By the way, I removed sudo and the script still ran, so I left sudo.


I’m a novice at this, can anyone recommend somewhere where I can hire someone to work on this? I tried a couple of people on Fiverr, they can’t fix, but say it is definitely not the script. Need a little higher caliber than fiverr

fbe
Posts: 483
Joined: Thu Aug 17, 2017 9:08 pm

Re: Bluetooth issue when python script run from boot console

Tue Jul 16, 2019 7:45 pm

You were asked to post the script in full (or the link to the source where you found the script and other instructions that you are following)...

Return to “Troubleshooting”