bluetooth

package
v0.0.14 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package bluetooth talks to Bluetooth LE devices: scales, printers, beacons and the like. Characteristics are read and written as bytes.

nimbus native plugin add bluetooth

ok, err := bluetooth.Request(ctx)
go bluetooth.Scan(scanCtx, func(d bluetooth.Device) { add(d) })
err = bluetooth.Connect(ctx, d.ID)
b, err := bluetooth.Read(ctx, d.ID, service, characteristic)

Written against the platform APIs, but not yet run on phones: simulators and emulators have no Bluetooth. In a browser (Chrome and Edge), Scan opens the browser's chooser and finds the one device picked, and only the services named in Scan can be read or written.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Connect

func Connect(ctx context.Context, id string) error

Connect connects to a device, and finds its services.

func Disconnect

func Disconnect(ctx context.Context, id string) error

Disconnect ends the connection.

func Read

func Read(ctx context.Context, id, service, characteristic string) ([]byte, error)

Read reads a characteristic.

func Request

func Request(ctx context.Context) (bool, error)

Request asks to use Bluetooth, once.

func Scan

func Scan(ctx context.Context, f func(Device), services ...string) error

Scan calls f with each device it finds until ctx ends. services narrows it to those UUIDs; in a browser, name every service you'll use. It blocks, so run it from a goroutine in an effect.

func Write

func Write(ctx context.Context, id, service, characteristic string, value []byte) error

Write writes a characteristic, and waits for the device to confirm.

Types

type Device

type Device struct {
	ID     string `json:"id"`     // for Connect; it differs between phones
	Name   string `json:"name"`   // its name, if it gives one
	Signal int    `json:"signal"` // RSSI, in dBm
}

Device is something nearby.

Jump to

Keyboard shortcuts

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