Pulseaudio output sink does not exists until user get logged in to X window environment - audio

Setup:
Embedded target device: Rock5B (ARM64)
Linux: Debian 11
Bluetooth stack: Bluez
Audio: Pulseaudio
Window environment: Xfce
I'm writing a Bluetooth application which connects to a headset.
If I manually log into window environment with user credentials and do manual Bluetooth pairing and select manually the output sink it does work as expected.
The same happens if I log into window environment and I run my application remotely using SSH which connects to Bluetooth headset and run the script remotely using SSH and selecting the output sink number 3 (which in that case is Bluetooth headset):
pacmd set-default-sink 3.
On the other hand if the device get started but I do not log into window environment but instead just run same steps remotly using SSH then Blutooth pairing is completed but the Pulseaudio sink number 3 is not present.
I have tried after restart to first run the Pulseaudio manually:
pulseaudio -k
pulseaudio -D
and after that I have run remotely using SSH my app and then select the sink with pacmd. Now pacmd found and selected the sink but when I tried to run the audio file remotely there was no audio output:
PULSE_SERVER=127.0.0.1 cvlc audo.wav
Again if I log into the window environment run everything remotely and run above cvlc the audio is working fine.
Something needs to be setup more than that when windows environment is starting but I can not figure what.

Related

Running a systemd service without sudo privileges

I have a PC that transmits log data over a TCP/IP socket to a Raspberry Pi. I have written a python server program that runs on the Pi, so that when certain keywords are encountered, it has to play the corresponding audio track - this is a gist of the problem I'm currently working on.
Now, I want this server program to run as soon as the Raspberry Pi boots up, and so I wrote a systemd service to enable that. Assuming my server code is named as server.py, my service file looks as follows:
[Unit]
Description=Python Server
[Service]
# Command to execute when the service is started
ExecStart=/usr/bin/python3 -u /usr/bin/server.py
[Install]
WantedBy=multi-user.target
I make this server program executable, and I don't face any issues to start and enable the service (verified by rebooting the Pi as well). Now, taking a step back, I play the audio track on the python server program using the following lines (a little snippet):
import subprocess
subprocess.run(["cvlc", "~/Downloads/doors.wav"])
No errors here, all good. But when the service that runs the server program is started, when the specific keyword is encountered, the audio track does not play - it shows an error:
: [00005565470df480] vlcpulse audio output error: PulseAudio server connection failure: Connection refused
: [0000556547157310] dbus interface error: Failed to connect to the D-Bus session daemon: Unable to autolaunch a dbus-daemon without a $D
: [0000556547157310] main interface error: no suitable interface module
: [000055654700c570] main libvlc error: interface "dbus,none" initialization failed
: [0000556547101460] main interface error: no suitable interface module
: [000055654700c570] main libvlc error: interface "globalhotkeys,none" initialization failed
: [0000556547101460] dummy interface: using the dummy interface module...
: [00007f5f98c0b610] idummy demux: command `quit'
This same error shown above occurs when I try to play the audio from the command line with sudo, that is:
cvlc ~/Downloads/doors.wav
which led me to believe that if the service is enabled, then the whole python program corresponding to the service is run with sudo privileges automatically, even if I don't intend that to happen. I did a little bit of digging, but based on what I understand, to run the service, sudo privilege is necessary. I was not able to find a solution to run vlc with sudo, although I understand that ideally sudo privileges should not be given to something such as vlc. Is there a way around this?
This is happening because the PulseAudio server runs under your user, not as root. The service you are starting runs as root and tries to connect to root's PulseAudio server.
You can run specify which user/group to run the service as under the [Service] section with the User and Group directives.
You can also run the service as your user like this:
$ systemctl start --user <service>.service

ubuntu mate will not log on after changing one of my init login scripts

I was having some issues with switching my audio output (ie I plug in HDMI, if an application is currently running its audio through the computer's speakers, the audio does not move to the HDMI unless I kill the pulseaudio session and restart the program) and tried adding some scripts that run at login but can't remember what they are (not smart). I know I put, for example, pulseaudio -k somewhere.
Anyway, I get to a login screen as usual but after I enter my credentials it flashes the dell screen then goes right back to login. I can login using the terminal. I am certain that I broke my system when adding these custom scripts as something related to them comes up after I login using the terminal.
I just want to basically reset my desktop without losing my files, and perhaps internet bookmarks, as I have given up on trying to see where the offending code is, but if there is an easy way to find this then I'm all ears. Maybe there is a way, for example, to restore my desktop to its factory settings from the terminal without touching my documents?
Ubuntu 19.10 PHILLIP-Precision-5520 tty
PHILLIP-Precision-5520 login: PHILLIP Password:
Last login: Sun Apr 19 13:46:31 EDT 2020 on tty4 Welcome to Ubuntu 19.10 (GNU/Linux 5.3.0-46-generic x86_64)
* Management:
* Support:
* Documentation: https://help.ubuntu.com https://landscape.canonical.com https://ubuntu.com/advantage
0 updates can be installed immediately.
0 of these updates are security updates.
Failed to connect to https://changelogs.ubuntu.com/meta-release. Check your Internet connection or proxy settings
Failed to kill PulseAudio daemon.
Toggling output devices (Speakers/Headset) No PulseAudio daemon running, or not running as session daemon.
No PulseAudio daemon running, or not running as session daemon.
No PulseAudio daemon running, or not running as session daemon.
No PulseAudio daemon running, or not running as session daemon.
Moving input: to sink:
Setting default sink to:
Can't open display E: (pulseaudio) main.c: Failed to kill daemon: No such process PHILLIP (master #) $ ==

Reloading code onto raspberry pi 3 and running it

I am currently writing a program that detects if an IoT is compromised (i.e sending information its not supposed to). When this behaviour is detected by the control server, it will then get the device to reset by downloading its uncompromised code functions (which i have on a cloud) and running them. Is there a way to do this. Im using nodejs on my raspberry by the way.
Is there a way to shutdown or reboot a raspberry pi via a script?
You can issue the command:
ssh <user>#<ip address to Pi> 'echo <password> | sudo <full path to shutdown command> -r now'
Replace with the Pi's username, replace with the password, and that path to shutdown (which you can find while connected to the Pi do which shutdown). And fill in the IP address to your PI.
That should reboot your Pi.

Bluetooth OPP profile - 'Client proxy not available'

I'm trying to enable the bluetooth OPP profile in my linux machine(Ubuntu-16.04 LTS) to connect it with android phone.
Initially I enabled the bluetooth interface using the command, /etc/init.d/bluetooth start
Began to scan for the devices to connect, using the hcitool scan that displays both device 'Bluetooth MAC address and Username'
I paired my PC with the device (Redmi note 4-Android Nougat) using the command hcitool cc --role=s <br_addr>
Then I executed the command the sudo obexctl, which lead to the interactive mode,
[obex]# connect <br_addr>
On connecting to the device using its bluetooth MAC address, following error is thrown,
Client proxy not available
Hope this link would be useful as it explains what the exact output is supposed to be like.
https://docs.ubuntu.com/core/en/stacks/bluetooth/bluez/docs/reference/sending-files
Yes, I just now figured out the answer for my own question(thought to leave the question undeleted as it may help someone encountering the same situation)
Before intialising the bluetooth services, got to run the daemon,
sudo service bluetooth stop
sudo systemctl daemon-reload
sudo service bluetooth start
sudo hciconfig -a hci0 reset
So now good to go, the obexctl command can be executed. Once entered into the interactive mode, connections can be made and the file could be pushed or pulled as mentioned in the link.

enable HDMI port after Disable it with shell programing in raspberry pi 3

I used a raspberry pi 3 model b v1.2. raspberry connected to a TV with HDMI port. I want to disable and enable HDMI port with shell program. I use this code for doing that. also, i install a teamviewer in raspberry and can control that with my laptop. when i run sh rpi-hdmi.sh off in terminal, HDMI port disable correctly and see this message in terminal:
Power off HDMI
but when i run sh rpi-hdmi.sh on, i see in TV that clear "no signal" message. but it not showing anything and i see just black tv.
when i run sh rpi-hdmi.sh on for first one, i see this message:
Power on HDMI with preferred settings
Couldn't get a file descriptor referring to the console
but for second one, i see just this message:
Power on HDMI with preferred settings
What must i do, for showing desktop in TV after enable HDMI port?
When you run sh rpi-hdmi.sh on, the line of tvservice -p need some time to run correctly. if you want to enable HDMI port quickly, you may run this code:
tvservice -p
xset dpms force on

Resources