2.5 KiB
2.5 KiB
Bluetooth on the Raspberry Pi Zero W (1 or 2)
The Zero W series has Bluetooth capability because of the Wifi chip on the board. Warning: This is a work in progress!!!
Reference
- "Exploring Raspberry Pi" by Derek Molloy pg 537-544
- Connecting to a Headless Raspberry Pi using Bluetooth
- https://github.com/sorah/bluetooth-getty
- Use dbus insteadd of sdptool
Getting Bluetooth working
- Login to the pi via a USB-serial port or monitor-keyboard-mouse. Configuring bluetooth can sometimes kick you off the wifi.
- Tell
rfkillto unblock bluetooth. Perhaps this is a security thing?
sudo rfkill unblock bluetooth
- Restart the bluetooth service and check it's status
sudo systemctl restart bluetooth
sudo systemctl status bluetooth
- Figure out the address using
hcitool
hcitool dev
- If you have a laptop set to be discoverable, you can check if bluetooth is working
hcitool scan
- You can then query that device for what services it offers
sdptool browse ADDRESS
- Now we want to make the Pi discoverable to our phone, tablet, or laptop
sudo hciconfig hci0 piscan
sudo hciconfig hci name RaspberryPi
- A Serial Port Profile(SPP) is needed for our serial port
sudo sdptool add SP
- For some reason, we have to put the bluetooth daemon in compatibility mode. (True as of 2016-2026 --foley). Find the line with
ExecStartand put--compatat the end
sudo nano /lib/systemd/system/bluetooth.service
- Test the SPP is setup
sudo sdptool browse local
- Time to pair it with a device
sudo bluetoothctl
discoverable on
agent on
pairable on
scan on
and once you have paired it
discoverable off
exit
- If this works, you can install the
bluetooth.servicesandrfcomm.servicefiles to automate some of this setup.
sudo cp bluetooth.service /etc/systemd/system/bluetooth.target.wants/.
sudo cp rfcomm.service /etc/systemd/system/.
sudo systemctl daemon-reload
sudo systemctl enable rfcomm
sudo reboot
Discussion
Apparently Bluez's sdptool is now depricated and they are telling people to use this new GATT via busctl or dbus-send. linuxvox article on depricated sdptool