Index

Battery Service


The BLE Battery Service is a well-known Bluetooth LE Service for checking a peripheral's battery level.

API Reference

How To Connect

bleAdaptor := ble.NewClientAdaptor("AA:BB:CC:DD:EE")
battery := ble.NewBatteryDriver(bleAdaptor)

How To Use

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

Compatibility