8

I am currently attempting the Raspberry Pi iBeacon tutorial posted by RadiusNetworks at

http://developer.radiusnetworks.com/2013/10/09/how-to-make-an-ibeacon-out-of-a-raspberry-pi.html

but I am having issues with the connection timing out after a few seconds. I have performed a fresh build of raspbian, and have tried with 2 different dongles (AZIO V400 and IOGEAR GBU521), and I have tried with Bluez 5.8 per the tutorial as well as Bluez 5.11, both on fresh Raspbian loads.

When I call the start script I see:

pi@piBlueTest ~ $ ./start
Launching virtual iBeacon...
LE set advertise enable on hci0 returned status 12
< HCI Command: ogf 0x08, ocf 0x0008, plen 44
  1E 02 01 1A 1A FF 4C 00 02 15 E2 C5 6D B5 DF FB 48 D2 B0 60 
  D0 F5 A7 10 96 E0 00 00 00 00 C9 00 00 00 00 00 00 00 00 00 
  00 00 00 00 
> HCI Event: 0x0e plen 4
  01 08 20 00 
Complete

This triggers an "Entered" event on the iPhone using the "Locate iBeacon" app, and shows a distance in meters for a few seconds. It then shows "Distance: unknown" as the range for several more seconds, followed by an "exit" event occurring. When I run the sequence with "hcidump" running, I get

HCI sniffer - Bluetooth packet analyzer ver 5.11
device: hci0 snap_len: 1500 filter: 0xffffffff
< HCI Command: LE Set Advertise Enable (0x08|0x000a) plen 1
> HCI Event: Command Complete (0x0e) plen 4
    LE Set Advertise Enable (0x08|0x000a) ncmd 1
    status 0x0c
    Error: Command Disallowed
< HCI Command: LE Set Advertising Data (0x08|0x0008) plen 44
> HCI Event: Command Complete (0x0e) plen 4
    LE Set Advertising Data (0x08|0x0008) ncmd 1
    status 0x00
< HCI Command: LE Set Advertising Parameters (0x08|0x0006) plen 15
    min 1280.000ms, max 1280.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 Advertise Enable (0x08|0x000a) plen 1
> HCI Event: Command Complete (0x0e) plen 4
    LE Set Advertise Enable (0x08|0x000a) ncmd 1
    status 0x00
> HCI Event: LE Meta Event (0x3e) plen 19
    LE Connection Complete
      status 0x00 handle 64, role slave
      bdaddr B8:F6:B1:1C:15:C8 (Public)
> ACL data: handle 64 flags 0x02 dlen 11
    ATT: Read By Type req (0x08)
      start 0x0001, end 0xffff
      type-uuid 0x2a00
> HCI Event: Disconn Complete (0x05) plen 4
    status 0x00 handle 64 reason 0x13
    Reason: Remote User Terminated Connection

It appears that the iPhone is trying to initiate a connection to the pi, and then fails at negotiating that connection which then ends the advertisement.

I have completed the steps from the tutorial to the letter, and cannot seem to determine what is causing the disconnect. I have tried changing bluez versions, and tried different hardware, but to no avail. Any ideas what step I may be missing? I have searched everything I can think of for clues, but have not found the answer yet. Thanks in advance for any advice!

Chris Sparrow
  • 83
  • 1
  • 1
  • 4
  • Chris, after this happens, if you restart LE advertising on the Pi, does iBeacon Locate start tracking it again? – davidgyoung Nov 28 '13 at 05:50
  • Hi David, thank you for the reply. Yes, I can keep restarting, and it will keep the same pattern, as soon as I restart, it will trigger an "Enter" event, reporting distance for a few seconds, then unknown for several more, then in hcidump I will see the disconnect, followed by the "Exit" event. – Chris Sparrow Nov 28 '13 at 12:48
  • Hmmm. I have never seen this behavior. I wonder if it is an issue with your BLE dongle, a difference in the way you have bluez configured, or a combination of both. – davidgyoung Nov 28 '13 at 12:57
  • It is certainly odd. Just to be certain, last night I again did a fresh build of 2013-09-25-wheezy-raspbian.zip, the only changes were to change locale settings, change the hostname, and run update and upgrade. I then followed the tutorial to the letter using the iogear dongle, and have the same exact result. – Chris Sparrow Nov 28 '13 at 13:31

3 Answers3

13

Try setting the device to "advertise and not-connectable" (3 instead of 0) instead of "advertise and connectable"

sudo hciconfig $BLUETOOTH_DEVICE leadv 3

We suddenly had a beacon going down after a few seconds due to a laptop trying to connect. Setting the device to not-connectable solved the problem.

  • Thanks Rayner! I made the recommended change and reinstalled the "Knock" app to check it out. The pi beacons now stay running solid with this tweak. I wasn't able to find anything that explained the various modes for leadv, so thanks for the tip. Working like a charm! Amazing how hard it is to find info on bluez and the like. – Chris Sparrow Dec 08 '13 at 16:27
  • Good find! We will update the Radius Networks howto and our pre-assembled iBeacon Dev Kits – davidgyoung Dec 08 '13 at 23:54
  • OK, the Radius Networks HOWTO is now updated to include this, as are all iBeacon Dev Kits that we ship pre-assembled. – davidgyoung Dec 13 '13 at 17:55
  • 1
    What if I get `LE set advertise enable on hci0 returned status 12` after running that command? – Nicola Ferraro Dec 28 '18 at 09:56
8

Looks like you have it solved but I'll go ahead and post for others that may have the same problem I did and find this thread.

Like Chris, I completed the steps from the tutorial with the exception of using bluez 5.11. After some experimentation I had to change the order of the steps in the "start" script. Not sure why but this seems to be the only order in which it will work correctly. Maybe I did something wrong?

#!/bin/sh
. ./ibeacon.conf
echo "Launching virtual iBeacon..."
sudo hciconfig $BLUETOOTH_DEVICE up
sudo hciconfig $BLUETOOTH_DEVICE noleadv
sudo hciconfig $BLUETOOTH_DEVICE leadv 0
sudo hcitool -i hci0 cmd 0x08 0x0008 1e 02 01 1a 1a ff 4c 00 02 15 $UUID $MAJOR $MINOR $POWER 00 00 00 00 00 00 00 00 00 00 00 00 00
echo "Complete"
bobscaggs
  • 81
  • 2
1

Perhaps you can stop this from happening by making whatever device is attempting a connection stop doing so. This is not normal for iOS. Did you tell it to attempt a connection? Are you sure it is the iOS device doing this? Perhaps it is your computer?

Alternately, if you cannot get it working yourself, I can provide a free .iso file with the exact code we put on the units we sell preassembled. This could eliminate a build problem. Please send a note through our sales contact if you want to try this.

davidgyoung
  • 63,876
  • 14
  • 121
  • 204
  • Thank you David, I will shut down the macs and see if that helps! I did not request a connection from any devices, so the connect/disconnect is certainly puzzling to me. If not, I may trouble you for that .iso if you don't mind. I really appreciate your help! – Chris Sparrow Nov 28 '13 at 13:34
  • That was it! I disabled bluetooth on my macbook, and now it will maintain the connection. Thanks so much for the guidance. Now, I just need to find a way to make the beacon more robust, so a connection attempt from another device will not kill it. – Chris Sparrow Nov 28 '13 at 14:44
  • As a followup to anyone else experiencing this, I see now it is the "Knock" application which I had running on my macbook which is driving the connection attempt and killing the ibeacon. Knock is an app that allows you to unlock your mac with 2 knocks on your iPhone, using BLE. When I have Knock running, it attempts to connect to the pi, and kills the beacon. If I close the knock app on the macbook, all is well. – Chris Sparrow Nov 28 '13 at 14:50
  • Interesting. Yours is the first report I have heard like this. I would like to make the Pi-based iBeacon robust enough to recover from this. We could probably do it with a process that restarts advertising if this happens, but I half suspect there is a way to simply tell Bluez to disallow connections and continue advertising. – davidgyoung Nov 28 '13 at 14:55