Skip to content
Redirecting to exemplar docs...

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 πŸš€

  1. 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.

  2. 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.

  3. 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.
  4. The demo_connect example is designed as a challenge exercise, encouraging more self-directed learning. It builds on the basics from the demo 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.