Categorygithub.com/sensefinitycloud/go-ble
modulepackage
0.1.15
Repository: https://github.com/sensefinitycloud/go-ble.git
Documentation: pkg.go.dev

# README

Go BLE Scan Response

Fork of github.com/go-ble/ble

  1. Removed macos support
  2. Added multiple features needed to integrate nordic features

New Features

General Advertisement function

Advertise(ctx context.Context, adv AdvertisementData) error

Struct:

// AdvertisementData represents the advertisement data for a Bluetooth Low Energy device.
type AdvertisementData struct {
	ShortName        string
	CompleteName     string
	ManufacturerData *ManufacturerData
	ScanResponse     *ScanResponse
	Services []UUID
}

type ScanResponse struct {
	ManufacturerData  *ManufacturerData
	IncludeDeviceName bool
}

// ManufacturerData represents the data structure for manufacturer-specific data in BLE advertising packets.
type ManufacturerData struct {
	CompanyId uint16
	Data      []byte
}

eg:

advData := ble.AdvertisementData{
	ShortName: "Example",
	Services:  []ble.UUID{ble.MustParse("6E400001-B5A3-F393-E0A9-E50E24DCCA9E")},
	ScanResponse: &ble.ScanResponse{
		ManufacturerData: &ble.ManufacturerData{
			CompanyId: uint16(89),
			Data:      []byte("Example"),
		},
	},
}

// It blocks the current goroutine until the advertising process is finished.
err = ble.Advertise(ctx, advData)
if err != nil {
	panic(err)
}

Added Notifier on HandleWrite

Feature: We can notify other characteristics when receiving new data

rx.HandleWrite(ble.WriteHandlerFunc(func(req ble.Request, rsp ble.ResponseWriter, n func(h uint16, data []byte) (int, error))

eg:

tx.HandleNotify(ble.NotifyHandlerFunc(func(req ble.Request, n ble.Notifier) {
		log.Println("TX Notify handler called")

}))


rx.HandleWrite(ble.WriteHandlerFunc(func(req ble.Request, rsp ble.ResponseWriter, n func(h uint16, data []byte) (int, error)) {
		n(tx.ValueHandle, []byte("ok"))
}))

Advertise Name And Services With ScanResponse

Advertises device name, and specified service UUIDs.
It tres to fit the UUIDs in the advertising packet as much as possible.
Advertises the given manufacturer data in the scan response.

AdvertiseNameAndServicesWithScanResponse(ctx context.Context, name string, companyId uint16, b []byte, uuids ...UUID) error

Go Ble

ble is a Golang Bluetooth Low Energy package for Linux and Mac OS.

Note: Is not being actively maintained, should use the original lib.

# Packages

No description provided by the author
No description provided by the author

# Functions

AddService adds a service to database.
No description provided by the author
AdvertiseIBeacon advertises iBeacon with specified parameters.
AdvertiseIBeaconData advertise iBeacon with given manufacturer data.
AdvertiseNameAndServices advertises device name, and specified service UUIDs.
Advertises device name, and specified service UUIDs.
Connect searches for and connects to a Peripheral which matches specified condition.
Contains returns a boolean reporting whether u is in the slice s.
Dial ...
Find ...
MustParse parses a standard-format UUID string, like Parse, but panics in case of error.
Name returns name of know services, characteristics, or descriptors.
NewAddr creates an Addr from string.
NewCharacteristic creates and returns a Characteristic.
NewDescriptor creates and returns a Descriptor.
NewNotifier ...
NewRequest returns a default implementation of Request.
NewResponseWriter ...
NewService creates and initialize a new Service using u as it's UUID.
OptAdvParams overrides default advertising parameters.
OptCentralRole configures the device to perform Central tasks.
No description provided by the author
OptConnParams overrides default connection parameters.
OptDeviceID sets HCI device ID.
OptDialerTimeout sets dialing timeout for Dialer.
No description provided by the author
OptListenerTimeout sets dialing timeout for Listener.
OptPeripheralRole configures the device to perform Peripheral tasks.
OptScanParams overrides default scanning parameters.
Parse parses a standard-format UUID string, such as "1800" or "34DA3AD1-7110-41A1-B1EF-4430F509CDE7".
RemoveAllServices removes all services that are currently in the database.
Reverse returns a reversed copy of u.
Scan starts scanning.
SetDefaultDevice returns the default HCI device.
SetServices set the specified service to the database.
Stop detatch the GATT server from a peripheral device.
UUID16 converts a uint16 (such as 0x1800) to a UUID.
WithSigHandler ...

# Constants

may be brocasted.
supports extended properties.
supports Indications.
supports notifications.
may be read.
supports signed write.
may be written to, with a reply.
may be written to, with no reply.
DefaultMTU defines the default MTU of ATT protocol including 3 bytes of ATT header.
ErrAttrNotFound means no attribute found within the given attribute handle range.
ErrAttrNotLong means the attribute cannot be read or written using the Read Blob Request.
ErrAuthentication means the attribute requires authentication before it can be read or written.
ErrAuthorization means the attribute requires authorization before it can be read or written.
ErrInsuffEnc means the attribute requires encryption before it can be read or written.
ErrInsuffEncrKeySize means the Encryption Key Size used for encrypting this link is insufficient.
ErrInsuffResources means insufficient resources to complete the request.
ErrInvalAttrValueLen means the attribute value length is invalid for the operation.
ErrInvalidHandle means the attribute handle given was not valid on this server.
ErrInvalidOffset means the specified was past the end of the attribute.
ErrInvalidPDU means the attribute PDU was invalid.
ErrPrepQueueFull means too many prepare writes have been queued.
ErrReadNotPerm eans the attribute cannot be read.
ErrReqNotSupp means the attribute server does not support the request received from the client.
ErrSuccess measn the operation is success.
ErrUnlikely means the attribute request that was requested has encountered an error that was unlikely, and therefore could not be completed as requested.
ErrUnsuppGrpType means the attribute type is not a supported grouping attribute as defined by a higher layer specification.
ErrWriteNotPerm eans the attribute cannot be written.
MaxMTU is maximum of ATT_MTU, which is 512 bytes of value length, plus 3 bytes of ATT header.

# Variables

UUIDs ...
Battery Service.
UUIDs ...
UUIDs ...
ContextKeyCCC for per connection contexts.
ContextKeySig for SigHandler context.
Current Time Service.
Device Information.
UUIDs ...
ErrDefaultDevice ...
ErrEIRPacketTooLong is the error returned when an AdvertisingPacket or ScanResponsePacket is too long.
ErrNotImplemented means the functionality is not implemented.
Generic Access.
Generic Attribute.
Human Interface Device.
UUIDs ...
UUIDs ...
UUIDs ...
UUIDs ...
UUIDs ...
UUIDs ...
UUIDs ...
UUIDs ...

# Structs

AdvertisementData represents the advertisement data for a Bluetooth Low Energy device.
A Characteristic is a BLE characteristic.
Descriptor is a BLE descriptor.
ManufacturerData represents the data structure for manufacturer-specific data in BLE advertising packets.
A Profile is composed of one or more services necessary to fulfill a use case.
No description provided by the author
A Service is a BLE service.
ServiceData ...

# Interfaces

Addr represents a network end point address.
Advertisement ...
A Client is a GATT client.
Conn implements a L2CAP connection.
Device ...
DeviceOption is an interface which the device should implement to allow using configuration options.
Notifier ...
A NotifyHandler handles GATT requests.
A ReadHandler handles GATT requests.
Request ...
ResponseWriter ...
A WriteHandler handles GATT requests.

# Type aliases

AdvFilter returns true if the advertisement matches specified condition.
AdvHandler handles advertisement.
ATTError is the error code of Attribute Protocol [Vol 3, Part F, 3.4.1.1].
ContextKey is a type used for keys of a context.
A NotificationHandler handles notification or indication from a server.
NotifyHandlerFunc is an adapter to allow the use of ordinary functions as Handlers.
An Option is a configuration function, which configures the device.
Property ...
ReadHandlerFunc is an adapter to allow the use of ordinary functions as Handlers.
A UUID is a BLE UUID.
WriteHandlerFunc is an adapter to allow the use of ordinary functions as Handlers.