Code Monkey home page Code Monkey logo

ble's People

Contributors

chenkaie avatar deadprogram avatar hasty avatar jaracil avatar lizrice avatar moogle19 avatar roylee17 avatar syoder avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ble's Issues

Subscribe call returns invalid attribute value length

I am connecting to a Health Thermometer and when I subscribe to the characteristic 2A1C to get indications back. It errors with the invalid attribute value length. I have been using notify on everything else (about 5 devices) and it works great. Does anybody know if indications are working correctly? It seems that the code has support for it. It seems notify is preferred, but this standard uses indications.

https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.service.health_thermometer.xml

# master-slave mode conversion

hi, I recently used the code to achieve BLE master-slave mode conversion. From mode to master mode is no problem. However, the main mode (scan) transfer to the mode encountered HCI resources can not open the problem. You probably do not really know the way I did it. I can simply say it. I set the scan time to 5min, after 5min has passed, I will call the stop () method to close the HCI interface and turn off the main_loop () (which polls the HCI for a while and calls the related functions to handle it) thread. After both are closed, I start ble_server again. It is at this time, there has been the problem of HCI interface can not be opened. I'm sure I've run stop () and did not print any errors.

  d.Stop()
  necessary.HCI_main_loop_chan <- 1 //this is used to end the main_loop thread 

  time.Sleep( 5 * time.Second)

  go ble_server()


If you have any good way to convert from master to slave or slave to master ,please tell me. Thanks!

Unhandled event & Failed to set MTU, err: Not implemented OS X Sierra

Hey fellow BLE Golangers,

I've noticed this error in trying to connect to a BLE light. Although the device I'm connecting to I don't think is related.

I'm on OS X Sierra:

uname -a
Darwin Geomon 16.1.0 Darwin Kernel Version 16.1.0: Thu Oct 13 21:26:57 PDT 2016; root:xnu-3789.21.3~60/RELEASE_X86_64 x86_64

With Go version:

go version
go version go1.7.3 darwin/amd64

The error is:

2016/11/16 17:03:31 Unhandled event: xpc.Dict{"kCBMsgId":53, "kCBMsgArgs":xpc.Dict{"kCBMsgArgDeviceUUID":xpc.UUID{0x97, 0x99, 0xe, 0x8, 0x6b, 0x9b, 0x4b, 0xc, 0x90, 0xb0, 0x7f, 0x86, 0x11, 0x3f, 0x30, 0x7f}, "kCBMsgArgATTMTU":23}}

Connected Peripheral ID:97990e086b9b4b0c90b07f86113f307f, NAME:()
Failed to set MTU, err: Not implemented
2016/11/16 17:03:31 Unhandled event: xpc.Dict{"kCBMsgId":81, "kCBMsgArgs":xpc.Dict{"kCBMsgArgSupervisionTimeout":500, "kCBMsgArgDeviceUUID":xpc.UUID{0x97, 0x99, 0xe, 0x8, 0x6b, 0x9b, 0x4b, 0xc, 0x90, 0xb0, 0x7f, 0x86, 0x11, 0x3f, 0x30, 0x7f}, "kCBMsgArgConnectionInterval":198, "kCBMsgArgConnectionLatency":0}}

The MTU error I guess is related to #3
But I am unsure of the XPC.Dict errors.

I am using both currantlabs/ble & currantlabs/gatt. However I am unsure where which of these the error is coming from.

If it's from currantlabs/gatt I can't add an issue at it's a fork of PayPal/gatt. And that project hasn't been touched it seems in a long while.

Peripheral Disconnect in General (but also does not get picked up by blesh)

As a client, Is there a way to get the disconnect notification when a peripheral disconnects. I used blesh and it does not see the device go away. In all other libraries, there is a way to know if the device goes away via a callback notification. I assume there is one here as well. And there may be other notifications as well that may be of interest.

Error on Linux while init'ing HCI

Here's a portion of the stacktrace:

panic: makechan: size out of range

goroutine 1 [running]:
panic(0x53e380, 0xc42000b1d0)
	/usr/local/Cellar/go/1.7.3/libexec/src/runtime/panic.go:500 +0x1a1
github.com/currantlabs/ble/linux/hci.NewPool(0x5, 0xffffffffffffffff, 0xc420039de8)
	/Users/syoder/src/golang/src/github.com/currantlabs/ble/linux/hci/buffer.go:19 +0x3e
github.com/currantlabs/ble/linux/hci.(*HCI).Init(0xc420096000, 0x0, 0x0)
	/Users/syoder/src/golang/src/github.com/currantlabs/ble/linux/hci/hci.go:152 +0x754
github.com/currantlabs/ble/linux.NewDevice(0x7fc022118080, 0xc420018db0, 0x56a0b2)
	/Users/syoder/src/golang/src/github.com/currantlabs/ble/linux/device.go:21 +0xac
...

Looks like it's trying to create a pool of buffers here: https://github.com/currantlabs/ble/blob/master/linux/hci/hci.go#L151

But bufCnt is zero, so it's trying to create a pool with -1 buffers, which crashes.

And here's the twist: it only crashes when I'm NOT running hcidump. When I am running it, bufCnt has a proper value (15). Maybe there's a race condition, and hcidump changes the timing?

If we can get to the bottom of this, I have a couple of PR's I'd like to submit that will add the ability to advertise arbitrary manufacturer and service advertisements (to allow altBeacon and Eddystone advertisements) on both mac and linux.

notifyhandler

Hi
if i subscribe to characteristic the notfyhandler function has only one input req []bytes
how do i know which characteristic is sending notification ?
at least the uuid should be part of notifier

WriteCharacteristic on Linux Doesn't Appear To Write

I'm writing a configuration characteristic on the Nordic Thingy 52. So in order to do so, I've followed the example code in blesh to a tee.

Expected Behavior

When I write this data blob to the characteristic in question, and read it back it should read 701760ea60eadc0503674e1d

    data,_ := hex.DecodeString("701760ea60eadc0503674e1d")

    fmt.Printf("[ %s ] Intended config: %x %d\n", m.client.Address().String(), data, len(data))

    err := m.client.WriteCharacteristic(u.(*ble.Characteristic),data,true)
    if err != nil {
      return errors.Wrap(err, "can't write characteristic")
    }

    new, err := m.client.ReadCharacteristic(u.(*ble.Characteristic))
    if err != nil {
      return errors.Wrap(err, "can't read characteristic")
    }
    fmt.Printf("[ %s ] Config read: %x\n", m.client.Address().String(), new)

Observed behavior

When I read back the characteristic it displays the still default value of 60ea60ea60eadc0503674e1d

Note: that this value can be changed with the phone app no problem.

Ble Gatt Server: How to monitor incoming connection / disconnection ?

Hello !
I started to use this wonderful library for a RaspberryPi based project.
It works very well and its stable with the latest Raspbian.
However, I would like to know when a Central successfully connects the Peripheral I created, and more importantly I would like to know when the Central disconnects. The goal is to make my application more robust to these events.

I started to check the code but I am not experienced enough with HCI Socket thing, and I would like to know if there is a solution (undocumented/workaround) to monitor theses events.

Thanks !

Linux - Unable to Connect() to more than one peripheral at same time

I am unable to connect to more than one peripheral at same time when using Linux. Here is an example that illustrates the problem:

package main

import (
	"fmt"
	"log"
	"os"
	"strings"
	"time"

	"golang.org/x/net/context"

	"github.com/currantlabs/ble"
	"github.com/currantlabs/ble/examples/lib/dev"
)

func main() {
	d, err := dev.NewDevice("default")
	if err != nil {
		log.Fatalf("can't new device : %s", err)
	}
	ble.SetDefaultDevice(d)

	ctx1 := ble.WithSigHandler(context.WithTimeout(context.Background(), 5*time.Second))
	cln1 := doConnect(os.Args[1], ctx1)

	ctx2, _ := context.WithTimeout(context.Background(), 15*time.Second)
	cln2 := doConnect(os.Args[2], ctx2)

	fmt.Printf("Disconnecting [ %s ]... (this might take up to few seconds on OS X)\n", cln1.Address())
	cln1.CancelConnection()

	fmt.Printf("Disconnecting [ %s ]... (this might take up to few seconds on OS X)\n", cln2.Address())
	cln2.CancelConnection()
}

func getFilter(name string) func(a ble.Advertisement) bool {
	return func(a ble.Advertisement) bool {
		return strings.ToUpper(a.LocalName()) == strings.ToUpper(name)
	}
}

func doConnect(name string, ctx context.Context) ble.Client {
	filter := getFilter(name)

	fmt.Println("Scanning...")
	cln, err := ble.Connect(ctx, filter)
	if err != nil {
		log.Fatalf("can't connect : %s", err)
	}

	fmt.Printf("Discovering profile...\n")
	p, err := cln.DiscoverProfile(true)
	if err != nil {
		log.Fatalf("can't discover profile: %s", err)
	}

	fmt.Println("P:", p)
	return cln
}

When I run the above code, I get the following output:

$ sudo ./mutiple_connect BB-7108 2B-DCC6
Scanning...
Discovering profile...
P: &{[0xc4200c2040 0xc4200c2080 0xc4200c2140 0xc4200b4440 0xc4200b4500 0xc4200b45c0]}
Scanning...
Discovering profile...

It appears that I am unable to connect/discover the profile for the second client connection using the same device. Sometimes it hangs on the second Connect(), sometimes on the second DiscoverProfile()

Here is an hcidump file I logged while attempting to connect.
multiple-connect.txt

Is it possible to "free" the physical Bluetooth interface so that it can be used by external commands?

I would like to be able to use the physical Bluetooth interface without stopping the go application so I need some way to free up the device once it has been initialised. Is this possible?

While the code is running I get errors as expected:

package main

import (
	"flag"
	"fmt"
	"log"
	"time"

	"github.com/currantlabs/ble/examples/lib/dev"
)

var (
	device = flag.String("device", "default", "implementation of ble")
)

func main() {
	_, err := dev.NewDevice(*device)
	if err != nil {
		log.Fatalf("can't new device : %s", err)
	}
	fmt.Println("opened")

	time.Sleep(100 * time.Second)
}
 ~  gatttool -I -t random -b E0:1A:35:05:47:EB
[E0:1A:35:05:47:EB][LE]> connect
Attempting to connect to E0:1A:35:05:47:EB
Error: connect: No route to host (113)
[E0:1A:35:05:47:EB][LE]> 
[E0:1A:35:05:47:EB][LE]> 
 ~  sudo hciconfig hci0 reset
Can't down device hci0: Device or resource busy (16)
 ✘  ~  sudo hciconfig hci0 down 
Can't down device hci0: Device or resource busy (16)
 ✘  ~  hciconfig dev
hci0:    Type: Primary  Bus: USB
    BD Address: E4:B3:18:4D:40:8F  ACL MTU: 1021:4  SCO MTU: 96:6
    UP RUNNING 
    RX bytes:49338 acl:2 sco:0 events:3888 errors:0
    TX bytes:625918 acl:181 sco:0 commands:4087 errors:0

 ~  gatttool -I -t random -b E0:1A:35:05:47:EB
[E0:1A:35:05:47:EB][LE]> connect
Attempting to connect to E0:1A:35:05:47:EB
Error: connect: No route to host (113)
[E0:1A:35:05:47:EB][LE]> 

Is it possible to free the device created and then use external commands during the sleep period?

linux: Unable to subscribe to GATT characteristic

Hi, @roylee17

I have been testing this package with a WICED Sense device on Ubuntu 14.04. I was able to scan, and explore with no problems thus far. I then tried to subscribe to notifications, and received an error unexpected EOF.

$ sudo ./bin/explorer --name="WICED Sense Kit" --sub="10s"
2016/07/01 11:34:23 dev: hci0 up
2016/07/01 11:34:23 dev: hci0 reset
2016/07/01 11:34:23 dev: hci0 down
2016/07/01 11:34:23 dev: hci0 opened
Exploring Peripheral [ 20:73:77:65:43:21 ] ...
Service: 1801 Generic Attribute

Service: 1800 Generic Access
  Characteristic: 2A00, Property: 0x02, Device Name
    Value         57494345442053656e7365204b697400 | "WICED Sense Kit\x00"
  Characteristic: 2A01, Property: 0x02, Appearance
    Value         0002 | "\x00\x02"

Service: 739298B687B64984A5DCBDC18B068985 
  Characteristic: 33EF91133B55413EB553FEA1EAADA459, Property: 0x12, 
    Value         0000000000000000000000000000000000000000 | "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    Descriptor: 2902, Client Characteristic Configuration
    Value         0000 | "\x00\x00"

-- Subscribe to notification for 10s --
2016/07/01 11:34:26 subscribe failed: unexpected EOF

It appears that when the GATT client writes:
https://github.com/currantlabs/ble/blob/master/linux/gatt/client.go#L273

that when it calls the ATT client's Write: https://github.com/currantlabs/ble/blob/master/linux/att/client.go#L336

the sendReq function here https://github.com/currantlabs/ble/blob/master/linux/att/client.go#L350

is returning the error from here: https://github.com/currantlabs/ble/blob/master/linux/att/client.go#L501

Perhaps this is related to some specific value or behaviour of the WICED Sense device. I was able to run the explorer on a LightBlue bean on Linux, and did not have this particular error.

Client connection closing when it shouldn't

I noticed my device was getting disconnected pretty much as soon as a connection was made, thus preventing me from interacting with the device. I then ran the explorer example and the connection still closes before it should - I have reduced the explorer example down to a minimal reproducible example.

main.go

package main

import (
	"fmt"
	"log"
	"strings"
	"time"

	"golang.org/x/net/context"

	"github.com/currantlabs/ble"
	"github.com/currantlabs/ble/examples/lib/dev"
)

func main() {
	d, err := dev.NewDevice("default")
	if err != nil {
		log.Fatalf("can't new device : %s", err)
	}
	ble.SetDefaultDevice(d)

	filter := func(a ble.Advertisement) bool {
		return strings.ToUpper(a.Address().String()) == strings.ToUpper("FA:D3:31:E8:A6:5D")
	}

	fmt.Printf("Scanning for %s...\n", 5 * time.Second)
	ctx := ble.WithSigHandler(context.WithTimeout(context.Background(), 5 * time.Second))
	cln, err := ble.Connect(ctx, filter)
	if err != nil {
		log.Fatalf("can't connect : %s", err)
	}

	go func() {
		cln.Disconnected()
		fmt.Printf("[ %s ] is disconnected \n", cln.Address())
	}()

	time.Sleep(10 * time.Second)

	fmt.Printf("Disconnecting [ %s ]... (this might take up to few seconds on OS X)\n", cln.Address())
	cln.CancelConnection()
}

Output

$ sudo ./explorer
Scanning for 5s...
[ fa:d3:31:e8:a6:5d ] is disconnected 
Disconnecting [ fa:d3:31:e8:a6:5d ]... (this might take up to few seconds on OS X)

Strace

sudo strace -f -tt -e trace=ioctl,socket,close,open ./explorer                       

16:07:12.366993 open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
16:07:12.367235 close(3)                = 0
16:07:12.367309 open("/usr/lib/libpthread.so.0", O_RDONLY|O_CLOEXEC) = 3
16:07:12.367615 close(3)                = 0
16:07:12.367677 open("/usr/lib/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
16:07:12.367966 close(3)                = 0
strace: Process 9135 attached
strace: Process 9136 attached
strace: Process 9137 attached
strace: Process 9138 attached
[pid  9134] 16:07:12.373841 ioctl(1, TCGETS, {B38400 opost isig icanon echo ...}) = 0
[pid  9134] 16:07:12.374226 close(3)    = 0
[pid  9134] 16:07:12.374290 socket(AF_INET, SOCK_STREAM, IPPROTO_TCP) = 3
[pid  9134] 16:07:12.374335 close(3)    = 0
[pid  9134] 16:07:12.374377 socket(AF_INET6, SOCK_STREAM, IPPROTO_TCP) = 3
[pid  9134] 16:07:12.374458 socket(AF_INET6, SOCK_STREAM, IPPROTO_TCP) = 4
[pid  9134] 16:07:12.374552 close(4)    = 0
[pid  9134] 16:07:12.374591 close(3)    = 0
[pid  9134] 16:07:12.374697 socket(AF_BLUETOOTH, SOCK_RAW, 1) = 3
[pid  9134] 16:07:12.374738 ioctl(3, HCIGETDEVLIST, 0xc42004fbbc) = 0
[pid  9134] 16:07:12.374782 ioctl(3, HCIDEVDOWN, 0) = 0
[pid  9134] 16:07:12.374821 ioctl(3, HCIDEVUP, 0) = 0
[pid  9134] 16:07:14.042167 ioctl(3, HCIDEVDOWN, 0) = 0
Scanning for 5s...
strace: Process 9144 attached
strace: Process 9145 attached
strace: Process 9143 attached
[ fa:d3:31:e8:a6:5d ] is disconnected 
Disconnecting [ fa:d3:31:e8:a6:5d ]... (this might take up to few seconds on OS X)
[pid  9145] 16:07:24.514802 +++ exited with 0 +++
[pid  9144] 16:07:24.514901 +++ exited with 0 +++
[pid  9138] 16:07:24.514930 +++ exited with 0 +++
[pid  9137] 16:07:24.515001 +++ exited with 0 +++
[pid  9136] 16:07:24.515039 +++ exited with 0 +++
[pid  9135] 16:07:24.515064 +++ exited with 0 +++
[pid  9143] 16:07:24.516427 +++ exited with 0 +++
16:07:24.516469 +++ exited with 0 +++

hcidump

HCI sniffer - Bluetooth packet analyzer ver 5.43
device: hci0 snap_len: 1500 filter: 0xffffffffffffffff
< HCI Command: Reset (0x03|0x0003) plen 0
> HCI Event: Command Complete (0x0e) plen 4
    Reset (0x03|0x0003) ncmd 2
    status 0x00
< HCI Command: Read Local Supported Features (0x04|0x0003) plen 0
> HCI Event: Command Complete (0x0e) plen 12
    Read Local Supported Features (0x04|0x0003) ncmd 1
    status 0x00
    Features: 0xbf 0xfe 0x0f 0xfe 0xdb 0xff 0x7b 0x87
< HCI Command: Read Local Version Information (0x04|0x0001) plen 0
> HCI Event: Command Complete (0x0e) plen 12
    Read Local Version Information (0x04|0x0001) ncmd 1
    status 0x00
    HCI Version: 4.1 (0x7) HCI Revision: 0x100
    LMP Version: 4.1 (0x7) LMP Subversion: 0x100
    Manufacturer: Intel Corp. (2)
< HCI Command: Read BD ADDR (0x04|0x0009) plen 0
> HCI Event: Command Complete (0x0e) plen 10
    Read BD ADDR (0x04|0x0009) ncmd 1
    status 0x00 bdaddr E4:B3:18:4D:40:8F
< HCI Command: Read Buffer Size (0x04|0x0005) plen 0
> HCI Event: Command Complete (0x0e) plen 11
    Read Buffer Size (0x04|0x0005) ncmd 1
    status 0x00
    ACL MTU 1021:4 SCO MTU 96:6
< HCI Command: Read Class of Device (0x03|0x0023) plen 0
> HCI Event: Command Complete (0x0e) plen 7
    Read Class of Device (0x03|0x0023) ncmd 1
    status 0x00 class 0x000000
< HCI Command: Read Local Name (0x03|0x0014) plen 0
> HCI Event: Command Complete (0x0e) plen 252
    Read Local Name (0x03|0x0014) ncmd 1
    status 0x00 name 'Bluemoon Universal Bluetooth Host Controller'
< HCI Command: Read Voice Setting (0x03|0x0025) plen 0
> HCI Event: Command Complete (0x0e) plen 6
    Read Voice Setting (0x03|0x0025) ncmd 1
    status 0x00 voice setting 0x0060
< HCI Command: Read Number of Supported IAC (0x03|0x0038) plen 0
> HCI Event: Command Complete (0x0e) plen 5
    Read Number of Supported IAC (0x03|0x0038) ncmd 1
< HCI Command: Read Current IAC LAP (0x03|0x0039) plen 0
> HCI Event: Command Complete (0x0e) plen 8
    Read Current IAC LAP (0x03|0x0039) ncmd 2
    IAC 0x9e8b33 (General Inquiry Access Code)
< HCI Command: Set Event Filter (0x03|0x0005) plen 1
    type 0 condition 0
    Clear all filters
> HCI Event: Command Complete (0x0e) plen 4
    Set Event Filter (0x03|0x0005) ncmd 1
    status 0x00
< HCI Command: Write Connection Accept Timeout (0x03|0x0016) plen 2
    timeout 32000
> HCI Event: Command Complete (0x0e) plen 4
    Write Connection Accept Timeout (0x03|0x0016) ncmd 1
    status 0x00
< HCI Command: LE Read Buffer Size (0x08|0x0002) plen 0
> HCI Event: Command Complete (0x0e) plen 7
    LE Read Buffer Size (0x08|0x0002) ncmd 1
    status 0x00 pktlen 0x001b maxpkt 0x07
< HCI Command: LE Read Local Supported Features (0x08|0x0003) plen 0
> HCI Event: Command Complete (0x0e) plen 12
    LE Read Local Supported Features (0x08|0x0003) ncmd 1
    status 0x00 features 0x1f00000000000000 (Link Layer supports LE Encryption)
< HCI Command: LE Read Supported States (0x08|0x001c) plen 0
> HCI Event: Command Complete (0x0e) plen 12
    LE Read Supported States (0x08|0x001c) ncmd 1
< HCI Command: Read Local Supported Commands (0x04|0x0002) plen 0
> HCI Event: Command Complete (0x0e) plen 68
    Read Local Supported Commands (0x04|0x0002) ncmd 1
    status 0x00
    Commands: fffffb03ccffefffff3ffc9ff30fe8fe3ff78fff1c00040061f7ffff7fb80000
              fe3f
< HCI Command: Write Simple Pairing Mode (0x03|0x0056) plen 1
    mode 0x01
> HCI Event: Command Complete (0x0e) plen 4
    Write Simple Pairing Mode (0x03|0x0056) ncmd 1
    status 0x00
< HCI Command: Write Inquiry Mode (0x03|0x0045) plen 1
    mode 2
> HCI Event: Command Complete (0x0e) plen 4
    Write Inquiry Mode (0x03|0x0045) ncmd 2
    status 0x00
< HCI Command: Read Inquiry Response Transmit Power Level (0x03|0x0058) plen 0
> HCI Event: Command Complete (0x0e) plen 5
    Read Inquiry Response Transmit Power Level (0x03|0x0058) ncmd 1
    status 0x00 level 7
< HCI Command: Read Local Extended Features (0x04|0x0004) plen 1
    page 1
> HCI Event: Command Complete (0x0e) plen 14
    Read Local Extended Features (0x04|0x0004) ncmd 1
    status 0x00 page 1 max 2
    Features: 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00
< HCI Command: Set Event Mask (0x03|0x0001) plen 8
    Mask: 0xfffffbff07f8bf3d
> HCI Event: Command Complete (0x0e) plen 4
    Set Event Mask (0x03|0x0001) ncmd 1
    status 0x00
< HCI Command: Read Stored Link Key (0x03|0x000d) plen 7
    bdaddr 00:00:00:00:00:00 all 1
> HCI Event: Command Complete (0x0e) plen 8
    Read Stored Link Key (0x03|0x000d) ncmd 1
    status 0x00 max 5 num 0
< HCI Command: Write Default Link Policy Settings (0x02|0x000f) plen 2
    policy 0x05
    Link policy: RSWITCH SNIFF 
> HCI Event: Command Complete (0x0e) plen 4
    Write Default Link Policy Settings (0x02|0x000f) ncmd 1
    status 0x00
< HCI Command: Read Page Scan Activity (0x03|0x001b) plen 0
> HCI Event: Command Complete (0x0e) plen 8
    Read Page Scan Activity (0x03|0x001b) ncmd 2
    status 0x00 interval 2048 window 18
< HCI Command: Read Page Scan Type (0x03|0x0046) plen 0
> HCI Event: Command Complete (0x0e) plen 5
    Read Page Scan Type (0x03|0x0046) ncmd 2
< HCI Command: LE Set Event Mask (0x08|0x0001) plen 8
    mask 0x3f00000000000000 (Reserved)
> HCI Event: Command Complete (0x0e) plen 4
    LE Set Event Mask (0x08|0x0001) ncmd 1
    status 0x00
< HCI Command: LE Read Advertising Channel Tx Power (0x08|0x0007) plen 0
> HCI Event: Command Complete (0x0e) plen 5
    LE Read Advertising Channel Tx Power (0x08|0x0007) ncmd 1
    status 0x00 level 0x7 (dBm)
< HCI Command: LE Read White List Size (0x08|0x000f) plen 0
> HCI Event: Command Complete (0x0e) plen 5
    LE Read White List Size (0x08|0x000f) ncmd 1
< HCI Command: LE Clear White List (0x08|0x0010) plen 0
> HCI Event: Command Complete (0x0e) plen 4
    LE Clear White List (0x08|0x0010) ncmd 1
    status 0x00
< HCI Command: Write LE Host Supported (0x03|0x006d) plen 2
> HCI Event: Command Complete (0x0e) plen 4
    Write LE Host Supported (0x03|0x006d) ncmd 1
< HCI Command: Read Local Extended Features (0x04|0x0004) plen 1
    page 2
> HCI Event: Command Complete (0x0e) plen 14
    Read Local Extended Features (0x04|0x0004) ncmd 1
    status 0x00 page 2 max 2
    Features: 0x20 0x0b 0x00 0x00 0x00 0x00 0x00 0x00
< HCI Command: Delete Stored Link Key (0x03|0x0012) plen 7
    bdaddr 00:00:00:00:00:00 all 1
> HCI Event: Command Complete (0x0e) plen 6
    Delete Stored Link Key (0x03|0x0012) ncmd 1
    status 0x00 deleted 0
< HCI Command: Set Event Mask Page 2 (0x03|0x0063) plen 8
    Mask: 0x0000800000000000
> HCI Event: Command Complete (0x0e) plen 4
    Set Event Mask Page 2 (0x03|0x0063) ncmd 1
    status 0x00
< HCI Command: Unknown (0x04|0x000b) plen 0
> HCI Event: Command Complete (0x0e) plen 12
    Unknown (0x04|0x000b) ncmd 1
< HCI Command: Unknown (0x03|0x007a) plen 1
> HCI Event: Command Complete (0x0e) plen 4
    Unknown (0x03|0x007a) ncmd 1
< HCI Command: LE Set Advertising Data (0x08|0x0008) plen 32
> HCI Event: Command Complete (0x0e) plen 4
    LE Set Advertising Data (0x08|0x0008) ncmd 1
    status 0x00
< HCI Command: LE Set Scan Response Data (0x08|0x0009) plen 32
> HCI Event: Command Complete (0x0e) plen 4
    LE Set Scan Response Data (0x08|0x0009) ncmd 1
    status 0x00
< HCI Command: Write Class of Device (0x03|0x0024) plen 3
    class 0x00010c
> HCI Event: Command Complete (0x0e) plen 4
    Write Class of Device (0x03|0x0024) ncmd 1
    status 0x00
< HCI Command: Write Local Name (0x03|0x0013) plen 248
    name 'x1pro'
> HCI Event: Command Complete (0x0e) plen 4
    Write Local Name (0x03|0x0013) ncmd 1
    status 0x00
< HCI Command: Write Extended Inquiry Response (0x03|0x0052) plen 241
    fec 0x00
    Complete local name: 'x1pro'
    TX power level: 7
    Unknown type 0x10 with 8 bytes data
    Complete service classes: 0x1800 0x1801 0x110e 0x110c
> HCI Event: Command Complete (0x0e) plen 4
    Write Extended Inquiry Response (0x03|0x0052) ncmd 1
    status 0x00
< HCI Command: Reset (0x03|0x0003) plen 0
> HCI Event: Command Complete (0x0e) plen 4
    Reset (0x03|0x0003) ncmd 2
    status 0x00
< HCI Command: Read BD ADDR (0x04|0x0009) plen 0
> HCI Event: Command Complete (0x0e) plen 10
    Read BD ADDR (0x04|0x0009) ncmd 1
    status 0x00 bdaddr E4:B3:18:4D:40:8F
< HCI Command: Read Buffer Size (0x04|0x0005) plen 0
> HCI Event: Command Complete (0x0e) plen 11
    Read Buffer Size (0x04|0x0005) ncmd 1
    status 0x00
    ACL MTU 1021:4 SCO MTU 96:6
< HCI Command: LE Read Buffer Size (0x08|0x0002) plen 0
> HCI Event: Command Complete (0x0e) plen 7
    LE Read Buffer Size (0x08|0x0002) ncmd 1
    status 0x00 pktlen 0x001b maxpkt 0x07
< HCI Command: LE Read Advertising Channel Tx Power (0x08|0x0007) plen 0
> HCI Event: Command Complete (0x0e) plen 5
    LE Read Advertising Channel Tx Power (0x08|0x0007) ncmd 1
    status 0x00 level 0x7 (dBm)
< HCI Command: LE Set Event Mask (0x08|0x0001) plen 8
    mask 0x1f00000000000000 (Reserved)
> HCI Event: Command Complete (0x0e) plen 4
    LE Set Event Mask (0x08|0x0001) ncmd 1
    status 0x00
< HCI Command: Set Event Mask (0x03|0x0001) plen 8
    Mask: 0xfffffbff07f8bf3d
> HCI Event: Command Complete (0x0e) plen 4
    Set Event Mask (0x03|0x0001) ncmd 1
    status 0x00
< HCI Command: Write LE Host Supported (0x03|0x006d) plen 2
> HCI Event: Command Complete (0x0e) plen 4
    Write LE Host Supported (0x03|0x006d) ncmd 1
< HCI Command: LE Set Advertising Parameters (0x08|0x0006) plen 15
    min 20.000ms, max 20.000ms
    type 0x00 (ADV_IND - Connectable undirected advertising) ownbdaddr 0x00 (Public)
    directbdaddr 0x00 (Public) 00:00:00:00:00:00
    channelmap 0x07 filterpolicy 0x00 (Allow scan from any, connection from any)
> HCI Event: Command Complete (0x0e) plen 4
    LE Set Advertising Parameters (0x08|0x0006) ncmd 1
    status 0x00
< HCI Command: LE Set Scan Parameters (0x08|0x000b) plen 7
    type 0x01 (active)
    interval 2.500ms window 2.500ms
    own address: 0x00 (Public) policy: All
> HCI Event: Command Complete (0x0e) plen 4
    LE Set Scan Parameters (0x08|0x000b) ncmd 1
    status 0x00
< HCI Command: LE Set Scan Enable (0x08|0x000c) plen 2
    value 0x01 (scanning enabled)
    filter duplicates 0x01 (enabled)
> HCI Event: Command Complete (0x0e) plen 4
    LE Set Scan Enable (0x08|0x000c) ncmd 2
    status 0x00
> HCI Event: LE Meta Event (0x3e) plen 23
    LE Advertising Report
      ADV_IND - Connectable undirected advertising (0)
      bdaddr D0:03:4B:49:64:7C (Public)
      Flags: 0x1a
      Unknown type 0xff with 6 bytes data
      RSSI: -76
> HCI Event: LE Meta Event (0x3e) plen 12
    LE Advertising Report
      SCAN_RSP - Scan Response (4)
      bdaddr D0:03:4B:49:64:7C (Public)
      RSSI: -76
> HCI Event: LE Meta Event (0x3e) plen 29
    LE Advertising Report
      ADV_IND - Connectable undirected advertising (0)
      bdaddr E0:73:DB:AE:F5:89 (Random)
      Flags: 0x05
      Complete local name: 'Puck.js f589'
      RSSI: -65
> HCI Event: LE Meta Event (0x3e) plen 30
    LE Advertising Report
      SCAN_RSP - Scan Response (4)
      bdaddr E0:73:DB:AE:F5:89 (Random)
      Unknown type 0x07 with 16 bytes data
      RSSI: -65
> HCI Event: LE Meta Event (0x3e) plen 38
    LE Advertising Report
      ADV_IND - Connectable undirected advertising (0)
      bdaddr FA:D3:31:E8:A6:5D (Random)
      Flags: 0x06
      Complete local name: 'BBC micro:bit [14539]'
      RSSI: -53
> HCI Event: LE Meta Event (0x3e) plen 12
    LE Advertising Report
      SCAN_RSP - Scan Response (4)
      bdaddr FA:D3:31:E8:A6:5D (Random)
      RSSI: -53
< HCI Command: LE Set Scan Enable (0x08|0x000c) plen 2
    value 0x00 (scanning disabled)
    filter duplicates 0x01 (enabled)
> HCI Event: Command Complete (0x0e) plen 4
    LE Set Scan Enable (0x08|0x000c) ncmd 2
    status 0x00
< HCI Command: LE Create Connection (0x08|0x000d) plen 25
    bdaddr FA:D3:31:E8:A6:5D type 1
    interval 4 window 4 initiator_filter 0
    own_bdaddr_type 0 min_interval 6 max_interval 6
    latency 0 supervision_to 72 min_ce 0 max_ce 0
> HCI Event: Command Status (0x0f) plen 4
    LE Create Connection (0x08|0x000d) status 0x00 ncmd 2
> HCI Event: LE Meta Event (0x3e) plen 19
    LE Connection Complete
      status 0x00 handle 3585, role master
      bdaddr FA:D3:31:E8:A6:5D (Random)
< HCI Command: Disconnect (0x01|0x0006) plen 3
    handle 3585 reason 0x13
    Reason: Remote User Terminated Connection
> HCI Event: Command Status (0x0f) plen 4
    Disconnect (0x01|0x0006) status 0x00 ncmd 1

Gattool works (the address type is random)
Output

gatttool -I -t random -b FA:D3:31:E8:A6:5D
[FA:D3:31:E8:A6:5D][LE]> connect
Attempting to connect to FA:D3:31:E8:A6:5D
Connection successful
[FA:D3:31:E8:A6:5D][LE]> disconnect

(gatttool:12770): GLib-WARNING **: Invalid file descriptor.

[FA:D3:31:E8:A6:5D][LE]>

hcidump

HCI sniffer - Bluetooth packet analyzer ver 5.43
device: hci0 snap_len: 1500 filter: 0xffffffffffffffff
< HCI Command: LE Add Device To White List (0x08|0x0011) plen 7
> HCI Event: Command Complete (0x0e) plen 4
    LE Add Device To White List (0x08|0x0011) ncmd 1
    status 0x00
< HCI Command: LE Set Scan Parameters (0x08|0x000b) plen 7
    type 0x00 (passive)
    interval 60.000ms window 30.000ms
    own address: 0x00 (Public) policy: white list only
> HCI Event: Command Complete (0x0e) plen 4
    LE Set Scan Parameters (0x08|0x000b) ncmd 1
    status 0x00
< HCI Command: LE Set Scan Enable (0x08|0x000c) plen 2
    value 0x01 (scanning enabled)
    filter duplicates 0x01 (enabled)
> HCI Event: Command Complete (0x0e) plen 4
    LE Set Scan Enable (0x08|0x000c) ncmd 2
    status 0x00
> HCI Event: LE Meta Event (0x3e) plen 38
    LE Advertising Report
      ADV_IND - Connectable undirected advertising (0)
      bdaddr FA:D3:31:E8:A6:5D (Random)
      Flags: 0x06
      Complete local name: 'BBC micro:bit [14539]'
      RSSI: -48
< HCI Command: LE Set Scan Enable (0x08|0x000c) plen 2
    value 0x00 (scanning disabled)
    filter duplicates 0x00 (disabled)
> HCI Event: Command Complete (0x0e) plen 4
    LE Set Scan Enable (0x08|0x000c) ncmd 2
    status 0x00
< HCI Command: LE Create Connection (0x08|0x000d) plen 25
    bdaddr FA:D3:31:E8:A6:5D type 1
    interval 96 window 96 initiator_filter 0
    own_bdaddr_type 0 min_interval 40 max_interval 56
    latency 0 supervision_to 42 min_ce 0 max_ce 0
> HCI Event: Command Status (0x0f) plen 4
    LE Create Connection (0x08|0x000d) status 0x00 ncmd 2
> HCI Event: LE Meta Event (0x3e) plen 19
    LE Connection Complete
      status 0x00 handle 3585, role master
      bdaddr FA:D3:31:E8:A6:5D (Random)
< HCI Command: LE Read Remote Used Features (0x08|0x0016) plen 2
> HCI Event: Command Status (0x0f) plen 4
    LE Read Remote Used Features (0x08|0x0016) status 0x00 ncmd 1
> HCI Event: LE Meta Event (0x3e) plen 12
    LE Read Remote Used Features Complete
      status 0x00 handle 3585
      Features: 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00
< HCI Command: Disconnect (0x01|0x0006) plen 3
    handle 3585 reason 0x13
    Reason: Remote User Terminated Connection
> HCI Event: Command Status (0x0f) plen 4
    Disconnect (0x01|0x0006) status 0x00 ncmd 1
> HCI Event: Disconn Complete (0x05) plen 4
    status 0x00 handle 3585 reason 0x16
    Reason: Connection Terminated by Local Host

Notes:

  • Using the master branch of this repo
  • Tried with a few different devices
  • The bluetoothd service is disabled
  • bluez version is 5.43-2
  • uname -a outputs Linux x1pro 4.9.6-1-ARCH #1 SMP PREEMPT Thu Jan 26 09:22:26 CET 2017 x86_64 GNU/Linux
  • Tried lots of rfkill, hciconfig hci0 reset etc etc.

Thanks in advance

linux: Unable to Dial certain periperals

When trying on Ubuntu 14.04 to explore a Parrot Minidrone, I am unable to connect aka Dial. I have the same problem with a Sphero Ollie.

Here are my debug logs:

$ sudo LOGXI=* ./bin/explorer -name="Mars_143521"
2016/07/02 10:34:56 dev: hci0 up
2016/07/02 10:34:56 dev: hci0 reset
2016/07/02 10:34:56 dev: hci0 down
2016/07/02 10:34:56 dev: hci0 opened
10:34:56.771410 INF hci state +: AdvertisingUpdated
10:34:56.774330 INF hci state -: AdvertisingUpdated
10:34:56.774391 INF hci state +: ScanningUpdated
10:34:56.775491 INF hci state -: ScanningUpdated
10:34:56.775620 INF hci state +: Scanning
10:34:56.777080 INF hci state -: Scanning
10:34:56.899511 INF hci state +: StopScanning
10:34:56.902393 INF hci state -: StopScanning
10:34:56.902439 INF hci state +: StopScanning
10:34:56.902466 INF hci state -: StopScanning
10:34:56.902501 INF hci state +: Dialing
10:34:56.903387 INF hci state -: Dialing

The program never connects or times out, it just sits there forever. I have tried using the BLE address instead of the name, but same problem.

The associated HCIDUMP log file is attached.

Thank you!
mini.txt

Goroutine leak on Device disconnect

Hi,
when connecting and disconnecting from the Example-Server there is one Goroutine leak per connection. It is caused by server.close() in linux/att/server.go.
It sends a false on the unbuffered server.chConfirm channel which is never read.

Proposed fix:
Close the channel instead of sending a false and check the channel status in indicate instead of the value on the channel.

diff --git a/linux/att/server.go b/linux/att/server.go
index 3d360eb..6ff454a 100644
--- a/linux/att/server.go
+++ b/linux/att/server.go
@@ -104,7 +104,7 @@ func (s *Server) indicate(h uint16, data []byte) (int, error) {
 		return n, err
 	}
 	select {
-	case ok := <-s.chConfirm:
+	case _, ok := <-s.chConfirm:
 		if !ok {
 			return 0, io.ErrClosedPipe
 		}
@@ -169,7 +169,7 @@ func (s *Server) Loop() {
 }
 
 func (s *Server) close() error {
-	s.chConfirm <- false
+	close(s.chConfirm)
 	return s.conn.Close()
 }

linux: C.H.I.P. cannot initialize device to scan

I am trying to use ble scanner with a C.H.I.P. $9 Linux computer. No luck scanning with ble, however am able to scan successfully with hcitool lescan.

chip@chip:~$ uname -a
Linux chip 4.4.13-ntc-mlc #1 SMP Thu Nov 3 01:28:54 UTC 2016 armv7l GNU/Linux
chip@chip:~$ dpkg -s bluez|grep Version
Version: 5.23-2+b1

Attached is the hcidump file. Thanks!

hcidump1-chip.txt

Project status?

Is this project actively being maintained? Who are the primary SMEs here?

The only other related BLE Go library/project is paypal/gatt which seems to be quite stalled/dead/inacitce -- paypal/gatt#88

ClientOptions and connParams

I cant quite work out if the code is complete to the point that i can make changes to the connection Paramters via ClientOptions, i'm looking to be able to change the slave latency after peripheral connection, but if its possible to just change it generally via device options rather than altering the defaults, that would be great, as i need to be able to set it on a per peripheral basis. Is this possible with current code base?

Edit: This is on linux, running as a central device

Not working on macOS High Sierra

Hi there,

I know that macOS High Sierra was released just few days ago, but just wanted to warn those of you who develop on Mac.
That's what I'm getting from the lib in console:

Unhandled event: xpc.Dict{"kCBMsgId":4, "kCBMsgArgs":xpc.Dict{"kCBMsgArgState":5}}

Number of connections to peripherals as a central

Is there a limit to the number of peripherals that can be connected at once using the library? It seems like the second call to Dial, it blocks forever but the peripherals are alive and can be connected to. I tested it with the shell and they all connect. When I use my own program it blocks on the second call to Dial after the first one is successfully connected,

Notifications disconnected after 60 seconds

Hi,

I did a peripheral program with a NRF52 working perfectly.
I did a central program receiving data from the NRF with "github.com/currantlabs/ble" as library
When i suscribe to a characteristic, the program seems to stop itself (disconnecting) after 60 seconds every time.

First i thought it was my code, but i tested with an example of "github.com/getsenic/gatt-python", and it works perfectly indefinitely
So, my question is : how is it possible to receive more than 60 seconds of data ?

I join you an of the program running (on the central program, being run on a Raspberry Pi 3).

kevin@kevin-rpi3:~ $ hcidump -t -x
HCI sniffer - Bluetooth packet analyzer ver 5.23
device: hci0 snap_len: 1500 filter: 0xffffffff
2017-11-06 18:46:51.133945 > HCI Event: Command Complete (0x0e) plen 12
Read Local Supported Features (0x04|0x0003) ncmd 1
status 0x00
Features: 0xbf 0xfe 0xcf 0xfe 0xdb 0xff 0x7b 0x87
2017-11-06 18:46:51.134741 > HCI Event: Command Complete (0x0e) plen 12
Read Local Version Information (0x04|0x0001) ncmd 1
status 0x00
HCI Version: 4.1 (0x7) HCI Revision: 0x145
LMP Version: 4.1 (0x7) LMP Subversion: 0x2209
Manufacturer: Broadcom Corporation (15)
2017-11-06 18:46:51.135180 > HCI Event: Command Complete (0x0e) plen 10
Read BD ADDR (0x04|0x0009) ncmd 1
status 0x00 bdaddr B8:27:EB:D5:E8:94
2017-11-06 18:46:51.135688 > HCI Event: Command Complete (0x0e) plen 11
Read Buffer Size (0x04|0x0005) ncmd 1
status 0x00
ACL MTU 1021:8 SCO MTU 64:1
2017-11-06 18:46:51.136105 > HCI Event: Command Complete (0x0e) plen 7
Read Class of Device (0x03|0x0023) ncmd 1
status 0x00 class 0x000000
2017-11-06 18:46:51.139176 > HCI Event: Command Complete (0x0e) plen 252
Read Local Name (0x03|0x0014) ncmd 1
status 0x00 name 'BlueZ 5.47'
2017-11-06 18:46:51.139562 > HCI Event: Command Complete (0x0e) plen 6
Read Voice Setting (0x03|0x0025) ncmd 1
status 0x00 voice setting 0x0060
2017-11-06 18:46:51.139929 > HCI Event: Command Complete (0x0e) plen 5
Read Number of Supported IAC (0x03|0x0038) ncmd 1
00 04
2017-11-06 18:46:51.140338 > HCI Event: Command Complete (0x0e) plen 8
Read Current IAC LAP (0x03|0x0039) ncmd 1
IAC 0x9e8b33 (General Inquiry Access Code)
2017-11-06 18:46:51.140718 > HCI Event: Command Complete (0x0e) plen 4
Set Event Filter (0x03|0x0005) ncmd 1
status 0x00
2017-11-06 18:46:51.141119 > HCI Event: Command Complete (0x0e) plen 4
Write Connection Accept Timeout (0x03|0x0016) ncmd 1
status 0x00
2017-11-06 18:46:51.141514 > HCI Event: Command Complete (0x0e) plen 7
LE Read Buffer Size (0x08|0x0002) ncmd 1
status 0x00 pktlen 0x00fb maxpkt 0x08
2017-11-06 18:46:51.141968 > HCI Event: Command Complete (0x0e) plen 12
LE Read Local Supported Features (0x08|0x0003) ncmd 1
status 0x00 features 0x1f00000000000000 (Link Layer supports LE Encryption)
2017-11-06 18:46:51.142442 > HCI Event: Command Complete (0x0e) plen 12
LE Read Supported States (0x08|0x001c) ncmd 1
00 FF FF FF FF FF 03 00 00
2017-11-06 18:46:51.143505 > HCI Event: Command Complete (0x0e) plen 68
Read Local Supported Commands (0x04|0x0002) ncmd 1
status 0x00
Commands: ffffff03ccffefffffffec1ff20fe8fe3ff78fff1c00040061f7ffff7ff8ffff
ff3f
2017-11-06 18:46:51.248855 > HCI Event: Command Complete (0x0e) plen 4
Write Simple Pairing Mode (0x03|0x0056) ncmd 1
status 0x00
2017-11-06 18:46:51.249297 > HCI Event: Command Complete (0x0e) plen 4
Write Inquiry Mode (0x03|0x0045) ncmd 1
status 0x00
2017-11-06 18:46:51.249637 > HCI Event: Command Complete (0x0e) plen 5
Read Inquiry Response Transmit Power Level (0x03|0x0058) ncmd 1
status 0x00 level 0
2017-11-06 18:46:51.250110 > HCI Event: Command Complete (0x0e) plen 14
Read Local Extended Features (0x04|0x0004) ncmd 1
status 0x00 page 1 max 2
Features: 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00
2017-11-06 18:46:51.250573 > HCI Event: Command Complete (0x0e) plen 4
Set Event Mask (0x03|0x0001) ncmd 1
status 0x00
2017-11-06 18:46:51.251097 > HCI Event: Command Complete (0x0e) plen 8
Read Stored Link Key (0x03|0x000d) ncmd 1
status 0x00 max 1 num 0
2017-11-06 18:46:51.251468 > HCI Event: Command Complete (0x0e) plen 4
Write Default Link Policy Settings (0x02|0x000f) ncmd 1
status 0x00
2017-11-06 18:46:51.251907 > HCI Event: Command Complete (0x0e) plen 8
Read Page Scan Activity (0x03|0x001b) ncmd 1
status 0x00 interval 2048 window 18
2017-11-06 18:46:51.252280 > HCI Event: Command Complete (0x0e) plen 5
Read Page Scan Type (0x03|0x0046) ncmd 1
00 00
2017-11-06 18:46:51.252738 > HCI Event: Command Complete (0x0e) plen 4
LE Set Event Mask (0x08|0x0001) ncmd 1
status 0x00
2017-11-06 18:46:51.253090 > HCI Event: Command Complete (0x0e) plen 5
LE Read Advertising Channel Tx Power (0x08|0x0007) ncmd 1
status 0x00 level 0xc (dBm)
2017-11-06 18:46:51.253432 > HCI Event: Command Complete (0x0e) plen 5
LE Read White List Size (0x08|0x000f) ncmd 1
00 80
2017-11-06 18:46:51.253896 > HCI Event: Command Complete (0x0e) plen 4
LE Clear White List (0x08|0x0010) ncmd 1
status 0x00
2017-11-06 18:46:51.254327 > HCI Event: Command Complete (0x0e) plen 4
Write LE Host Supported (0x03|0x006d) ncmd 1
00
2017-11-06 18:46:51.254852 > HCI Event: Command Complete (0x0e) plen 14
Read Local Extended Features (0x04|0x0004) ncmd 1
status 0x00 page 2 max 2
Features: 0x13 0x03 0x00 0x00 0x00 0x00 0x00 0x00
2017-11-06 18:46:51.255346 > HCI Event: Command Complete (0x0e) plen 6
Delete Stored Link Key (0x03|0x0012) ncmd 1
status 0x00 deleted 0
2017-11-06 18:46:51.255807 > HCI Event: Command Complete (0x0e) plen 4
Set Event Mask Page 2 (0x03|0x0063) ncmd 1
status 0x00
2017-11-06 18:46:51.256291 > HCI Event: Command Complete (0x0e) plen 12
Unknown (0x04|0x000b) ncmd 1
00 06 00 01 02 03 04 05 00
2017-11-06 18:46:51.256820 > HCI Event: Command Complete (0x0e) plen 15
Unknown (0x05|0x000c) ncmd 1
00 01 02 01 C0 C6 2D 00 C0 C6 2D 00
2017-11-06 18:46:51.257198 > HCI Event: Command Complete (0x0e) plen 4
Unknown (0x03|0x007a) ncmd 1
00
2017-11-06 18:46:51.258035 > HCI Event: Command Complete (0x0e) plen 4
LE Set Advertising Data (0x08|0x0008) ncmd 1
status 0x00
2017-11-06 18:46:51.258814 > HCI Event: Command Complete (0x0e) plen 4
LE Set Scan Response Data (0x08|0x0009) ncmd 1
status 0x00
2017-11-06 18:46:51.261924 > HCI Event: Command Complete (0x0e) plen 4
Write Local Name (0x03|0x0013) ncmd 1
status 0x00
2017-11-06 18:46:51.265021 > HCI Event: Command Complete (0x0e) plen 4
Write Extended Inquiry Response (0x03|0x0052) ncmd 1
status 0x00
2017-11-06 18:46:51.267827 > HCI Event: Command Complete (0x0e) plen 4
Reset (0x03|0x0003) ncmd 1
status 0x00
2017-11-06 18:46:51.271276 > HCI Event: Command Complete (0x0e) plen 4
Reset (0x03|0x0003) ncmd 1
status 0x00
2017-11-06 18:46:51.272224 > HCI Event: Command Complete (0x0e) plen 4
Set Event Mask (0x03|0x0001) ncmd 1
status 0x00
2017-11-06 18:46:51.273086 > HCI Event: Command Complete (0x0e) plen 4
LE Set Event Mask (0x08|0x0001) ncmd 1
status 0x00
2017-11-06 18:46:51.377079 > HCI Event: Command Complete (0x0e) plen 4
Write Simple Pairing Mode (0x03|0x0056) ncmd 1
status 0x00
2017-11-06 18:46:51.377736 > HCI Event: Command Complete (0x0e) plen 4
Write LE Host Supported (0x03|0x006d) ncmd 1
00
2017-11-06 18:46:51.378388 > HCI Event: Command Complete (0x0e) plen 4
Write Inquiry Mode (0x03|0x0045) ncmd 1
status 0x00
2017-11-06 18:46:51.378895 > HCI Event: Command Complete (0x0e) plen 4
Write Page Scan Type (0x03|0x0047) ncmd 1
00
2017-11-06 18:46:51.379481 > HCI Event: Command Complete (0x0e) plen 4
Write Inquiry Scan Type (0x03|0x0043) ncmd 1
status 0x00
2017-11-06 18:46:51.380021 > HCI Event: Command Complete (0x0e) plen 4
Write Class of Device (0x03|0x0024) ncmd 1
status 0x00
2017-11-06 18:46:51.380644 > HCI Event: Command Complete (0x0e) plen 4
Write Page Timeout (0x03|0x0018) ncmd 1
status 0x00
2017-11-06 18:46:51.381243 > HCI Event: Command Complete (0x0e) plen 4
Write Default Link Policy Settings (0x02|0x000f) ncmd 1
status 0x00
2017-11-06 18:46:51.381946 > HCI Event: Command Complete (0x0e) plen 4
Host Buffer Size (0x03|0x0033) ncmd 1
status 0x00
2017-11-06 18:46:51.382575 > HCI Event: Command Complete (0x0e) plen 4
LE Set Scan Parameters (0x08|0x000b) ncmd 1
status 0x00
2017-11-06 18:46:51.383478 > HCI Event: Command Complete (0x0e) plen 4
LE Set Scan Enable (0x08|0x000c) ncmd 1
status 0x00
2017-11-06 18:46:52.470542 > HCI Event: Command Complete (0x0e) plen 4
LE Set Scan Enable (0x08|0x000c) ncmd 1
status 0x00
2017-11-06 18:46:52.471602 > HCI Event: Command Status (0x0f) plen 4
LE Create Connection (0x08|0x000d) status 0x00 ncmd 1
2017-11-06 18:46:52.628253 > HCI Event: Command Complete (0x0e) plen 4
LE Set Advertise Enable (0x08|0x000a) ncmd 1
status 0x00
2017-11-06 18:47:52.669468 > HCI Event: Disconn Complete (0x05) plen 4
status 0x00 handle 64 reason 0x13
Reason: Remote User Terminated Connection
2017-11-06 18:47:52.670744 > HCI Event: Command Complete (0x0e) plen 4
LE Set Advertise Enable (0x08|0x000a) ncmd 1
status 0x0c
Error: Command Disallowed
2017-11-06 18:48:54.164165 > HCI Event: Command Complete (0x0e) plen 4
Reset (0x03|0x0003) ncmd 1
status 0x00
^C
kevin@kevin-rpi3:~ $

I'm hoping on having news about this thread soon :)

is this repo is still live

do we still have support on this repo ?
I'm looking to add a SMP support for simple pairing with noinputkey
did someone manage to add such feature ?

SEGV on read

Not sure if I'm doing something wrong but I tried to connect to a Puck.js Espruino device and read and ran into:

blesh > read -a 6e400001b5a3f393e0a9e50e24dcca9e
Dialing to specified address: 6e400001b5a3f393e0a9e50e24dcca9e
context deadline exceeded
blesh > panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x38 pc=0x41a81b9]

goroutine 46 [running]:
main.cmdConnect.func1(0x0, 0x0)
	/Users/prologic/go/src/github.com/currantlabs/ble/examples/blesh/main.go:261 +0x29
created by main.cmdConnect
	/Users/prologic/go/src/github.com/currantlabs/ble/examples/blesh/main.go:265 +0x29b

According to the docs here I think I'm at least half doing the right thing? Not sure if this is a bug?

can't accept: skt: unsupported event packet

Hello.
I can open connection to device successfully but when I close connection with Client.CancelConnection() method the connection is closed but package yields this log string: "2017/08/11 21:18:29 can't accept: skt: unsupported event packet: FF 07 82 66 90 80 30 2E 59"
After that, all future connection attempts with the device will fail with similar error: "2017/08/11 21:18:30 connection fail: can't dial: skt: unsupported event packet: FF 07 82 66 90 80 30 2E 59"

Thanks.

can't new device : can't init hci: no devices available: (hci0: can't down device: operation not permitted)

Dear,
I am trying to run example scanner / explorer, but dev.NewDevice(*device) is returning error 'can't new device : can't init hci: no devices available: (hci0: can't down device: operation not permitted)'
Bluetooth device is up. Please advise how to fix this issue.

sudo hciconfig hci0 status
hci0: Type: BR/EDR Bus: USB
BD Address: 40:B8:9A:3C:30:00 ACL MTU: 820:8 SCO MTU: 255:16
UP RUNNING PSCAN ISCAN
RX bytes:12989 acl:65 sco:0 events:605 errors:0
TX bytes:32909 acl:65 sco:0 commands:436 errors:0

Regards,

Cannot explore devices on Raspberry Pi

I'm trying to run the explorer program under Raspbian on a Raspberry Pi. When I attempt to connect to a device, this happens:

root@raspberrypi:/home/pi/bluetooth/examples/basic# go run explorer/main.go -addr EB:3F:D1:59:21:80
Scanning for 5s...
Discovering profile...
2017/01/20 23:51:51 can't discover profile: can't discover services: ATT request failed: input channel closed: io: read/write on closed pipe

I've tried to explore two different Bluetooth LE devices (Surface Mouse and a sensor module), with the same result.

Documentation?

Is there any documentation on how to use the api? I have tried running the examples, but am unsure how to get other devices to connect.

Can't dial error locks up device

Background:

I have written some code which connects to multiple BLE devices and subscribes to a handful characteristics. Should the connection break or fail at any time, the code periodically checks to see if that client has been disconnected and attempts to reconnect.

The Problem:

When connecting using the snippet below, the device occasionally locks up after the ble.Connect command. The context does not return no matter what. My delay is a 15 second duration.

What's important to mention here is that the lock only happens when I receive a "can't dial" error. That's usually the sign of death and it never returns after its next attempt.

It also seems to happen with more devices. With 3 devices it happens sparingly and with 6 devices it happens much more often.

  // Filter based on address
  filter := func(a ble.Advertisement) bool {
    return strings.ToUpper(a.Address().String()) == m.address
  }

  // Scan for specified durantion, or until interrupted by user.
  log.Infof("[ %s ] Connecting...", m.address)
  ctx := ble.WithSigHandler(context.WithTimeout(context.Background(), *sd))
  cln, err := ble.Connect(ctx, filter)

  //If an error ignore, otherwise set up.
  if err != nil && cln == nil {
    log.Errorf("[ %s ] Cannot connect : %s", m.address, err)
    return err
  } else if err != nil && cln != nil {
    log.Errorf("[ %s ] Weird connect : %s", m.address, err)
    return err
  } else {
    log.Infof("[ %s ] Connected", m.address)

Expected Behavior:

I expect the device to cleanly connect or disconnect and proceed to the next chunk of code. (or return and retry depending on what happens)

Observed Behavior:

Here's a log right before the lockup. Pay attention to where it says Connecting...

time="2018-01-18T04:22:34Z" level=info msg="[ C0:F2:1E:9F:B5:C9 ] Connecting..."
time="2018-01-18T04:22:37Z" level=info msg="[ C0:F2:1E:9F:B5:C9 ] Connected"
time="2018-01-18T04:22:37Z" level=error msg="[ C0:F2:1E:9F:B5:C9 ] can't discover profile: can't discover services: ATT request failed: input channel closed: io: read/write on closed pipe\n"
time="2018-01-18T04:22:37Z" level=info msg="[ C0:F2:1E:9F:B5:C9 ] is disconnected"
time="2018-01-18T04:22:49Z" level=info msg="[ C0:F2:1E:9F:B5:C9 ] Connecting..."
time="2018-01-18T04:22:53Z" level=info msg="[ C0:F2:1E:9F:B5:C9 ] Connected"
time="2018-01-18T04:22:54Z" level=error msg="[ C0:F2:1E:9F:B5:C9 ] can't discover profile: can't discover services: ATT request failed: input channel closed: io: read/write on closed pipe\n"
time="2018-01-18T04:22:54Z" level=info msg="[ C0:F2:1E:9F:B5:C9 ] is disconnected"
time="2018-01-18T04:23:03Z" level=info msg="[ E9:A0:4D:07:38:2B ] Update success"
time="2018-01-18T04:23:04Z" level=info msg="[ C0:F2:1E:9F:B5:C9 ] Connecting..."
time="2018-01-18T04:23:07Z" level=info msg="[ E9:A0:4D:07:38:2B ] { 1516249387 } Batt:     92% - Raw: (92)"
time="2018-01-18T04:23:12Z" level=info msg="[ E9:A0:4D:07:38:2B ] { 1516249392 } Batt:     91% - Raw: (91)"
time="2018-01-18T04:23:19Z" level=error msg="[ C0:F2:1E:9F:B5:C9 ] Cannot connect : can't dial: can't dial: context deadline exceeded"
time="2018-01-18T04:23:19Z" level=info msg="[ C0:F2:1E:9F:B5:C9 ] Connecting..."

It does not return after the last line. Other go routines though continue to run in the background in the same program.

Note: can't discover profile: can't discover services: ATT request failed: input channel closed: io: read/write on closed pipe Doesn't always happen every time. Sometimes, I'll go to connect, get the can't dial error and then it fails right there.

fatal error: concurrent map writes / ble.ReadCharacteristic() gets stuck

I'm getting the following error when calling ble.Connect():

2017/07/25 16:13:59 Unhandled event: xpc.Dict{"kCBMsgId":54, "kCBMsgArgs":xpc.Dict{"kCBMsgArgServiceStartHandle":10, "kCBMsgArgDeviceUUID":xpc.UUID{0x26, 0x80, 0x8d, 0x10, 0xb, 0xa8, 0x46, 0xfb, 0xbb, 0x58, 0xa2, 0x7e, 0xe1, 0x90, 0xc, 0x7c}, "kCBMsgArgServiceEndHandle":65535}}
fatal error: concurrent map writes

goroutine 17 [running, locked to thread]:
runtime.throw(0x44aebec, 0x15)
	/usr/local/Cellar/go/1.8.1/libexec/src/runtime/panic.go:596 +0x95 fp=0xc42004da28 sp=0xc42004da08
runtime.mapassign(0x4422340, 0xc42015e0f0, 0xc42004db88, 0xc4201fb600)
	/usr/local/Cellar/go/1.8.1/libexec/src/runtime/hashmap.go:499 +0x667 fp=0xc42004dac8 sp=0xc42004da28
github.com/currantlabs/ble/darwin.(*Device).conn(0xc42008c500, 0xc4201f0c00, 0x44a7755)
	/Users/matti/go/src/github.com/currantlabs/ble/darwin/device.go:500 +0x414 fp=0xc42004dbc0 sp=0xc42004dac8
github.com/currantlabs/ble/darwin.(*Device).HandleXpcEvent(0xc42008c500, 0xc4201f0bd0, 0x0, 0x0)
	/Users/matti/go/src/github.com/currantlabs/ble/darwin/device.go:448 +0x190f fp=0xc42004de20 sp=0xc42004dbc0
github.com/raff/goble/xpc.handleXpcEvent(0x4a00ac0, 0xc420051de8)
	/Users/matti/go/src/github.com/raff/goble/xpc/xpc.go:229 +0x242 fp=0xc42004de90 sp=0xc42004de20
github.com/raff/goble/xpc._cgoexpwrap_f507673fb4e8_handleXpcEvent(0x4a00ac0, 0xc420051de8)
	github.com/raff/goble/xpc/_obj/_cgo_gotypes.go:460 +0x35 fp=0xc42004deb0 sp=0xc42004de90
runtime.call32(0x0, 0x7000050d0248, 0x7000050d02e8, 0x10)
	/usr/local/Cellar/go/1.8.1/libexec/src/runtime/asm_amd64.s:514 +0x48 fp=0xc42004dee0 sp=0xc42004deb0
runtime.cgocallbackg1(0x0)
	/usr/local/Cellar/go/1.8.1/libexec/src/runtime/cgocall.go:301 +0x19d fp=0xc42004df58 sp=0xc42004dee0
runtime.cgocallbackg(0x0)
	/usr/local/Cellar/go/1.8.1/libexec/src/runtime/cgocall.go:184 +0x84 fp=0xc42004dfc0 sp=0xc42004df58
runtime.cgocallback_gofunc(0x0, 0x0, 0x0, 0x0)
	/usr/local/Cellar/go/1.8.1/libexec/src/runtime/asm_amd64.s:767 +0x74 fp=0xc42004dfe0 sp=0xc42004dfc0
runtime.goexit()
	/usr/local/Cellar/go/1.8.1/libexec/src/runtime/asm_amd64.s:2197 +0x1 fp=0xc42004dfe8 sp=0xc42004dfe0

This could be just me misusing the library (or Golang, for I am quite a beginner with the language still), but with next to no documentation for the lib I am not sure..

So I am doing the Connect() call from within the AdvHandler func of my Scan() call. I have tried using the same exact context.Context as well as a fresh new one (allocated new one per each Connect() call) but neither way seems to work. Sometimes it crashes like this, sometimes Connect() succeeds but then the whole program gets stuck on ble.ReadCharacteristic() call I am making, following the Connect() (and DiscoverProfile() etc).

I am running this on MacBook Pro PC, OSX Sierra 10.12.6, go version go1.8.1 darwin/amd64

The device I am trying to Connect() to is an iPhone6 with the latest iOS (10.3.2)

  • Matti

Implement read from handle

Sometimes you would like to be able to directly read from a handle instead of going via Service / Characteristics. Would it be possible to support this use case?

Hangs

Hi there,

I have noticed, that ble periodically hangs and stops sending information from a device (I run it with allowDup=true). I.e. it sends adv for some period (e.g. 20 seconds) and then stops.

The time when it hangs not constant. It may hangs in 30 seconds or in 1-2 minutes. Or later. But in average it's 5 minutes.

System
Fedora 25 Kernel 4.9.12
go version go1.7.5 linux/amd64

Here is a code
https://github.com/blent/beagle/blob/master/src/core/discovery/devices/device-ble.go#L58

Channel is buffered and its buffer size is 500. Most of peripherals get filtered by if statement. So, it's not the case of full channel.

fatal error: concurrent map read and map write

Running a GATT server, and after many (two hundred plus) service reads, the program dies with:
fatal error: concurrent map read and map write

It seems to be coming from somewhere deep in the 'server.go' module, but I don't know if I'm interpreting the dump correctly.

Very repeatable - I've never made it to 300 service reads. Seems to happen with equal frequency using golang 1.6 or 1.8

Where to start debugging?

Missing license file

Right now this looks like it has no license file. What do you plan on licensing this and the x.io.bt code under?

Specify different HCI device

My laptop has two Bluetooth devices - an older built-in one that doesn't support BLE, and a newer USB one that does. They tend to initialize in whatever order the laptop feels like, so sometimes the BLE one is hci0, other times hci1.

Does this library have any way to let me pick which device it's using? In all the tests I've run, it does not, and if I look at what the examples use, they just import https://github.com/currantlabs/ble/blob/master/examples/lib/dev/dev.go which completely ignores the string argument.

Possible goroutine leak

In gatt.go/Connect, once Scan has been called, it looks as though incoming adverts will create goroutines that eventually call fn to pass the advert data to Dial via ch. If multiple adverts arrive quickly, Dial will process the first, but the remaining adverts will block in fn on the send to ch.
Similarly, if Scan terminates for any reason other than a cancel, then we don't reach Dial and an incoming advert could block when trying to send to ch.
These blocked sends could leak goroutines, so Connect should probably close ch before the two return paths exit, and fn could defer a call to recover, in order to handle any panics when a is sent to a ch that's been closed.

osx: Error when exploring characteristic

When testing on the latest OS X El Capitan using a LightBlue Bean device, I received the following error:

rons-MacBook-Air:examples ron$ ./bin/explorer --name="Bean"
Exploring Peripheral [ D7DE53F5A9824C3D80449C28A9543BE8 ] ...
Service: F000FFC004514000B000000000000000 
  Characteristic: F000FFC104514000B000000000000000, Property: 0x1C, 
    Descriptor: 2902, Client Characteristic Configuration
    Value         0000 | "\x00\x00"
    Descriptor: 2901, Characteristic User Description
panic: interface conversion: interface is string, not []uint8

goroutine 1 [running]:
panic(0x40de960, 0xc4200b8240)
    /Users/ron/.gvm/gos/go1.7beta2/src/runtime/panic.go:500 +0x1a1
github.com/currantlabs/ble/darwin.(*Client).ReadDescriptor(0xc4200c0000, 0xc4200ae780, 0xc420051da0, 0x2, 0x2, 0x36, 0x0)
    /Users/ron/.gvm/pkgsets/go1.7beta2/global/src/github.com/currantlabs/ble/darwin/client.go:165 +0x383
main.explorer(0x4170600, 0xc4200c0000, 0x4170600, 0xc4200c0000)
    /Users/ron/Development/ble/examples/explorer/main.go:69 +0x6c6
main.main()
    /Users/ron/Development/ble/examples/explorer/main.go:158 +0x27d

It appears that the type being returned by ReadDescriptor is not the same as the one that is expected.

linux: Intel Edison with Yocto cannot initialize device

When trying to run the latest ble on an Intel Edison running the latest Yocto, the ble scanner fails when trying to connect. The reason for this is that the Yocto's bluetooth does not support HCI_CHANNEL_USER

root@howtocode:~# ./scanner 
2017/01/15 13:56:00 can't new device : can't init hci: no devices available: (hci0: can't bind socket to hci user channel: invalid argument)

I had already reported this, but it was mixed in with another issue. Here is a clean report.

Device health check

Hey guys,

is it possible to implement some kind of health check for an underlying device?
BLE is not very stable on Linux, so it may make sense to check whether it's fine and working.

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.