Giter Club home page Giter Club logo

sluez's Introduction

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

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

Releases

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

Examples

# Get a current overview of your adapters and bluetooth devices
$ sluez status
Adapters:
1) name="jonathan-Blade" alias="jonathan-Blade" address="9C:B6:D0:1C:BB:B0" discoverable=true pairable=true powered=true discovering=false
Connected devices:
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
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

# Pair bluetooth devices, you will need to put you device into pairing mode,
# if --device or --device-name are not specified, sluez will pair with the first
# device it finds
$ sluez pairi --debug
[sluez] trying to pair bluetooth devices to "hci0"found no devices similar to specified device= or device-name=
waiting for new bluetooth devices, make sure to put device into pairing mode
[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[]]]
[sluez] trying to pair with device mac "2C:41:A1:49:37:CF"
successfully paired "2C:41:A1:49:37:CF" and "hci0"

# If no device is specified, the first device found will be connected. If
# there is more than one device, you will be asked to select the device.
$ ./sluez connect
Choose a bluetooth device from the following:
1) Pixel 2, 40:4E:36:9F:1E:EC
2) Bose QC35 II, 2C:41:A1:49:37:CF
>> 2
successfully connected "2C:41:A1:49:37:CF" and "hci0"

# Connect a bluetooth device by part of its device name, this will do a simple
# fuzzy search on known device names (device must be paired). It will find
# devices thate look like "bose", ie: "Bose QC35 II".
$ sluez connect --device-name=bose

# Or connect to your phone
$ sluez connect --device-name=pixel

# Disconnect a bluetooth device by its MAC
$ sluez disconnect --device=AA:BB:CC:11:22:33
successfully disconnected "2C:41:A1:49:37:CF" and "hci0

# Discover bluetooth devices as the become pairable or when they disconnect.
# This will watch for new events about bluetooth devices.
$ sluez discover

Usage

Simple CLI for Bluez dBus on linux

Usage:
  sluez [command]

Available Commands:
  connect     Connect a device to an adapter
  disconnect  Disconnect a device from an adapter
  discover    Discover will watch for devices as the connect or disconnect to an adapter
  help        Help about any command
  pair        Pair a device from to an adapter, requires your device to be in pairing mode
  remove      Remove a device from an adapter
  status      The current status of known adapters and devices

Flags:
  -a, --adapter string       HCI device adapter. Can be found from 'hciconfig -a' (default "hci0")
      --debug                Print debug logs
  -d, --device string        Bluetooth device MAC address
  -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
  -h, --help                 help for sluez

Use "sluez [command] --help" for more information about a command.

TODO

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

sluez's People

Contributors

vishen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

sluez's Issues

discover: crashes

on armv7l with go 1.11 and latest sluez version.

dev@devpi:~$ ./go/bin/sluez discover
Adapters:
1) name="devpi" alias="devpi" address="AA:AA:AA:AA:AA:AA" discoverable=false pairable=false powered=true discovering=false
Connected devices:
watching for new bluetooth events, make sure to put device into pairing mode
panic: interface conversion: interface {} is nil, not string

goroutine 1 [running]:
github.com/vishen/sluez/bluez.(*Bluez).ConvertToDevices(0x104c020, 0x10d0150, 0x25, 0x10be3c0, 0x3, 0x4d, 0x0)
	/home/dev/go/src/github.com/vishen/sluez/bluez/device.go:88 +0x52c
github.com/vishen/sluez/cmd.glob..func4(0x3d2f00, 0x3e4b70, 0x0, 0x0, 0x0, 0x0)
	/home/dev/go/src/github.com/vishen/sluez/cmd/discover.go:71 +0x6dc
github.com/vishen/sluez/vendor/github.com/spf13/cobra.(*Command).execute(0x3d2f00, 0x3e4b70, 0x0, 0x0, 0x3d2f00, 0x3e4b70)
	/home/dev/go/src/github.com/vishen/sluez/vendor/github.com/spf13/cobra/command.go:762 +0x364
github.com/vishen/sluez/vendor/github.com/spf13/cobra.(*Command).ExecuteC(0x3d3290, 0x16764, 0x1066030, 0x0)
	/home/dev/go/src/github.com/vishen/sluez/vendor/github.com/spf13/cobra/command.go:852 +0x210
github.com/vishen/sluez/vendor/github.com/spf13/cobra.(*Command).Execute(0x3d3290, 0x1066030, 0x0)
	/home/dev/go/src/github.com/vishen/sluez/vendor/github.com/spf13/cobra/command.go:800 +0x1c
github.com/vishen/sluez/cmd.Execute()
	/home/dev/go/src/github.com/vishen/sluez/cmd/root.go:33 +0x20
main.main()
	/home/dev/go/src/github.com/vishen/sluez/main.go:20 +0x14

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.