Bluetooth Low Energy for Go
Go to file
2019-12-06 14:00:55 -05:00
gatt Working Android implementation. 2019-11-27 10:44:37 -05:00
ns Improve handling of peripheral disconnections and some refactoring. 2019-12-05 08:49:41 -05:00
.gitignore Documentation 2019-11-27 11:11:42 -05:00
ble_android.go Improve handling of peripheral disconnections and some refactoring. 2019-12-05 08:49:41 -05:00
ble_darwin.go Improve handling of peripheral disconnections and some refactoring. 2019-12-05 08:49:41 -05:00
ble.go Improve handling of peripheral disconnections and some refactoring. 2019-12-05 08:49:41 -05:00
Ble.jar Improve handling of peripheral disconnections and some refactoring. 2019-12-05 08:49:41 -05:00
blessed-full.jar Working Android version using Blessed library. 2019-12-04 17:25:10 -05:00
BlessedConnect.java Improve handling of peripheral disconnections and some refactoring. 2019-12-05 08:49:41 -05:00
go.mod Working Android implementation. 2019-11-27 10:44:37 -05:00
go.sum Working Android implementation. 2019-11-27 10:44:37 -05:00
jni_android.c Improve handling of peripheral disconnections and some refactoring. 2019-12-05 08:49:41 -05:00
jni_android.go Partial android implementation, including Enable(), readyToScan(), 2019-11-22 16:15:02 -05:00
jni_android.h Further debuging version. 2019-12-04 16:09:54 -05:00
nswrap.yaml Improve handling of peripheral disconnections and some refactoring. 2019-12-05 08:49:41 -05:00
README.md Revert "Doc updates, add "wantScan" to BleConnect.java so scan starts" 2019-12-06 14:00:55 -05:00
timber.jar Conversion to Blessed library for Android -- interim check-in, 2019-12-04 14:47:56 -05:00

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
			}
		}
	}