hybridgroup.gobot/platforms/ble
Thomas Kohler 002c75ce88
test(all): substitude assert.Nil by assert.NoError if useful (#1016)
2023-10-26 20:34:19 +02:00
..
LICENSE Build(v2): revert move to v2 subfolder (#932) 2023-05-29 19:23:28 +02:00
README.md core(build): CLI removed (#946) 2023-06-04 18:36:55 +02:00
battery_driver.go build(style): switch to gofumpt and add linters (#1009) 2023-10-20 20:50:42 +02:00
battery_driver_test.go test(all): substitude assert.Nil by assert.NoError if useful (#1016) 2023-10-26 20:34:19 +02:00
ble_client_adaptor.go build(style): switch to gofumpt and add linters (#1009) 2023-10-20 20:50:42 +02:00
ble_client_adaptor_test.go test(all): switch to test package stretchr testify (#1006) 2023-10-20 10:27:09 +02:00
device_information_driver.go Build(v2): revert move to v2 subfolder (#932) 2023-05-29 19:23:28 +02:00
device_information_driver_test.go test(all): substitude assert.Nil by assert.NoError if useful (#1016) 2023-10-26 20:34:19 +02:00
doc.go Build(v2): revert move to v2 subfolder (#932) 2023-05-29 19:23:28 +02:00
generic_access_driver.go all(style) : fix linter issues for errcheck, ineffassign, unused and fix errors (#950) 2023-06-12 19:51:25 +02:00
generic_access_driver_test.go test(all): substitude assert.Nil by assert.NoError if useful (#1016) 2023-10-26 20:34:19 +02:00
helpers_test.go Build(v2): revert move to v2 subfolder (#932) 2023-05-29 19:23:28 +02:00
serial_port.go all(style) : fix linter issues for errcheck, ineffassign, unused and fix errors (#950) 2023-06-12 19:51:25 +02:00
serial_port_test.go test(all): switch to test package stretchr testify (#1006) 2023-10-20 10:27:09 +02:00
uuid.go Build(v2): revert move to v2 subfolder (#932) 2023-05-29 19:23:28 +02: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 TinyGo Bluetooh package.

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

Please refer to the main README.md

macOS

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

Ubuntu

Everything should already just compile on most Linux systems.

Windows

You will need to have a GCC compiler such as mingw-w64 installed in order to use BLE on Windows.

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.

Connect on 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

Connect on 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/v2"
  "gobot.io/x/gobot/v2/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()
}