bluez

package module
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2021 License: MIT Imports: 5 Imported by: 4

README

bluez-connect = GATT of BlueZ

Package provides a Bluetooth Low Energy GATT implementation over linux BlueZ API.

bluez-connect communicates with BlueZ over D-Bus (linux message bus system).

This package was developed as part of IoT project in order to add GATT capability to Raspberry Pi like devices. Package was tested against BlueZ 5.46

Because this package mostly makes sense for Linux / arm devices, build environment is adopted to such platform. In other words GOOS=linux GOARCH=arm

Usage

Please see godoc.org for documentation. (Not ready yet)

Examples

Peripheral example

This example creates and advertizes, Echo service with single Echo characteristic with Read / Write capabilities.

Build and run

GOOS=linux GOARCH=arm go build examples/server/server-example.go 
# Copy to target device
./server-example

Central example

This example is only template. You need to replace Service and Characteristics by real ones you want to connect.

Build and run

GOOS=linux GOARCH=arm go build examples/client/client-example.go 
# Copy to target device
./client-example

Package release under a MIT license.

Documentation

Index

Constants

View Source
const (
	DBusIntrospectableInterface = "org.freedesktop.DBus.Introspectable"
	DBusPropertiesInterface     = "org.freedesktop.DBus.Properties"
	DBusPropertiesIntro         = `` /* 865-byte string literal not displayed */

	GattService1Interface = "org.bluez.GattService1"
	GattService1Intro     = `<node>
<interface name="org.bluez.GattService1">
      <property name="UUID" type="s" access="read" />
      <property name="Primary" type="b" access="read" />
</interface>` + DBusPropertiesIntro + introspect.IntrospectDataString + `</node>`

	GattCharacteristic1Interface = "org.bluez.GattCharacteristic1"
	GattCharacteristic1Intro     = `<node>
<interface name="org.bluez.GattCharacteristic1">
      <property name="UUID" type="s" access="read" />
</interface>` + DBusPropertiesIntro + introspect.IntrospectDataString + `</node>`

	ObjectManagerInterface = "org.freedesktop.DBus.ObjectManager"
	ObjectManagerIntro     = `<node>
<interface name="org.freedesktop.DBus.ObjectManager">
	<method name="GetManagedObjects">
		<arg name="objects" type="a{oa{sa{sv}}}" direction="out"/>
	</method>
	<signal name="InterfacesAdded">
		<arg name="Object" type="o"/>
		<arg name="interfaces" type="a{sa{sv}}"/>
	</signal>
	<signal name="InterfacesRemoved">
		<arg name="Object" type="o"/>
		<arg name="interfaces" type="as"/>
	</signal>
</interface>` + DBusPropertiesIntro + introspect.IntrospectDataString + `</node>`

	LEAdvertisement1Interface = "org.bluez.LEAdvertisement1"
	LEAdvertisement1Intro     = `` /* 1508-byte string literal not displayed */

	Agent1Interface = "org.bluez.Agent1"
	Agent1Intro     = `
<node>
    <interface name="org.bluez.Agent1">
        <method name="Release" />
        <method name="RequestPinCode">
            <arg direction="in" type="o" />
            <arg direction="out" type="s" />
        </method>
        <method name="DisplayPinCode">
            <arg direction="in" type="o" />
            <arg direction="in" type="s" />
        </method>
        <method name="RequestPasskey">
            <arg direction="in" type="o" />
            <arg direction="out" type="u" />
        </method>
        <method name="DisplayPasskey">
            <arg direction="in" type="o" />
            <arg direction="in" type="u" />
            <arg direction="in" type="q" />
        </method>
        <method name="RequestConfirmation">
            <arg direction="in" type="o" />
            <arg direction="in" type="u" />
        </method>
        <method name="RequestAuthorization">
            <arg direction="in" type="o" />
        </method>
        <method name="AuthorizeService">
            <arg direction="in" type="o" />
            <arg direction="in" type="s" />
        </method>
        <method name="Cancel" />
    </interface>` + DBusPropertiesIntro + introspect.IntrospectDataString + `</node>`
)

Variables

This section is empty.

Functions

func HasPrefix

func HasPrefix(path1 dbus.ObjectPath, path2 dbus.ObjectPath) bool

func MakeFailedError

func MakeFailedError(err error) *dbus.Error

Types

type Agent

type Agent interface {
	Release() (e *dbus.Error)
	RequestPinCode(device dbus.Object) (pincode string, e *dbus.Error)
	DisplayPinCode(device dbus.Object, pincode string) (e *dbus.Error)
	RequestPasskey(device dbus.Object) (passkey uint32, e *dbus.Error)
	DisplayPasskey(device dbus.Object, passkey uint32, entered int16) (e *dbus.Error)
	RequestConfirmation(device dbus.Object, passkey uint32) (e *dbus.Error)
	RequestAuthorization(device dbus.Object) (e *dbus.Error)
	AuthorizeService(device dbus.Object, uuid string) (e *dbus.Error)
	Cancel() (e *dbus.Error)
	Capability() (capability AgentCapability)
}

type AgentCapability

type AgentCapability string
const (
	DisplayOnly     AgentCapability = "DisplayOnly"
	DisplayYesNo    AgentCapability = "DisplayYesNo"
	KeyboardOnly    AgentCapability = "KeyboardOnly"
	NoInputNoOutput AgentCapability = "NoInputNoOutput"
	KeyboardDisplay AgentCapability = "KeyboardDisplay"
)

type BlueZ

type BlueZ struct {
	*BlueZObject
	SignalChannel chan *dbus.Signal
}

func NewBLueZ

func NewBLueZ() (bluez *BlueZ, e error)

func (*BlueZ) AddInterfacesObserver

func (self *BlueZ) AddInterfacesObserver() (e error)

func (*BlueZ) Close

func (self *BlueZ) Close() (e error)

func (*BlueZ) GetAdapter

func (self *BlueZ) GetAdapter(hostId string) (a *BlueZAdapter, e error)

func (*BlueZ) GetAdapters

func (self *BlueZ) GetAdapters() (adapters []*BlueZAdapter, e error)

func (*BlueZ) RegisterAgent

func (self *BlueZ) RegisterAgent(agent Agent, path string, iface string) (e error)

func (*BlueZ) RemoveInterfacesObserver

func (self *BlueZ) RemoveInterfacesObserver() (e error)

func (*BlueZ) UnregisterAgent

func (self *BlueZ) UnregisterAgent(path string) (e error)

func (*BlueZ) WaitForSignals

func (self *BlueZ) WaitForSignals(callback func(signal *dbus.Signal))

type BlueZAdapter

type BlueZAdapter struct {
	BlueZObject
	// contains filtered or unexported fields
}

func (*BlueZAdapter) FindPeripheral

func (self *BlueZAdapter) FindPeripheral(nameOrAddress string) (foundDevice *BlueZDevice)

func (*BlueZAdapter) GetDevices

func (self *BlueZAdapter) GetDevices() (devices []*BlueZDevice, e error)

func (*BlueZAdapter) GetGattManager

func (self *BlueZAdapter) GetGattManager() (gattManager *BlueZGattManager, e error)

func (*BlueZAdapter) StartAdvertise

func (self *BlueZAdapter) StartAdvertise(path string, localName string, serviceUUIDs []string) (e error)

func (*BlueZAdapter) StartDiscovery

func (self *BlueZAdapter) StartDiscovery() (e error)

func (*BlueZAdapter) StopAdvertise

func (self *BlueZAdapter) StopAdvertise(path string) (e error)

func (*BlueZAdapter) StopDiscovery

func (self *BlueZAdapter) StopDiscovery() (e error)

type BlueZCharacteristic

type BlueZCharacteristic struct {
	BlueZObject
	// contains filtered or unexported fields
}

func (*BlueZCharacteristic) ReadValue

func (self *BlueZCharacteristic) ReadValue() (data []byte, e error)

func (*BlueZCharacteristic) StartNotify

func (self *BlueZCharacteristic) StartNotify() (e error)

func (*BlueZCharacteristic) StopNotify

func (self *BlueZCharacteristic) StopNotify() (e error)

func (*BlueZCharacteristic) ToDisplayString

func (self *BlueZCharacteristic) ToDisplayString() (text string)

func (*BlueZCharacteristic) UUID

func (self *BlueZCharacteristic) UUID() (value string)

func (*BlueZCharacteristic) WriteValue

func (self *BlueZCharacteristic) WriteValue(value []byte) (e error)

type BlueZDevice

type BlueZDevice struct {
	BlueZObject
	// contains filtered or unexported fields
}

func (*BlueZDevice) Address

func (self *BlueZDevice) Address() (value string)

func (*BlueZDevice) Connect

func (self *BlueZDevice) Connect() (e error)

func (*BlueZDevice) Connected

func (self *BlueZDevice) Connected() (value bool)

func (*BlueZDevice) Disconnect

func (self *BlueZDevice) Disconnect() (e error)

func (*BlueZDevice) GetCharacteristic

func (self *BlueZDevice) GetCharacteristic(uuid string, serviceUuid string) (foundCharacteristic *BlueZCharacteristic, foundService *BlueZService, e error)

func (*BlueZDevice) GetServices

func (self *BlueZDevice) GetServices() (services []BlueZService, e error)

func (*BlueZDevice) Name

func (self *BlueZDevice) Name() (value string)

func (*BlueZDevice) Refresh

func (self *BlueZDevice) Refresh() (e error)

func (*BlueZDevice) ServicesResolved

func (self *BlueZDevice) ServicesResolved() (value bool)

func (*BlueZDevice) ToDisplayString

func (self *BlueZDevice) ToDisplayString() (text string)

func (*BlueZDevice) UUIDs

func (self *BlueZDevice) UUIDs() (value []string)

type BlueZGattApplication

type BlueZGattApplication struct {
	// contains filtered or unexported fields
}

func (*BlueZGattApplication) GetManagedObjects

func (self *BlueZGattApplication) GetManagedObjects() (managedObjects map[dbus.ObjectPath]map[string]map[string]dbus.Variant, e *dbus.Error)

type BlueZGattCharacteristic

type BlueZGattCharacteristic struct {
	// contains filtered or unexported fields
}

func (*BlueZGattCharacteristic) Confirm

func (self *BlueZGattCharacteristic) Confirm() (e *dbus.Error)

func (*BlueZGattCharacteristic) Get

func (self *BlueZGattCharacteristic) Get(iface string, name string) (variant dbus.Variant, e *dbus.Error)

func (*BlueZGattCharacteristic) GetAll

func (self *BlueZGattCharacteristic) GetAll(iface string) (properties map[string]dbus.Variant, e *dbus.Error)

func (*BlueZGattCharacteristic) ReadValue

func (self *BlueZGattCharacteristic) ReadValue(options map[string]interface{}) (value []byte, e *dbus.Error)

func (*BlueZGattCharacteristic) StartNotify

func (self *BlueZGattCharacteristic) StartNotify() (e *dbus.Error)

func (*BlueZGattCharacteristic) StopNotify

func (self *BlueZGattCharacteristic) StopNotify() (e *dbus.Error)

func (*BlueZGattCharacteristic) WriteValue

func (self *BlueZGattCharacteristic) WriteValue(value []byte, options map[string]interface{}) (e *dbus.Error)

type BlueZGattManager

type BlueZGattManager struct {
	BlueZObject
	// contains filtered or unexported fields
}

func (*BlueZGattManager) AddApplication

func (self *BlueZGattManager) AddApplication(gattApplication *GattApplication) (e error)

type BlueZGattService

type BlueZGattService struct {
	// contains filtered or unexported fields
}

func (*BlueZGattService) Get

func (self *BlueZGattService) Get(iface string, name string) (variant dbus.Variant, e *dbus.Error)

func (*BlueZGattService) GetAll

func (self *BlueZGattService) GetAll(iface string) (properties map[string]dbus.Variant, e *dbus.Error)

type BlueZObject

type BlueZObject struct {
	Conn   *dbus.Conn
	Object dbus.BusObject
}

func (*BlueZObject) AddPropertiesObserver

func (self *BlueZObject) AddPropertiesObserver() (e error)

func (*BlueZObject) RemovePropertiesObserver

func (self *BlueZObject) RemovePropertiesObserver() (e error)

type BlueZService

type BlueZService struct {
	BlueZObject
	// contains filtered or unexported fields
}

func (*BlueZService) GetCharacteristicByUUID

func (self *BlueZService) GetCharacteristicByUUID(uuid string) (foundCharacteristic *BlueZCharacteristic, e error)

func (*BlueZService) GetCharacteristics

func (self *BlueZService) GetCharacteristics() (characteristics []BlueZCharacteristic, e error)

func (*BlueZService) ToDisplayString

func (self *BlueZService) ToDisplayString() (text string)

func (*BlueZService) UUID

func (self *BlueZService) UUID() (value string)

type GattApplication

type GattApplication struct {
	Path     string
	Services map[string]*GattService
}

func NewGattApplication

func NewGattApplication(path string) (gattApplication *GattApplication)

func (*GattApplication) AddService

func (self *GattApplication) AddService(gattService *GattService)

func (*GattApplication) RemoveService

func (self *GattApplication) RemoveService(gattService *GattService)

type GattCharacteristic

type GattCharacteristic struct {
	UUID        string
	Flags       []string
	OnReadFunc  func() ([]byte, error)
	OnWriteFunc func([]byte) error
}

func NewGattCharacteristic

func NewGattCharacteristic(uuid string, flags []string) (gattCharacteristic *GattCharacteristic)

type GattService

type GattService struct {
	UUID            string
	Characteristics map[string]*GattCharacteristic
}

func NewGattService

func NewGattService(uuid string) (gattService *GattService)

func (*GattService) AddCharacteristic

func (self *GattService) AddCharacteristic(gattCharacteristic *GattCharacteristic)

func (*GattService) RemoveCharacteristic

func (self *GattService) RemoveCharacteristic(gattCharacteristic *GattCharacteristic)

type LEAdvertisement1

type LEAdvertisement1 struct {
	// contains filtered or unexported fields
}

func (*LEAdvertisement1) Get

func (self *LEAdvertisement1) Get(iface string, name string) (variant dbus.Variant, e *dbus.Error)

func (*LEAdvertisement1) GetAll

func (self *LEAdvertisement1) GetAll(iface string) (properties map[string]dbus.Variant, e *dbus.Error)

func (*LEAdvertisement1) Includes

func (self *LEAdvertisement1) Includes() ([]string, *dbus.Error)

func (*LEAdvertisement1) LocalName

func (self *LEAdvertisement1) LocalName() (string, *dbus.Error)

func (*LEAdvertisement1) Release

func (self *LEAdvertisement1) Release() (dbusError *dbus.Error)

func (*LEAdvertisement1) ServiceUUIDs

func (self *LEAdvertisement1) ServiceUUIDs() ([]string, *dbus.Error)

func (*LEAdvertisement1) Type

func (self *LEAdvertisement1) Type() (string, *dbus.Error)

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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