Setup Minidlna omxplayer bluetooth on RPi

Install minidlna by sudo apt-get install minidlna

Changes in /etc/minidlna.conf

1
2
media_dir=/home/pi/minidlna
db_dir=/var/lib/minidlna (allow minidlna to index files)

Restart minidlna,

  1. sudo systemctl restart minidlna
  2. sudo service minidlna start
  3. sudo /etc/init.d/minidlna start
  4. sudo service minidlna status -l
  5. sudo systemctl status minidlna -l

http://mkitby.com/2015/11/09/raspberry-pi-nas-upnp-dlna/
http://cheng-min-i-taiwan.blogspot.hk/2013/02/raspberry-pi-dlna.html

Install the command line media player by sudo apt-get install omxplayer, then play the music from ssh command line.

Control the playback via such app “OMX Remote” or “Raspicast” which can be download from google play.

https://codeyarns.com/2016/09/09/how-to-cast-to-raspberry-pi-using-raspicast/
https://codeyarns.com/2016/03/20/omxplayer/
https://codeyarns.com/2016/09/09/omx-remote/

Connect to bluetooth speaker

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
hcitool dev
hciconfig - show BD address of Pi
hciconfig -a hci0
rfkill unblock bluetooth or rfkill unblock all // If bluetoothctl cannot find any controller, the bluetooth device may be blocked. Try to unblock it using rfkill
sudo bluetoothctl
# scan on (find the BD address)
# scan off
# agent on
# default-agent
# pair A0:E4:53:20:77:79
# trust A0:E4:53:20:77:79
# connect A0:E4:53:20:77:79
# list
# devices
# show
# disconnect A0:E4:53:20:77:79

Play music with the bluetooth speaker(Phillips BT3000) using A2DP profile

  1. Check if pulseaudio is running (Reference https://wiki.archlinux.org/index.php/PulseAudio_(%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87))

    1
    2
    3
    4
    5
    ps aux | grep pulseaudio
    =>
    /usr/bin/start-pulseaudio-X11
    pulseaudio --start
    (PulseAudio would run along with X11 desktop startup)
  2. List the sound cards pacmd list-cards. Test audio output of left and right channal speaker-test -c 2

  3. List the audio output pacmd list-sinks or pactl list sinks short. Check the default audio sink aplay -L

  4. List the audio input pacmd list-sources or pactl list sources short

  5. Set the Bluetooth speaker becomes default sink pacmd set-default-sink 1 (index 1 is like bluez_sink.xx_xx_xx_xx_xx_xx)

  6. Turn up the PulseAudio volume pacmd set-sink-volume 0 65537 Or turn up the ALSA volume amixer set Master 100% or amixer cset numid=3 100%
    Reference:
    http://youness.net/raspberry-pi/bluetooth-headset-raspberry-pi
    http://www.crazy-audio.com/2014/09/pulseaudio-on-the-raspbery-pi/

  7. Show soundcard information aplay -L or aplay -l, play a music aplay -v -V stereo HANA.mp3

Stream music to RPi from mobile phone connecting with bluetooth (Optional, maybe RPi can automatically detect the audio source (bluetooth) and sink(3.5mm audio jack)

pactl load-module module-loopback source=bluez_source.B8_C6_8E_52_E8_CA sink=alsa_output.platform-bcm2835_AUD0.0.analog-stereo
Reference:
http://kmonkey711.blogspot.hk/2012/12/a2dp-audio-on-raspberry-pi.html
http://www.dreamincode.net/forums/blog/62/entry-4272-sound-on-an-arch-linux-arm-raspberry-pi/

Bluetooth stack

Controller stack
HCI(Host Controller Interface)
Protocol stack
- L2CAP (Logical Link Control and Adaptation Protocol) -
- SDP (Service Discovery protocol) - scan devices
- RFCOMM (Radio frequency communication) - on top of L2CAP, providing emulated RS-232 serial ports
- BNEP (Bluetooth network encapsulation protocol) - on top of L2CAP, for personal area networking (PAN) profile
Profiles
- A2DP (Advanced Audio Distribution Profile) - for headset
- DUN (Dial-up Networking Profile) - for accessing internet by dialing up on a modem
https://en.wikipedia.org/wiki/List_of_Bluetooth_protocols
https://en.wikipedia.org/wiki/List_of_Bluetooth_profiles

Setup PAN

  1. Install bridge-utils sudo apt install bridge-utils

  2. Install python-dbus sudo apt install python-dbus

  3. Download bt-pan script wget https://raw.githubusercontent.com/mk-fg/fgtk/master/bt-pan

  4. Setup bpen bridge

    1
    2
    3
    4
    5
    6
    7
    sdptool add NAP # advertise NAP service, but found sdptool does not work in bluez 5
    brctl show bnep
    sudo brctl addbr bnep
    sudo brctl setfd bnep 0
    sudo brctl stp bnep off
    sudo ip addr add 192.168.12.3/24 dev bnep
    sudo ip link set bnep up
  5. Setup server via dbus

    1
    2
    dbus-send --system --dest=org.bluez --print-reply --type=method_call /org/bluez/hci0 org.bluez.NetworkServer1.Unregister string:'nap'
    dbus-send --system --dest=org.bluez --print-reply --type=method_call /org/bluez/hci0 org.bluez.NetworkServer1.Register string:'nap' string:'bnep'

    Reference

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    dbus-send --system --type=method_call --print-reply --dest=org.bluez /org/bluez org.freedesktop.DBus.Introspectable.Introspect
    dbus-send --system --dest=org.bluez --type=method_call --print-reply /org/bluez/hci0 org.freedesktop.DBus.Introspectable.Introspect
    dbus-send --system --type=method_call --print-reply=literal --dest=org.bluez /org/bluez/hci0 org.freedesktop.DBus.Properties.Set string:org.bluez.Adapter1 string:Powered variant:boolean:false
    dbus-send --system --type=method_call --print-reply --dest=org.bluez /org/bluez/hci0 org.freedesktop.DBus.Properties.Get string:org.bluez.Adapter1 string:Address
    dbus-send --system --type=method_call --print-reply --dest=org.freedesktop.DBus / org.freedesktop.DBus.ListNames

    //below script is from http://rrbluetoothx.blogspot.hk/2016/06/rr-bluetooth-list-dbus-services-buses.html
    dbus-send --system \
    --dest=org.freedesktop.DBus \
    --type=method_call \
    --print-reply \
    /org/freedesktop/DBus \
    org.freedesktop.DBus.ListNames

    //below script is from https://gist.github.com/studiofuga/5262efb95968b02a365d
    * Making an adapter discoverable (check that rfkill is enabled, otherwise /org/bluez/hci0 will not be available)
    dbus-send --system --dest=org.bluez --print-reply /org/bluez/hci0 \
    org.freedesktop.DBus.Properties.Set \
    string:org.bluez.Adapter1 string:Discoverable variant:boolean:true

    * Changing the discoverable timeout. Default is 180s.

    dbus-send --system --dest=org.bluez --print-reply /org/bluez/hci0 \
    org.freedesktop.DBus.Properties.Set \
    string:org.bluez.Adapter1 string:DiscoverableTimeout variant:uint32:0

    Or Run bt server ./bt-pan --debug server bnep

  6. Run bt client ./bt-pan --debug client 00:11:67:55:8F:69
    https://blind.guru/tag/bluetooth-pan.html
    http://blog.fraggod.net/2015/03/28/bluetooth-pan-network-setup-with-bluez-5x.html (provide the bt-pan script)
    http://www.agouros.de/Elwood/Bluetooth.html
    http://trac.gateworks.com/wiki/wireless/bluetooth (very detail)
    http://wiki.openmoko.org/wiki/Manually_using_Bluetooth#Bluetooth_networking_with_a_Linux_system_-_More_secure_way

sshfs

  1. Install sshfs sudo apt-get install sshfs
  2. Mount the directory by
    1
    2
    3
    sshfs -o allow_other -o kernel_cache -o auto_cache -o reconnect \
    -o compression=no -o cache_timeout=600 -o ServerAliveInterval=15 \
    support@192.168.42.1:/tmp/song /home/pi/minidlna
  3. Refresh the list to load new songs from sshfs directory by minidlnad -R
  4. Reload minidlna service sudo service minidlna force-reload
  5. Unmount directory fusermount -u ~/minidlna

tinyproxy and iptables

1
2
sudo apt-get install tinyproxy
sudo service tinyproxy start

After install tinyproxy in my chromebook, found RPi cannot connect to 8888 port of tinyproxy(nc -l 8888 in chromebook and fail to connect by nc 192.168.42.9 8888 in RPi), which is caused by iptables rule. Then add it,

  1. Save the rules sudo iptables-save > iptables.rules
  2. Add the rule for proxy working sudo iptables -A INPUT -s 192.168.42.0/24 -i wlan0 -p tcp -dport 8888 -j ACCEPT
  3. Restore the rules sudo iptables-restore < iptables.rules

mpg321, mpg123, speedtest-cli (just mark this, this is nothing)

Check the release or other useful information

1
2
3
4
5
6
7
8
9
10
lsb_release -a
vcgencmd version

cat /etc/os-release
cat /etc/rpi-issue
cat /etc/debian_version

cat /proc/cpuinfo
cat /proc/meminfo
cat /proc/version

Show various hardware information to RPi

1
2
3
4
5
6
7
8
9
vcgencmd commands

vcgencmd measure_clock arm
vcgencmd measure_clock core

vcgencmd get_config int

vcgencmd get_mem arm
vcgencmd get_mem gpu