device use:
pi zero 2 W
OS - Legacy
I got this bash code
I created a cron job using
crontab -e and add the followingnow when I do reboot the devices it does connect to the bluetooth since I can tell from the speaker but the problem is that on the checking or setting the bluetooth sink it's not working when listing devices the bluetooth is not found below is the complete logs
pi zero 2 W
OS - Legacy
I got this bash code
Code:
#!/bin/bash# Function to list all output devicesfunction list_output_devices() { pactl list short sinks}# Function to connect to Bluetooth devicefunction connect_to_bluetooth_device() { local mac_address="$1" echo -e "connect $mac_address\nquit" | bluetoothctl > /dev/null}# Function to check if Bluetooth device is connectedfunction check_bluetooth_connection() { local mac_address="$1" bluetoothctl info "$mac_address" | grep -q "Connected: yes" return $?}# Redirect output to log fileexec &> /home/admin/devices.logecho "starting pulseaudio"pulseaudio --startaconnect -x# Connect to Bluetooth devicemac_address="CC:14:BC:32:F9:39" # Replace with the MAC address of your Bluetooth deviceecho "Connecting to Bluetooth device: $mac_address"echo connect_to_bluetooth_device "$mac_address"sleep 2# Wait for Bluetooth connection to stabilizeecho "Waiting for Bluetooth connection to stabilize..."sleep 5# Check if Bluetooth device is connectedecho "Checking Bluetooth connection status..."check_bluetooth_connection "$mac_address"#if [ $? -eq 0 ]; then# echo "Bluetooth device is connected."#else# echo "Bluetooth device is not connected."#fi# Start PulseAudio#echo "Starting PulseAudio"#pulseaudio --startsleep 5# List all output devicesecho "Listing all output devices:"list_output_devices# Set the Bluetooth device as default outputbluetooth_sink="bluez_sink.CC_14_BC_32_F9_39.a2dp_sink"echo "Setting default output to Bluetooth device: $bluetooth_sink"pactl set-default-sink "$bluetooth_sink"# Show confirmation messageecho "Bluetooth device set as default output."# List output devices againlist_output_devices
I created a cron job using
crontab -e and add the following
Code:
@reboot sleep 15 && /bin/bash /home/admin/con.sh >/home/admin/cron.log 2>&1
Code:
starting pulseaudioW: [pulseaudio] main.c: This program is not intended to be run as root (unless - -system is specified).Connecting to Bluetooth device: CC:14:BC:32:F9:39connect_to_bluetooth_device CC:14:BC:32:F9:39Waiting for Bluetooth connection to stabilize...Checking Bluetooth connection status...Listing all output devices:0 auto_null module-null-sink.c s16le 2ch 44100Hz SUSPENDE DSetting default output to Bluetooth device: bluez_sink.CC_14_BC_32_F9_39.a2dp_si nkFailure: No such entityBluetooth device set as default output.0 auto_null module-null-sink.c s16le 2ch 44100Hz SUSPENDE D
Statistics: Posted by mugichan — Tue May 07, 2024 12:14 pm — Replies 0 — Views 32