<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Bluetooth on Arshad Siddiqui</title><link>https://arshadhs.github.io/tags/bluetooth/</link><description>Recent content in Bluetooth on Arshad Siddiqui</description><generator>Hugo</generator><language>en-us</language><lastBuildDate>Tue, 13 Nov 2018 20:45:00 +0000</lastBuildDate><atom:link href="https://arshadhs.github.io/tags/bluetooth/index.xml" rel="self" type="application/rss+xml"/><item><title>Bluetooth Speaker</title><link>https://arshadhs.github.io/docs/technology/bluetoothspeakerraspberrypi/</link><pubDate>Tue, 13 Nov 2018 20:45:00 +0000</pubDate><guid>https://arshadhs.github.io/docs/technology/bluetoothspeakerraspberrypi/</guid><description>&lt;h1 id="raspberry-pi--connect-bluetooth-speaker">
 Raspberry Pi : Connect Bluetooth Speaker
 
 &lt;a class="anchor" href="#raspberry-pi--connect-bluetooth-speaker">#&lt;/a>
 
&lt;/h1>
&lt;p>Connecting Raspberry Pi to Mi Pocket Speaker 2&lt;/p>
&lt;pre tabindex="0">&lt;code class="language-pi@raspberrypi:~" data-lang="pi@raspberrypi:~">[bluetooth]# power on
Changing power on succeeded
[bluetooth]# agent on
Agent registered
[bluetooth]# scan on
Discovery started
[CHG] Controller B8:27:EB:79:F6:B7 Discovering: yes
[bluetooth]# default-agent
Default agent request successful
[CHG] Device 00:EC:0A:57:F2:65 LegacyPairing: yes
[bluetooth]# list
Controller B8:27:EB:79:F6:B7 raspberrypi [default]
[bluetooth]# devices
Device 5C:72:FE:B7:35:FD 5C-72-FE-B7-35-FD
Device 28:F0:76:0A:B9:7B 28-F0-76-0A-B9-7B
Device 00:EC:0A:57:F2:65 Redmi
[NEW] Device 74:A3:4A:15:DD:71 Mi Pocket Speaker 2
[bluetooth]# pair 74:A3:4A:15:DD:71
Attempting to pair with 74:A3:4A:15:DD:71
[CHG] Device 74:A3:4A:15:DD:71 Connected: yes
[CHG] Device 74:A3:4A:15:DD:71 UUIDs:
 00001108-0000-1000-8000-00805f9b34fb
 0000110b-0000-1000-8000-00805f9b34fb
 0000110c-0000-1000-8000-00805f9b34fb
 0000110e-0000-1000-8000-00805f9b34fb
 0000111e-0000-1000-8000-00805f9b34fb
[CHG] Device 74:A3:4A:15:DD:71 Paired: yes
Pairing successful
[CHG] Device 74:A3:4A:15:DD:71 Connected: no
[bluetooth]# info 74:A3:4A:15:DD:71
Device 74:A3:4A:15:DD:71
 Name: Mi Pocket Speaker 2
 Alias: Mi Pocket Speaker 2
 Class: 0x240404
 Icon: audio-card
 Paired: yes
 Trusted: no
 Blocked: no
 Connected: no
 LegacyPairing: yes
 UUID: Headset (00001108-0000-1000-8000-00805f9b34fb)
 UUID: Audio Sink (0000110b-0000-1000-8000-00805f9b34fb)
 UUID: A/V Remote Control Target (0000110c-0000-1000-8000-00805f9b34fb)
 UUID: A/V Remote Control (0000110e-0000-1000-8000-00805f9b34fb)
 UUID: Handsfree (0000111e-0000-1000-8000-00805f9b34fb)
[bluetooth]# trust 74:A3:4A:15:DD:71
[CHG] Device 74:A3:4A:15:DD:71 Trusted: yes
Changing 74:A3:4A:15:DD:71 trust succeeded
[bluetooth]# info 74:A3:4A:15:DD:71
Device 74:A3:4A:15:DD:71
 Name: Mi Pocket Speaker 2
 Alias: Mi Pocket Speaker 2
 Class: 0x240404
 Icon: audio-card
 Paired: yes
 Trusted: yes
 Blocked: no
 Connected: no
 LegacyPairing: yes
 UUID: Headset (00001108-0000-1000-8000-00805f9b34fb)
 UUID: Audio Sink (0000110b-0000-1000-8000-00805f9b34fb)
 UUID: A/V Remote Control Target (0000110c-0000-1000-8000-00805f9b34fb)
 UUID: A/V Remote Control (0000110e-0000-1000-8000-00805f9b34fb)
 UUID: Handsfree (0000111e-0000-1000-8000-00805f9b34fb)
[bluetooth]# quit

pi@raspberrypi:~ $ sudo apt-get update &amp;amp;&amp;amp; sudo apt-get install pulseaudio -y
pi@raspberrypi:~ $ mkdir -p scripts
pi@raspberrypi:~ $ vim scripts/autopair
#!/bin/bash
bluetoothctl &amp;lt;&amp;lt; EOF
connect [enter your MAC add]
EOF
pi@raspberrypi:~ $ chmod +x !$
chmod +x scripts/autopair
pi@raspberrypi:~ $ sudo vim /boot/config.txt
#dtparam=audio=on
pi@raspberrypi:~ $ vim ~/scripts/on.py
#!/usr/bin/python
&lt;/code>&lt;/pre>&lt;h2 id="monitor-removal-of-bluetooth-reciever">
 Monitor removal of bluetooth reciever
 
 &lt;a class="anchor" href="#monitor-removal-of-bluetooth-reciever">#&lt;/a>
 
&lt;/h2>
&lt;pre tabindex="0">&lt;code class="language-import" data-lang="import">import sys
import subprocess
import time
def blue_it():
 status = subprocess.call(&amp;#39;ls /dev/input/event0 2&amp;gt;/dev/null&amp;#39;, shell=True)
 while status == 0:
 print(&amp;#34;Bluetooth UP&amp;#34;)
 print(status)
 time.sleep(15)
 status = subprocess.call(&amp;#39;ls /dev/input/event0 2&amp;gt;/dev/null&amp;#39;, shell=True)
 else:
 waiting()
def waiting():
 subprocess.call(&amp;#39;killall -9 pulseaudio&amp;#39;, shell=True)
 time.sleep(3)
 subprocess.call(&amp;#39;pulseaudio --start&amp;#39;, shell=True)
 time.sleep(2)
 status = subprocess.call(&amp;#39;ls /dev/input/event0 2&amp;gt;/dev/null&amp;#39;, shell=True)
 while status == 2:
 print(&amp;#34;Bluetooth DOWN&amp;#34;)
 print(status)
 subprocess.call(&amp;#39;~/scripts/autopair&amp;#39;, shell=True)
 time.sleep(15)
 status = subprocess.call(&amp;#39;ls /dev/input/event0 2&amp;gt;/dev/null&amp;#39;, shell=True)
 else:
 blue_it()
blue_it()
pi@raspberrypi:~ $chmod +x ~/scripts/on.py
pi@raspberrypi:~ $vim ~/.bashrc
pulseaudio --start
wait
~/python/on.py
&lt;/code>&lt;/pre>&lt;h3 id="reboot">
 Reboot
 
 &lt;a class="anchor" href="#reboot">#&lt;/a>
 
&lt;/h3>
&lt;p>If the connection fails, remove the device and pair-trust-connect&lt;/p></description></item></channel></rss>