A BLE (Bluetooth Low Energy) Neighbour Discovery Protocol on nRF52¶
This exemplar demonstrates the implementation of a BLE neighbor discovery protocol on the nRF52 platform using nRF Connect for VS Code. Each device alternates between advertising and scanning according to a scheduled time pattern, enabling unidirectional neighbor discovery. Once a peer is discovered, the device initiates a connection and uses a custom BLE service to exchange data.
Although Nordic provides a BLE tutorial course, the official examples typically demonstrate a device in the Peripheral role (GAP, Generic Access Profile) or Server role (GATT, Generic Attribute Profile) interacting with a mobile app. This exemplar goes further by walking through the Central and Client as well, enabling your devices to interact directly with each other.
This exemplar was developed at Imperial College London by Sabrina Wang in collaboration with Jay DesLauriers from Research Software Engineering and Dan Cummins from Research Computing & Data Science at the Early Career Researcher Institute.
Learning Outcomes π¶
After completing this exemplar, students will:
- Understand basic BLE stack concepts.
- Implement BLE advertising, scanning, and connection.
- Build a simple neighbor discovery and data exchange application using BLE services.
Target Audience π―¶
-
Graduate and undergraduate students new to BLE technology who need practical experience for their research or projects.
-
Students seeking a hands-on introduction to BLE neighbor discovery protocols and GATT services.
-
Learners interested in wireless communication and low-power device design using nRF52 platforms.
-
Anyone aiming to build foundational BLE skills for academic coursework or prototyping.
Prerequisites β ¶
Academic π¶
-
Basic knowledge of C programming (variables, functions, control structures).
-
No prior experience with BLE is required β this exemplar includes guidance and references to official BLE tutorials to support beginners.
System π»¶
-
A Nordic BLE development board (e.g. nRF52832 DK or nRF52840 DK).
-
A USB cable for programming and serial communication.
-
A development environment set up by following Lesson 1 of Nordic's official nRF Connect SDK Fundamentals course:
π https://academy.nordicsemi.com/courses/bluetooth-low-energy-fundamentals/
Getting Started π¶
-
Before diving into this exemplar, itβs important to ensure your development environment is properly set up. We highly recommend starting with Lesson 1, Exercise 1 from Nordic Semiconductorβs official nRF Connect SDK Fundamentals tutorial. This exercise will guide you step-by-step through installing the essential development tools and configuring your environment for success.
-
Once youβre comfortable with that, take a moment to complete Exercise 2. It offers practical experience in building and flashing applications onto your development board using the nRF Connect SDK. If youβre new to Nordicβs workflow, this exercise will be especially valuable in helping you become familiar with compiling firmware and programming your device smoothly.
-
The Notebook: demo notebook walks you through the beginner-level example in the
demo
folder step by step:- Learn the theory: It first refers to the What is BLEnd? Theoretical Foundations and BLE Advertising and Scanning: What You Need to Know documents in the
docs
folder to introduce the basics of BLE and the BLEnd protocol. - Understand the code: Next, it uses the How to Use a Timer and Introduction to GAP. document to explain how the example code interacts with the official BLE API (Application Programming Interface).
- See the results: Finally, it presents the observed output so you can compare your own results with the expected behavior. In this stage, you should see your devices scanning and advertising, allowing them to discover nearby devices.
- Learn the theory: It first refers to the What is BLEnd? Theoretical Foundations and BLE Advertising and Scanning: What You Need to Know documents in the
-
The
demo_connect
example is designed as a challenge exercise, encouraging more self-directed learning. It builds on the basics from thedemo
example and introduces additional concepts, such as creating and using a customized GATT service after establishing a connection. The Notebook: demo_connect notebook provides learning resources, service explanation and observed results.
Project Structure ποΈ¶
Overview of code organisation and structure.
.
βββ demo
β βββ src
β β βββ advertiser_scanner.c
β β βββ advertiser_scanner.h
β β βββ blend.c
β β βββ blend.h
β β βββ main.c
β βββ CMakeLists.txt
β βββ prj.conf
βββ demo_connect
β βββ src
β β βββ advertiser_scanner.c
β β βββ advertiser_scanner.h
β β βββ blend.c
β β βββ blend.h
β β βββ main.c
β β βββ my_lbs.c
β β βββ my_lbs.h
β β βββ my_lbs_client.c
β β βββ my_lbs_client.h
β βββ CMakeLists.txt
β βββ prj.conf
βββ docs
β βββ BLE_Background.md
β βββ BLEnd.md
β βββ introduction_to_GAP.md
β βββ introduction_to_Ktimer.md
βββ notebooks
β βββ demo.md
β βββ demo_connect.md
βββ README.md
Code is organised into logical components: - demo
for beginner-level code, potentially divided into further modules - demo_connect
for challenge code, potentially divided into further modules - docs
for documentation - notebooks
for tutorials and exercises
Estimated Time β³¶
Task | Time |
---|---|
Reading | 4 hours |
Practising | 2 hours |
Additional Resources π¶
Licence π¶
This project is licensed under the BSD-3-Clause license.