Bluetooth Low Energy for Go
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
Greg Pomerantz 6da0474e59 Bug fix for Android (C variable name conflict). 8 months ago
depjars Fixes to depjars/build.go 3 years ago
gatt Working Android implementation. 3 years ago
ns Update to gioui.org@v0.0.0-20211113093644. Updates for MacOS 11.5. 8 months ago
.gitignore Documentation 3 years ago
Ble.jar Port to gio gioui.org@20200829. 2 years ago
BlessedConnect.java Port to gio gioui.org@20200829. 2 years ago
LICENSE Add license information. 3 years ago
LICENSE-BLESSED Add license information. 3 years ago
LICENSE-TIMBER Add Timber license. Add depjars/ and go:generate commands to build 3 years ago
README.md Switch back to Blessed library after bug fixes. 3 years ago
ble.go Improve handling of peripheral disconnections and some refactoring. 3 years ago
ble_android.go Bug fix for Android (C variable name conflict). 8 months ago
ble_darwin.go Update to gioui.org@v0.0.0-20211113093644. Updates for MacOS 11.5. 8 months ago
blessed-full.jar Add Timber license. Add depjars/ and go:generate commands to build 3 years ago
go.mod Port to gio gioui.org@20200829. 2 years ago
go.sum Port to gio gioui.org@20200829. 2 years ago
jni_android.c Port to gio gioui.org@20200829. 2 years ago
jni_android.go Partial android implementation, including Enable(), readyToScan(), 3 years ago
jni_android.h Bump gio version, use window.Do() instead of RegisterFragment(). 2 years ago
nswrap.yaml Update to gioui.org@v0.0.0-20211113093644. Updates for MacOS 11.5. 8 months ago
timber.jar Add Timber license. Add depjars/ and go:generate commands to build 3 years ago

README.md

BLE

A modern, cross-platform Go library for Bluetooth Low Energy

This package is a working but incomplete interface for access to Bluetooth Low Energy devices. It is intended to support multiple operating systems with a uniform API. Currently, MacOS and Android are supported. Android support requires the use of Gio.

The API is asyncrhonous and event driven. To access Bluetooth hardware, first create a BLE variable with NewBLE(). On Android, you must also call Enable with a pointer to your Gio Window.

import (
	...
	"git.wow.st/gmp/ble"
	"gioui.org/app"
)

func runloop() {
	b := ble.NewBle()
	w := app.NewWindow()
	b.Enable(w)
	...

Once enabled, you can call the primary API functions, Scan, StopScan, Connect, and CancelConnection. You can also query the state of the Bluetooth hardware by calling State.

Calling Events on your BLE object returns a channel on which API events are delivered. These events notify your program when the state of the BLE hardware changes (e.g. powered on or off), peripherals are connected, services or characteristics are discovered, or values for characteristics are updated.

Using Gio, your main event loop will look something like this:

	for {
		select {
		case e := <-b.Events():
			switch e := e.(type) {
				// Handle BLE Events
			}
		}
		case e := <-w.Events():
			switch e := e.(type) {
				// Handle Gio events
			}
		}
	}

An example heart rate monitor app can be found at git.wow.st/gmp/hrm.