gobot.io/x/gobot/v2@v2.1.0/examples/ble_device_info.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_device_info.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  	info := ble.NewDeviceInformationDriver(bleAdaptor)
    29  
    30  	work := func() {
    31  		fmt.Println("Model number:", info.GetModelNumber())
    32  		fmt.Println("Firmware rev:", info.GetFirmwareRevision())
    33  		fmt.Println("Hardware rev:", info.GetHardwareRevision())
    34  		fmt.Println("Manufacturer name:", info.GetManufacturerName())
    35  		fmt.Println("PnPId:", info.GetPnPId())
    36  	}
    37  
    38  	robot := gobot.NewRobot("bleBot",
    39  		[]gobot.Connection{bleAdaptor},
    40  		[]gobot.Device{info},
    41  		work,
    42  	)
    43  
    44  	robot.Start()
    45  }