39

I bought a developer kit from Radius Networks that includes a ioGear GBU521 BLE 4.0 dongle and a Raspberry Pi. I also bought one of their RadBeacon iBeacons. They both work as advertised, but I was kind of surprised by what I got.

I had assumed that the RaspPi could detect iBeacons. Instead, the kit is setup to create an iBeacon. My use case is to detect when a forklift enters a particular room so I can send work to them. My thought was to put an iBeacon on the forklift then put a RaspPi searching for iBeacons. And when an iBeacon (forklift) was detected, you could conclude that it is nearby. I would wire the RaspPi into the LAN and have it communicate the information via REST or similar. I know I could put a suitable Android or Apple device and accomplish it that way, but I don't see why this dongle can't detect these iBeacons and tell me what their UUID's are? What am I missing?

5
  • sudo hcitool lescan will detect BLE advertisements including those in "iBeacon" format, but will only display the hardware address which may or may not be sufficient for your purpose. You may need to either also run hcidump or modify the source of hcitool in order to dump the advertising packet contents from which you could extract the iBeacon-style UUID, major, minor, and transmit power fields. A little reading of the docs and/or code should reveal how to find the received power level, to use with the transmit level for very crude distance estimate. Feb 12, 2014 at 16:59
  • This helped Chris. I am able to see the RadBeacon with the RaspPi when I sudo hcitool lescan. And it answers with a MAC address. Then in another SSH window, I sudo hcidump -a and was able to see some stats including RSSI. But I was not able to see the UUID, Major and Minor. sudo hcidump -a -w outfile and I can pick out the UUID, Major and Minor. I also see where the power data is, but have not decoded it yet. Feb 12, 2014 at 23:12
  • Note that while the raspberry-pi is mentioned in the title and tags, this question is basically generic to any Linux system using bluez to which privileged access is available.. May 15, 2014 at 14:52
  • Hi, I'm looking to do the same things. Since February do you have feedbacks ? Is there good/small device to use ? Articles about it ? Sep 23, 2014 at 16:05
  • We are exploring using the Intel Edison's built-in bluetooth, but they say 4th quarter on BLE. The Edison seems ideal since it has an integrated Bluetooth and Wifi on the SoC. It should be possible to build a truly small device that would compete with the Pi on price and beat it in terms of size and power. It is also designed for industrial devices. Sep 24, 2014 at 20:44

3 Answers 3

74

Yes! You can use your Raspberry Pi to scan for iBeacons. We've put together a script below that does this, you can also do it yourself with these steps:

  1. Start a background process that does a bluetooth LE scan:

    sudo hcitool lescan --duplicates &
    

    With the --duplicates setting the scan will not ignore multiple packets from the same iBeacon.

  2. Start an hcidump and pipe the raw output to a script that will filter for iBeacon packets:

    sudo hcidump --raw 
    

The filtering is the tricky part, the raw output from hcidump isn't formatted nicely and also shows packets that aren't iBeacon transmissions. To solve this, we made a filter script that reads in the output line by line and separates out the raw packets from the other output (i.e., MAC addresses, etc.). We've done a lot of research at Radius Networks on the iBeacon bluetooth profile, which we used to identify iBeacon packets and filter them out from packets from other devices.

We've put this all together into an ibeacon_scan script that does everything, including converting the raw identifiers into human-readable form. You can download it here. Soon, we'll include this in the iBeacon Development Kit to add scanning capability.

Here's an example of the output from the script:

$ ./ibeacon_scan
UUID: 74278BDA-B644-4520-8F0C-720EAF059935 MAJOR: 0 MINOR: 73 POWER: -50
UUID: 2F234454-CF6D-4A0F-ADF2-F4911BA9FFA6 MAJOR: 1 MINOR: 6 POWER: -59
UUID: E2C56DB5-DFFB-48D2-B060-D0F5A71096E0 MAJOR: 6 MINOR: 9 POWER: -55

We've also included a -b option for bare output that is easy to parse into other scripts, here's an example:

$ ./ibeacon_scan -b
2F234454-CF6D-4A0F-ADF2-F4911BA9FFA6 1 6 -59
E2C56DB5-DFFB-48D2-B060-D0F5A71096E0 6 9 -55
74278BDA-B644-4520-8F0C-720EAF059935 0 73 -50

You can use this option and pipe the script's output to your script to trigger actions when iBeacons with certain identifiers are detected.

EDIT: We've reworked this script to make it more responsive and robust and incorporated it into the latest version of the development kit. The update is available to download here.

EDIT2: As pointed out by @sai-ramachandran, you can augment this script to capture the RSSI of each iBeacon packet in addition to POWER. To do this, add the following lines to the script:

 RSSI=`echo $packet | sed 's/^.\{132\}\(.\{2\}\).*$/\1/'`
 RSSI=`echo "ibase=16; $RSSI" | bc`
 RSSI=$[RSSI - 256]

and be sure to add RSSI to the output:

 echo "UUID: $UUID MAJOR: $MAJOR MINOR: $MINOR POWER: $POWER RSSI: $RSSI"
15
  • 1
    To address an edit to this answer about RSSI vs. POWER, it appears to be correct that capturing from char position 132 in each packet is the way to read RSSI for each iBeacon packet. However, RSSI was not originally intended to be included in this answer. Instead, with POWER we intended to capture the tx calibration constant, which is a different field and is always the same value (per iBeacon). I will edit this answer to include capturing RSSI in addition to calibrated power once I confirm this is correct.
    – jjnebeker
    May 27, 2014 at 19:00
  • Thanks for this script @jjnebeker. I notice in the latest BDK it has become a ruby script. I added the following line to grab rssi: rssi = packet.gsub(/^.{132}(.{2}).*$/, '\1').to_i(16) - 256 and it appears to work. May 28, 2014 at 14:10
  • @WillFaithfull Great, thanks. I will update the script to add this to the latest BDKs.
    – jjnebeker
    May 28, 2014 at 16:33
  • @jjnebeker don't forget to print it too :) May 29, 2014 at 9:11
  • 1
    If you've purchased our development kit, you can simply type ibeacon scan into the command line.
    – jjnebeker
    Jun 10, 2014 at 18:21
3

You are correct that the iBeacon Development Kit is not designed to detect iBeacons -- it is designed to transmit as an iBeacon.

That said, it is possible to detect iBeacons with a Raspberry Pi using a variation of what @ChrisStratton suggests in his comment. See the answer from my colleague @jjnebeker who has made a script to do want you want.

3
  • Will this script work with Estimote or Gimbal beacons? Jul 11, 2014 at 14:40
  • Gimbal beacons must be put in iBeacon mode for it to work. Estumotes are by default in such a mode. Jul 11, 2014 at 19:21
  • @davidgyoung I experienced the same issue that huge Android 5 advertisement data send from my MOTE G2 phone (and I don't think I can control the frequency too much in Phone side), this caused even I turned off advertise, this script in RPi still seeing the phantom data, I believe the script buffered the massive old historical data and trying to process them one by one. Typically need wait several minutes, then it's gone, do you have any idea how to fix this?
    – Shawn
    May 15, 2015 at 0:59
-1

https://github.com/RadiusNetworks/android-ibeacon-service

Use this to detect iBeacons.

It allows Android devices to use iBeacons much like iOS devices do. An app can request to get notifications when one or more iBeacons appear or disappear. An app can also request to get a ranging update from one or more iBeacons at a frequency of 1Hz.

1
  • 2
    I want to use the RaspPi to detect, not the Android. Feb 13, 2014 at 12:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.