gobot.io/x/gobot@v1.16.0/examples/ble_generic_access.go (about)

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