Git Product home page Git Product logo

go-bluetooth's Introduction

go-bluetooth

Golang bluetooth client based on bluez DBus interfaces

See here for reference https://git.kernel.org/cgit/bluetooth/bluez.git/tree/doc

Features

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

Examples

The examples/ folder offer an overview of library

  • agent a simple agent to support pairing
  • btmgmt interface to CLI btmgmt
  • discovery find devices around
  • hci_updown HCI based communication example
  • obex_push send file to a device
  • sensortag_info Obtain data from a TI SensorTag
  • sensortag_temperature Obtain temperature from a TI SensorTag
  • service expose a bluetooth device with corresponding services
  • show_miband_info show informations for MiBand2
  • watch_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/

Setup

The library has been tested with

  • golang 1.11.4 (starting from v1.6)
  • bluez bluetooth v5.50 (starting from v5.43)

bluez upgrade

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

Development notes

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 messages

    sudo 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
    

References

License

MIT License

go-bluetooth's People

Contributors

muka avatar packetdancer avatar lc-spxl avatar davidknezic avatar cuu avatar rachelblackman avatar niziak avatar mrmstn avatar gbrayut avatar phommel avatar svenschwermer avatar ghouscht avatar amenzhinsky avatar andyholmes avatar muesli avatar saurabh-zededa avatar

Watchers

Satish Chauhan avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.