element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      • Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Vietnam
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Pi IoT
  • Challenges & Projects
  • Design Challenges
  • Pi IoT
  • More
  • Cancel
Pi IoT
Blog [PiIoT#03]: Cheap BLE Beacons with nRF24L01+
  • Blog
  • Forum
  • Documents
  • Polls
  • Files
  • Events
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: vish
  • Date Created: 10 Jul 2016 6:39 AM Date Created
  • Views 3922 views
  • Likes 5 likes
  • Comments 8 comments
  • ble
  • nrf24l01+
  • arduino nano
  • raspberry pi 3 projects
  • vish_piiot
  • piiot
  • raspberry pi projects
  • piiot challenge
  • raspberry pi 3
  • arduino
  • beacons
Related
Recommended

[PiIoT#03]: Cheap BLE Beacons with nRF24L01+

vish
vish
10 Jul 2016

This blog post introduces how to create cheap bluetooth beacons with nRF24L01+ wireless modules. nRF24L01+ is a 2.4GHz wireless module from Nordic semiconductors and happens to share a very similar protocol as BLE packets. This similarity in packets along with some tinkering in code can enable these modules to act as a ble beacon advertising a valid packet. This hack is first published at "Bit-Banging" Bluetooth Low Energy - Dmitry Grinberg and from then there has been various ports to make this work on a variety of platforms. But there exists some compromises in packet length and data that can be transmitted. More technical details can be found at Lijun // Using nRF24L01+ as A Bluetooth Low Energy Broadcaster/Beacon. Most exciting thing is these modules are available for a little more than $1 at many outlets making this one of the cheapest way to fake BLE beacons.

 

In this post I uses an arduino with nRF24 and uses a library I wrote some time ago to fake BLE advertisement packets. I intend to use these in later stage of the project as bluetooth tags attached to objects and BLE presence detection.

 

Hardware Setup

Hardware setup is fairly string forward. You just have to connect nRF modules as the the way you uses it normally with arduino.

Pin connections are given below:

 

nRF24L01+
Arduino (nano)
VCC3.3V
GNDGND
CSND10
CED09
MISOD12
MOSID11
SCKD13
IRQn/a

 

 

My setup looks like this:

image

 

Downloading library

I have written a small library to make the procedure easy. You can get it from : https://github.com/v-i-s-h/RF24Beacon

To install the library, go to /<your_arduino_sketch_folder>/libraries and issue:

git clone https://github.com/v-i-s-h/RF24Beacon.git

 

 

Programming arduino

I have given an example along with the library. Once you successfully install the library, you will be able to go to File > Examples > RF24Beacon > beacon in your arduino ide to open the example. It looks like:

// RF24 Beacon

#include <SPI.h>

#include "RF24Beacon.h"

RF24Beacon beacon( 9,10 );

uint8_t customData[] = { 0x01, 0x02, 0x03 };
    
void setup() {

    beacon.begin();
    beacon.setMAC( 0x01, 0x02, 0x03, 0x04, 0x05, 0xF6 );
    
    uint8_t temp = beacon.setName( "myBeacon" );
    beacon.setData( customData, 2 );

}

void loop() {

    // beacon.sendData( customData, sizeof(customData) );
    beacon.beep();
    
    delay( 1000 );
}

 

  • In line#7, I configure the connection of nRF module. I should be RF24Beacon beacon( pin_CE, pin_CSN );. If you are using an alternate hardware setup, you might like to modify this.
  • In line#14, MAC address for the beacon is set. You can skip this, in that case a random MAC (based on the build date of sketch) will be used as MAC address.
  • Line#16 sets the name which will shown while scanning. Here comes the first limitation - you can set only a name of length atmost 14 characters. Not that bad, this will be enough for my applications.
  • Line#17 sets the custom data that can be send with the packet. And this is the second limitation - Your beacon name+data should not take more than 14 bytes. Here my name is 8 bytes length. So I can pack 6 bytes of data. Here I'm only putting in 2 bytes.
  • Line#24 is the function which transmits a BLE packet. Here, I'm sending a packet every 1 second (line#26).
  • Line#26 shows how to send a a packet with custom data. This way I will be able to send some sensor reading also in the packet image.

 

 

Testing with Raspberry Pi

Now it's time to test the hack. Power up your raspberry Pi. I'm using Pi3 here. Alternatively, any older version of Pi with a bluetooth dongle supporting BLE can also be used.

First we need to install a few packages. Some might be already installed in Pi, but l'm giving the full list.

$ sudo apt-get update
$ sudo apt-get install screen bluez bluez-tools bluez-hcidump

 

Now you can use hcitool to listen to advertised packets:

$ sudo hcitool lescan --duplicates

This will list all the available BLE packets around you. There you will be able to see one with name "myBeacon" (or the name you set in line#16). '--duplicates' flag is added ti continuously list the beacon - otherwise hcitool will list it only once.

 

Next we'll take a look into the raw BLE packet we are receiving at raspberry pi. What we need to do is to start hcitool for scanning and then use hcidump to display the packet. Since I want to run both the command side by side, I'll be using screen utility. You can find more about screen and how to use it here.

 

So in first screen, start hcitool with:

$ sudo hcitool lescan --duplicates

and in second screen, start hcidump with

$ sudo hcidump -R -X

This is how my output looks like after running these commands:

image

Now you will be able to build a cheap ble tags which can be monitored by Pi.

 

Happy hacking,

vish

 

<< Prev | Index | Next >>

  • Sign in to reply

Top Comments

  • BigG
    BigG over 9 years ago in reply to vish +1
    Hi Vish, thanks for your comment. Very helpful. Yes I happen to have actual beacons and a couple of nRF24's lying around. I'm in the process of looking for suitable low cost devices for reading / monitoring…
  • meganoodle
    meganoodle over 8 years ago +1
    Fantastic. I know this is an old post , but I recently come across this and it is exactly what I need. Two things I need to know. What would the best and smallest battery to use in this setup, and how…
Parents
  • BigG
    BigG over 9 years ago

    Wow great post.

     

    I have a question that is related but on slightly different topic (If you have not looked at this hoping others may read my comment and have an answer).

     

    If these nRF24L01+ wireless modules can be made to transmit beacon advertising data packets would it not be possible to try and use a nRF24L01+ as an observer to sniff out advertising data packets from other BLE beacons. If so looking for pointers on how to do this if it is possible. I see you used a Bluetooth dongle for this purpose.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • vish
    vish over 9 years ago in reply to BigG

    Hi BigG,

     

    Quoting from here

    Packet Length: BTLE packets are of various sizes, up to 39 bytes of payload in fact. But the one packet we would really want to support is the CONNECT_REQ packet, which is in fact 34 bytes of payload + 3 of CRC, meaning we'd need to receive 37 bytes if we want to check CRCs, and even if we were willing to throw caution to the wind and ignore them, we need to receive 34. nRF24 will not handle packets over 32 bytes. Sadly the last two bytes are kind of important (hop size and a part of the channel map). This is where we lose.

    So we may not be able to sniff all the packet out there from other 'actual beacons'.

     

    But if you are asking about these fake beacons in particular, then we can use another nRF24 module to sniff all the packets. Please refer to floe's BTLE library here.

     

    But why you want to use another nRF24 module to recv? You can use two nRF24 modules to do basic data transfer in normal mode without going through the pain of faking a BTLE packet image

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
Comment
  • vish
    vish over 9 years ago in reply to BigG

    Hi BigG,

     

    Quoting from here

    Packet Length: BTLE packets are of various sizes, up to 39 bytes of payload in fact. But the one packet we would really want to support is the CONNECT_REQ packet, which is in fact 34 bytes of payload + 3 of CRC, meaning we'd need to receive 37 bytes if we want to check CRCs, and even if we were willing to throw caution to the wind and ignore them, we need to receive 34. nRF24 will not handle packets over 32 bytes. Sadly the last two bytes are kind of important (hop size and a part of the channel map). This is where we lose.

    So we may not be able to sniff all the packet out there from other 'actual beacons'.

     

    But if you are asking about these fake beacons in particular, then we can use another nRF24 module to sniff all the packets. Please refer to floe's BTLE library here.

     

    But why you want to use another nRF24 module to recv? You can use two nRF24 modules to do basic data transfer in normal mode without going through the pain of faking a BTLE packet image

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
Children
  • BigG
    BigG over 9 years ago in reply to vish

    Hi Vish, thanks for your comment. Very helpful. Yes I happen to have actual beacons and a couple of nRF24's lying around. I'm in the process of looking for suitable low cost devices for reading / monitoring beacons prior to deployment. A quick n dirty solution is often useful to confirm things.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube