hybridgroup.gobot/platforms/ble
deadprogram d0e5e83ed1 ble: scanresult channel needs to handle linux scan results
Signed-off-by: deadprogram <ron@hybridgroup.com>
2020-11-27 19:14:38 +01:00
..
LICENSE docs: update copyright date to 2018 2018-02-14 08:24:39 +01:00
README.md ble: use hybridgroup fork of go-ble/ble package until Darwin changes get into upsteam version 2017-10-28 19:32:59 +02:00
battery_driver.go ble: initial take on working go-bluetooth replacement for go-ble 2020-11-27 19:14:38 +01:00
battery_driver_test.go ble: increase test coverage for battery, device information, and generic access drivers 2017-04-05 12:22:46 +02:00
ble_client_adaptor.go ble: scanresult channel needs to handle linux scan results 2020-11-27 19:14:38 +01:00
ble_client_adaptor_test.go ble: use new improved default namer to avoid API conflicts 2017-02-02 15:56:26 +01:00
device_information_driver.go ble: initial take on working go-bluetooth replacement for go-ble 2020-11-27 19:14:38 +01:00
device_information_driver_test.go ble: increase test coverage for battery, device information, and generic access drivers 2017-04-05 12:22:46 +02:00
doc.go ble: update docs to include reference to included drivers 2016-12-27 19:54:13 +01:00
generic_access_driver.go ble: initial take on working go-bluetooth replacement for go-ble 2020-11-27 19:14:38 +01:00
generic_access_driver_test.go ble: increase test coverage for battery, device information, and generic access drivers 2017-04-05 12:22:46 +02:00
helpers_test.go ble: correct spelling error in function name 2018-04-12 12:25:39 +02:00
serial_port.go ble: eliminate race conditions from response handling 2017-06-15 14:04:08 +02:00
serial_port_test.go firmata: WIP on adding support for BLE connected microcontrollers 2017-01-16 21:45:37 +01:00
uuid_darwin.go ble: updates so macOS works 2020-11-27 19:14:38 +01:00
uuid_linux.go ble: updates so macOS works 2020-11-27 19:14:38 +01:00

README.md

Bluetooth LE

The Gobot BLE adaptor makes it easy to interact with Bluetooth LE aka Bluetooth 4.0 using Go.

It is written using the ble package by @roylee17. Thank you!

Learn more about Bluetooth LE at http://en.wikipedia.org/wiki/Bluetooth_low_energy

This package also includes drivers for several well-known BLE Services:

  • Battery Service
  • Device Information Service
  • Generic Access Service

How to Install

go get -d -u gobot.io/x/gobot/...

OSX

You need to have XCode installed to be able to compile code that uses the Gobot BLE adaptor on OSX. This is because the ble package uses a CGo based implementation.

Ubuntu

Everything should already just compile on most Linux systems.

How To Connect

When using BLE a "peripheral" aka "server" is something you connect to such a a pulse meter. A "central" aka "client" is what does the connecting, such as your computer or mobile phone.

You need to know the BLE ID of the peripheral you want to connect to. The Gobot BLE client adaptor also lets you connect to a peripheral by friendly name.

OSX

To run any of the Gobot BLE code you must use the GODEBUG=cgocheck=0 flag in order to get around some of the issues in the CGo-based implementation.

If you connect by name, then you do not need to worry about the Bluetooth LE ID. However, if you want to connect by ID, OS X uses its own Bluetooth ID system which is different from the IDs used on Linux. The code calls thru the XPC interfaces provided by OSX, so as a result does not need to run under sudo.

For example:

GODEBUG=cgocheck=0 go run examples/minidrone.go 8b2f8032290143e18fc7c426619632e8

Ubuntu

On Linux the BLE code will need to run as a root user account. The easiest way to accomplish this is probably to use go build to build your program, and then to run the requesting executable using sudo.

For example:

go build examples/minidrone.go
sudo ./minidrone AA:BB:CC:DD:EE

Windows

Hopefully coming soon...

How to Use

Here is an example that uses the BLE "Battery" service to retrieve the current change level of the peripheral device:

package main

import (
	"fmt"
	"os"
	"time"

	"gobot.io/x/gobot"
	"gobot.io/x/gobot/platforms/ble"
)

func main() {
	bleAdaptor := ble.NewClientAdaptor(os.Args[1])
	battery := ble.NewBatteryDriver(bleAdaptor)

	work := func() {
		gobot.Every(5*time.Second, func() {
			fmt.Println("Battery level:", battery.GetBatteryLevel())
		})
	}

	robot := gobot.NewRobot("bleBot",
		[]gobot.Connection{bleAdaptor},
		[]gobot.Device{battery},
		work,
	)

	robot.Start()
}