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?

user1153660
  • 413
  • 1
  • 5
  • 8
  • `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. – Chris Stratton Feb 12 '14 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. – user1153660 Feb 12 '14 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.. – Chris Stratton May 15 '14 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 ? – Jean-Philippe Encausse Sep 23 '14 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. – user1153660 Sep 24 '14 at 20:44

3 Answers3

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"
Community
  • 1
  • 1
jjnebeker
  • 1,238
  • 1
  • 9
  • 12
  • 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 '14 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. – Will Faithfull May 28 '14 at 14:10
  • @WillFaithfull Great, thanks. I will update the script to add this to the latest BDKs. – jjnebeker May 28 '14 at 16:33
  • @jjnebeker don't forget to print it too :) – Will Faithfull May 29 '14 at 09:11
  • how can I run this script in the development kit image? (#noobHere) – ncubica Jun 10 '14 at 02:35
  • 1
    If you've purchased our development kit, you can simply type `ibeacon scan` into the command line. – jjnebeker Jun 10 '14 at 18:21
  • I installed the image from you site, Have the raspberry and all the equipment, do I have to do the same? – ncubica Jun 11 '14 at 17:41
  • yes! is running, how can I have access to the script? where its store? thanks for you help man. – ncubica Jun 11 '14 at 17:59
  • the script is stored in the `/etc/ibeacon` directory – jjnebeker Jun 12 '14 at 14:08
  • I'm managed to make the script ibeacon_scan work changing values doesn't seem to translate into a proximity reading. I'm getting a fixed power value and what look like random RSSI values. Is there a way to detect a beacon approaching the RPi, say 1 meter? – German Nov 18 '14 at 07:37
  • Never mind. I get consistent results if I start and stop the capture between measurements, for continuosly running capture it just doesn't give coherent results – German Nov 19 '14 at 07:01
  • While using --duplicates, I get a huge dump: in just a couple of minutes, I get 800 reads that your script then attempts to print on screen. Is there a way to control the scan such that lescan scans only once every 5 seconds or so, instead of continuously scanning? – Ninja Jan 22 '15 at 17:43
  • There isn't a built in way to control scan duration in the `lescan` command but you could create a wrapper script that starts and stops a new scan every 5 seconds. – jjnebeker Jan 26 '15 at 20:07
  • @jjnebeker 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, the 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 '15 at 00:58
  • @Shawn You're right, with a high volume of advertisements the parsing shell script will struggle to keep up and will keep spitting out packets long after the advertisements have stopped coming in. One solution would be to throttle the number of incoming packets by repeatedly starting and stopping the background `hcitool lescan` process. You could also see significant performance improvements from reworking the script in a language other than shell script (e.g., ruby, python). – jjnebeker May 18 '15 at 21:47
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.

Community
  • 1
  • 1
davidgyoung
  • 63,876
  • 14
  • 121
  • 204
  • Will this script work with Estimote or Gimbal beacons? – user2005121 Jul 11 '14 at 14:40
  • Gimbal beacons must be put in iBeacon mode for it to work. Estumotes are by default in such a mode. – davidgyoung Jul 11 '14 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 '15 at 00: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.