Golang bluetooth client based on bluez DBus interfaces
See here for reference https://git.kernel.org/cgit/bluetooth/bluez.git/tree/doc
The features implemented are
- Discovery
- Adapter support
- Client device support (see SensorTag example)
- GATT Service and characteristics interface
- Shell interfaces to
rfkill
,btmgmt
,hciconfig
,hcitool
- Handle systemd
bluetooth.service
unit - Expose
hci
basic API - Expose bluetooth services via bluez GATT API
- Basic pairing support
- Basic authentication support
The examples/
folder offer an overview of library
agent
a simple agent to support pairingbtmgmt
interface to CLI btmgmtdiscovery
find devices aroundhci_updown
HCI based communication exampleobex_push
send file to a devicesensortag_info
Obtain data from a TI SensorTagsensortag_temperature
Obtain temperature from a TI SensorTagservice
expose a bluetooth device with corresponding servicesshow_miband_info
show informations for MiBand2watch_changes
register for notifications from a TI SensorTag
Note Ensure to install proper dbus rules on the system. For a dev setup use
sudo ln -s `pwd`/scripts/dbus-go-bluetooth-service.conf /etc/dbus-1/system.d/
sudo ln -s `pwd`/scripts/dbus-go-bluetooth-dev.conf /etc/dbus-1/system.d/
The library has been tested with
- golang
1.11.4
(starting fromv1.6
) - bluez bluetooth
v5.50
(starting fromv5.43
)
Bluez, the linux bluetooth implementation, has introduced GATT support from v5.43
Ensure you are using an up to date version with bluetoothd -v
See in scripts/
how to upgrade bluez
Standard GATT characteristics descriptions can be found on https://www.bluetooth.com/specifications/gatt/
-
Give access to
hciconfig
to any user (may have security implications)sudo setcap 'cap_net_raw,cap_net_admin+eip' `which hciconfig`
-
Create a dbus profile
ln -s `pwd`/scripts/dbus-dev.conf /etc/dbus-1/system.d/go-bluetooth.config
-
Monitor activity
sudo dbus-monitor --system "type=error"
-
View
bluetoothd
debug messagessudo service bluetooth stop && sudo bluetoothd -Edn P hostname
-
Enable LE advertisement (to use a single pc, you will need 2 bluetooth adapter)
sudo btmgmt -i 0 power off sudo btmgmt -i 0 name "my go app" sudo btmgmt -i 0 le on sudo btmgmt -i 0 connectable on sudo btmgmt -i 0 advertising on sudo btmgmt -i 0 power on
- https://git.kernel.org/cgit/bluetooth/bluez.git/tree/doc
- https://www.bluetooth.com/specifications/gatt/services
- http://events.linuxfoundation.org/sites/events/files/slides/Bluetooth%20on%20Modern%20Linux_0.pdf
- https://github.com/nettlep/gobbledegook
MIT License