paypal / gatt

Gatt is a Go package for building Bluetooth Low Energy peripherals
BSD 3-Clause "New" or "Revised" License
1.14k stars 285 forks source link

Hangs on Beaglebone Black/Arch Linux #2

Closed leoneu closed 10 years ago

leoneu commented 10 years ago

The gatt_server example hangs after calling srv.AdvertiseAndServe().

$ uname -a
Linux bbb_001 3.14.4-1-ARCH #1 SMP Sun May 18 18:32:31 MDT 2014 armv7l GNU/Linux

$ go version
go version go1.3 linux/arm

I can see the Peripheral name using LightBlue but not the characteristics. The sample server never prints an output to stdout, just hangs there.

I'm using the plugable USB dongle:

$ hciconfig
hci0:   Type: BR/EDR  Bus: USB
    BD Address: 00:02:72:C5:C1:80  ACL MTU: 1021:8  SCO MTU: 64:1
    UP RUNNING PSCAN 
    RX bytes:2701 acl:11 sco:0 events:151 errors:0
    TX bytes:1825 acl:14 sco:0 commands:105 errors:0
lsusb
Bus 002 Device 002: ID 0a5c:21e8 Broadcom Corp. BCM20702A0 Bluetooth 4.0
josharian commented 10 years ago

The gatt_server example hangs after calling srv.AdvertiseAndServe().

AdvertiseAndServe is intended to block, much like net/http's ListenAndServe. You can always go srv.AdvertiseAndServe instead. (Or put it inside a closure so that you can check the error message.)

I can see the Peripheral name using LightBlue but not the characteristics.

Hmmm. So to be clear, you see the peripheral broadcasting, but you can't connect to it? Or is it that you can connect to it, but you don't get back a listing of services?

If you're using LightBlue on your laptop, please try turning off wi-fi on your laptop and trying again. Or try LightBlue from a phone.

leoneu commented 10 years ago

I mean it never gets to output the log message: "Advertising service..." as I can see in your demo. It seems to be hanging before reaching that message. I can see the standard services advertised for the device on LightBlue such as 1800, 1801, etc. but not the service from the sample program. So the connection seems to be OK. The same happens on Intel/Linux.

Could be something related to the BLE device, I'll try to get a different one. If you have suggestions on how I can debug, let me know.

leoneu commented 10 years ago

The problem doesn't seem to be hardware related. I was able to connect using command line tools. Example in Stack Overflow.

josharian commented 10 years ago

Hmmm. A few more sanity checks:

leoneu commented 10 years ago

I now stopped the bluetooth service, no change.

> sudo hciconfig hci0 up

> hciconfig hci0                                                                                                                                                                                            
hci0:   Type: BR/EDR  Bus: USB
    BD Address: 00:02:72:C5:C1:80  ACL MTU: 1021:8  SCO MTU: 64:1
    UP RUNNING PSCAN 
    RX bytes:7333 acl:12 sco:0 events:520 errors:0
    TX bytes:9423 acl:11 sco:0 commands:504 errors:0

> /usr/local/bin/hci-ble 0
hciDeviceId 0
adapterState poweredOn
...
[hangs here]
josharian commented 10 years ago

Thanks for your patience with me as we sort this out.

I now stopped the bluetooth service, no change.

Bummer. The bluetooth service would definitely have caused the symptoms you see.

Are you willing to try gatt_server.go again one more time, just to sanity check? Note that many centrals aggressively cache a peripheral's services and characteristic, so you might need to power cycle your phone or clear your OS X Bluetooth cache in order for them to see the new services and characteristics. (See http://godoc.org/github.com/paypal/gatt. Yes, it is very frustrating.)

> /usr/local/bin/hci-ble 0
hciDeviceId 0
adapterState poweredOn
...
[hangs here]

Is the ... part of the output? Does it represent elided output? Or does it just represent "hang"?

leoneu commented 10 years ago

Good news! I replaced the Plugable BLE dongle with a CSR BLE dongle and now it works. In summary:

I will do more testing to see if I find anything else. Thanks!

josharian commented 10 years ago

Sweet. Thanks!

If you're game, I'd love a pull request starting a section on known (non-)functional BLE adapters. The one I use is http://www.amazon.com/gp/product/B007GFX0PY/ref=oh_details_o00_s00_i00?ie=UTF8&psc=1.

go.dbus looks promising. I'd love to not have to do all that awful c shim muck. If you look into it and/or get anything working, please keep me posted!