go-bluetooth

command module
v0.0.0-...-ac156b6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 19, 2019 License: Apache-2.0 Imports: 1 Imported by: 0

README

go-bluetooth

Go bluetooth API for Bluez DBus interface.

GoDoc

Usage

  1. Build the binary

cd $GOPATH/src/github.com/muka/go-bluetooth && make build

  1. Run the examples eg.

go-bluetooth discovery

The examples/ folder offer an API overview.

Features

The library offers a wrapper to Bluez DBus API and some high level API to ease the interaction.

High level features supported:

  • Client code generation from bluez documentation
  • Shell wrappers for rfkill, btmgmt, hciconfig, hcitool
  • An hci basic API (from a fork of go-ble/ble)
  • Expose bluetooth service from go code
  • Pairing and authentication support (via agent)
  • Basic beaconing (iBeacon and Eddystone)

Setup

The go Bluez API is generated from the documentation, run make gen to re-generate go sources. There is also a commodity bluez JSON file available in the root folder for reference.

Code generation will not overwrite existing files, run make gen/clean to remove generated content.

Generated code has gen_ prefix. If an API file exists with the same filename but without the prefix, generation will be skipped for that API.

Note Ensure to install proper dbus rules on the system. For a dev setup, you can use the library configuration as follow

  cd $GOPATH/src/github.com/muka/go-bluetooth
  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/
  # Reload dbus to load new policies:
  # via dbus
  # dbus-send --system --type=method_call --dest=org.freedesktop.DBus / org.freedesktop.DBus.ReloadConfig
  # via systemctl
  systemctl reload dbus

Requirements

The library is tested with

  • golang 1.11
  • bluez bluetooth v5.50
Development notes
  • Standard GATT characteristics descriptions can be found on https://www.bluetooth.com/specifications/gatt/

  • Give access to hciconfig to any user and avoid sudo (may have security implications)

    sudo setcap 'cap_net_raw,cap_net_admin+eip' `which hciconfig`
    
  • Monitor Bluetooth activity

    sudo btmon

  • Monitor DBus activity

    sudo dbus-monitor --system "type=error"

  • Start bluetoothd with experimental features and verbose debug messages make bluetoothd

  • Enable LE advertisement (on a single pc ensure to use at least 2x 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
    
    

Contributing

Feel free to open an issue and/or a PR to contribute. If you would like to help improve the library without coding directly, you can also consider to contribute by providing some hardware to test on.

References

License

Copyright 2019 luca capra

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
api
package api wraps an high level API to simplify interaction
package api wraps an high level API to simplify interaction
profile/adapter
BlueZ D-Bus Adapter API description [adapter-api.txt]
BlueZ D-Bus Adapter API description [adapter-api.txt]
profile/advertising
BlueZ D-Bus LE Advertising API Description [advertising-api.txt] Advertising packets are structured data which is broadcast on the LE Advertising channels and available for all devices in range.
BlueZ D-Bus LE Advertising API Description [advertising-api.txt] Advertising packets are structured data which is broadcast on the LE Advertising channels and available for all devices in range.
profile/agent
BlueZ D-Bus Agent API description [agent-api.txt]
BlueZ D-Bus Agent API description [agent-api.txt]
profile/battery
BlueZ D-Bus Battery API description [battery-api.txt]
BlueZ D-Bus Battery API description [battery-api.txt]
profile/device
BlueZ D-Bus Device API description [device-api.txt]
BlueZ D-Bus Device API description [device-api.txt]
profile/gatt
BlueZ D-Bus GATT API description [gatt-api.txt] GATT local and remote services share the same high-level D-Bus API.
BlueZ D-Bus GATT API description [gatt-api.txt] GATT local and remote services share the same high-level D-Bus API.
profile/health
BlueZ D-Bus Health API description [health-api.txt]
BlueZ D-Bus Health API description [health-api.txt]
profile/input
BlueZ D-Bus Input API description [input-api.txt]
BlueZ D-Bus Input API description [input-api.txt]
profile/media
BlueZ D-Bus Media API description [media-api.txt]
BlueZ D-Bus Media API description [media-api.txt]
profile/network
BlueZ D-Bus Network API description [network-api.txt]
BlueZ D-Bus Network API description [network-api.txt]
profile/obex
OBEX D-Bus API description [obex-api.txt]
OBEX D-Bus API description [obex-api.txt]
profile/obex_agent
OBEX D-Bus Agent API description [obex-agent-api.txt]
OBEX D-Bus Agent API description [obex-agent-api.txt]
profile/profile
BlueZ D-Bus Profile API description [profile-api.txt]
BlueZ D-Bus Profile API description [profile-api.txt]
profile/sap
BlueZ D-Bus Sim Access API description [sap-api.txt]
BlueZ D-Bus Sim Access API description [sap-api.txt]
profile/thermometer
BlueZ D-Bus Thermometer API description [thermometer-api.txt] Santiago Carot-Nemesio <sancane@gmail.com>
BlueZ D-Bus Thermometer API description [thermometer-api.txt] Santiago Carot-Nemesio <sancane@gmail.com>
devices
examples
btmgmt
Example use of the btmgmt wrapper
Example use of the btmgmt wrapper
discovery
shows how to watch for new devices and list them
shows how to watch for new devices and list them
gen
hw

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL