gobot.io/x/gobot/v2@v2.1.0/examples/ble_generic_access.go (about)

     1  //go:build example
     2  // +build example
     3  
     4  //
     5  // Do not build by default.
     6  
     7  /*
     8   How to run
     9   Pass the Bluetooth address or name as the first param:
    10  
    11  	go run examples/ble_generic_access.go BB-1234
    12  
    13   NOTE: sudo is required to use BLE in Linux
    14  */
    15  
    16  package main
    17  
    18  import (
    19  	"fmt"
    20  	"os"
    21  
    22  	"gobot.io/x/gobot/v2"
    23  	"gobot.io/x/gobot/v2/platforms/ble"
    24  )
    25  
    26  func main() {
    27  	bleAdaptor := ble.NewClientAdaptor(os.Args[1])
    28  	access := ble.NewGenericAccessDriver(bleAdaptor)
    29  
    30  	work := func() {
    31  		fmt.Println("Device name:", access.GetDeviceName())
    32  		fmt.Println("Appearance:", access.GetAppearance())
    33  	}
    34  
    35  	robot := gobot.NewRobot("bleBot",
    36  		[]gobot.Connection{bleAdaptor},
    37  		[]gobot.Device{access},
    38  		work,
    39  	)
    40  
    41  	robot.Start()
    42  }