项目作者: vishen

项目描述 :
Simple bluez dbus command line client for linux
高级语言: Go
项目地址: git://github.com/vishen/sluez.git
创建时间: 2018-08-27T19:26:46Z
项目社区:https://github.com/vishen/sluez

开源协议:Apache License 2.0

下载


Sleuz (Simple Bluez) CLI for Linux

sleuz is a simple bluez dbus client for linux. It provides a command line interface
for interacting with bluez over the dbus protocol on linux, currently only the basic
commands and functionality are implemented.

This is a replacement for bluetoothctl on linux. bluetoothctl is very handy, but
the fact that it isn’t a command line interface makes it hard to use in scripts. sleuz
is usable in scripts as all the basic interactions are invokable via the command line.

Currently none of the authentication capabilities are implemented because I don’t
have a bluetooth device that requires authentication.

Installation

Using Go

  1. $ go get -u github.com/vishen/sluez

Releases

  1. # TODO: add releases for linux?
  2. $ curl -L -O https://github.com/vishen/sluez/releases/download/0.1.0/sluez_v0.1.0.tar.gz
  3. $ tar -zxvf sluez_v0.1.0.tar.gz
  4. $ ./sluez

Examples

  1. # Get a current overview of your adapters and bluetooth devices
  2. $ sluez status
  3. Adapters:
  4. 1) name="jonathan-Blade" alias="jonathan-Blade" address="9C:B6:D0:1C:BB:B0" discoverable=true pairable=true powered=true discovering=false
  5. Connected devices:
  6. 1) name="Pixel 2" alias="Pixel 2" address="40:4E:36:9F:1E:EC" adapter="/org/bluez/hci0" paired=true connected=false trusted=false blocked=false
  7. 2) name="Bose QC35 II" alias="Bose QC35 II" address="2C:41:A1:49:37:CF" adapter="/org/bluez/hci0" paired=true connected=false trusted=false blocked=fals
  8. # Pair bluetooth devices, you will need to put you device into pairing mode,
  9. # if --device or --device-name are not specified, sluez will pair with the first
  10. # device it finds
  11. $ sluez pairi --debug
  12. [sluez] trying to pair bluetooth devices to "hci0"found no devices similar to specified device= or device-name=
  13. waiting for new bluetooth devices, make sure to put device into pairing mode
  14. [sluez] received signal=org.freedesktop.DBus.ObjectManager.InterfacesAdded => (2)[/org/bluez/hci0/dev_2C_41_A1_49_37_CF map[org.freedesktop.DBus.Introspectable:map[] org.bluez.Device1:map[RSSI:@n -30 Modalias:"bluetooth:v009Ep4020d0251" Icon:"audio-card" Alias:"Bose QC35 II" Trusted:false LegacyPairing:false UUIDs:["0000110d-0000-1000-8000-00805f9b34fb", "0000110b-0000-1000-8000-00805f9b34fb", "0000110a-0000-1000-8000-00805f9b34fb", "0000110e-0000-1000-8000-00805f9b34fb", "0000110f-0000-1000-8000-00805f9b34fb", "00001130-0000-1000-8000-00805f9b34fb", "0000112e-0000-1000-8000-00805f9b34fb", "0000111e-0000-1000-8000-00805f9b34fb", "00001108-0000-1000-8000-00805f9b34fb", "00001131-0000-1000-8000-00805f9b34fb", "00000000-deca-fade-deca-deafdecacaff"] Adapter:@o "/org/bluez/hci0" Address:"2C:41:A1:49:37:CF" Blocked:false Connected:false Name:"Bose QC35 II" Paired:false Class:@u 2360344] org.freedesktop.DBus.Properties:map[]]]
  15. [sluez] trying to pair with device mac "2C:41:A1:49:37:CF"
  16. successfully paired "2C:41:A1:49:37:CF" and "hci0"
  17. # If no device is specified, the first device found will be connected. If
  18. # there is more than one device, you will be asked to select the device.
  19. $ ./sluez connect
  20. Choose a bluetooth device from the following:
  21. 1) Pixel 2, 40:4E:36:9F:1E:EC
  22. 2) Bose QC35 II, 2C:41:A1:49:37:CF
  23. >> 2
  24. successfully connected "2C:41:A1:49:37:CF" and "hci0"
  25. # Connect a bluetooth device by part of its device name, this will do a simple
  26. # fuzzy search on known device names (device must be paired). It will find
  27. # devices thate look like "bose", ie: "Bose QC35 II".
  28. $ sluez connect --device-name=bose
  29. # Or connect to your phone
  30. $ sluez connect --device-name=pixel
  31. # Disconnect a bluetooth device by its MAC
  32. $ sluez disconnect --device=AA:BB:CC:11:22:33
  33. successfully disconnected "2C:41:A1:49:37:CF" and "hci0
  34. # Discover bluetooth devices as the become pairable or when they disconnect.
  35. # This will watch for new events about bluetooth devices.
  36. $ sluez discover

Usage

  1. Simple CLI for Bluez dBus on linux
  2. Usage:
  3. sluez [command]
  4. Available Commands:
  5. connect Connect a device to an adapter
  6. disconnect Disconnect a device from an adapter
  7. discover Discover will watch for devices as the connect or disconnect to an adapter
  8. help Help about any command
  9. pair Pair a device from to an adapter, requires your device to be in pairing mode
  10. remove Remove a device from an adapter
  11. status The current status of known adapters and devices
  12. Flags:
  13. -a, --adapter string HCI device adapter. Can be found from 'hciconfig -a' (default "hci0")
  14. --debug Print debug logs
  15. -d, --device string Bluetooth device MAC address
  16. -n, --device-name string Bluetooth device name. A fuzzy search is used to determine which device the name matches for. '--device' will take precedence if both are specified
  17. -h, --help help for sluez
  18. Use "sluez [command] --help" for more information about a command.

TODO

  • Add command to be able to set device and/or adapter properties