Bird
Raised Fist0
IOT Protocolsdevops~6 mins

BLE advertising and scanning in IOT Protocols - Full Explanation

Choose your learning style10 modes available
Introduction
Imagine you want your phone to find nearby wireless devices like headphones or fitness trackers without connecting first. This is a challenge because devices need a way to announce their presence and listen for others without using too much power.
Explanation
BLE Advertising
BLE devices send out small packets of information called advertisements. These packets contain data like the device name or services it offers. Advertising happens on specific channels to make it easier for other devices to find them quickly and efficiently.
Advertising is how BLE devices broadcast their presence and basic info to nearby devices.
Advertising Types
There are different ways a device can advertise, such as connectable or non-connectable advertising. Connectable advertising allows other devices to start a connection, while non-connectable advertising just shares information without allowing connections.
Advertising types control whether devices can connect or just share info.
BLE Scanning
Scanning is when a device listens on advertising channels to find nearby BLE devices. It can be passive, just listening, or active, where it sends a request to get more information from the advertiser.
Scanning lets devices discover advertisers by listening or asking for more data.
Power Efficiency
Both advertising and scanning are designed to use very little power. Devices advertise or scan only for short bursts and then sleep, which helps battery-powered devices last longer.
BLE advertising and scanning balance discovery with low power use.
Real World Analogy

Imagine you are at a party where people wear name tags and shout out their names briefly so others can notice them. Some people just shout their names, while others are ready to chat if someone responds. Meanwhile, others listen carefully to catch these names and decide who to talk to.

BLE Advertising → People shouting their names to announce they are there
Advertising Types → Some people shout just to be noticed, others shout and are ready to chat
BLE Scanning → People listening carefully to hear names and decide who to approach
Power Efficiency → People shouting and listening only briefly to save energy for the party
Diagram
Diagram
┌───────────────┐       ┌───────────────┐
│ BLE Advertiser│──────▶│ BLE Scanner   │
│ (Sends Ads)   │       │ (Listens Ads) │
└───────────────┘       └───────────────┘
       ▲                        │
       │                        │
       │<───── Scan Request ────┘
       │
       │
       │
       │
       ▼
┌───────────────┐
│ Advertising   │
│ Channels      │
└───────────────┘
This diagram shows a BLE advertiser sending advertisements on channels and a scanner listening and optionally sending scan requests.
Key Facts
BLE Advertising → Broadcasting small packets to announce a device's presence and capabilities.
Advertising Channels → Specific radio channels used by BLE devices to send advertisements.
Connectable Advertising → Advertising that allows other devices to initiate a connection.
Non-Connectable Advertising → Advertising that only shares information without allowing connections.
BLE Scanning → Listening for advertisements to discover nearby BLE devices.
Active Scanning → Scanning where the scanner sends a request to get more data from the advertiser.
Common Confusions
Believing all BLE advertising allows connections.
Believing all BLE advertising allows connections. Not all advertising is connectable; some devices only broadcast info without accepting connections.
Thinking scanning always involves sending requests.
Thinking scanning always involves sending requests. Scanning can be passive (just listening) or active (sending requests), but passive scanning is common to save power.
Assuming advertising and scanning use a lot of battery.
Assuming advertising and scanning use a lot of battery. BLE advertising and scanning are designed for short bursts and low power use to extend battery life.
Summary
BLE advertising lets devices announce themselves by sending small packets on special channels.
Devices can advertise in ways that allow connections or just share information without connecting.
Scanning listens for these advertisements and can ask for more info, all while saving battery power.

Practice

(1/5)
1. What is the main purpose of BLE advertising in Bluetooth Low Energy communication?
easy
A. To broadcast small packets of data repeatedly to nearby devices
B. To establish a full connection between devices
C. To encrypt data between devices
D. To scan for other devices' signals

Solution

  1. Step 1: Understand BLE advertising role

    BLE advertising sends small data packets repeatedly to announce presence.
  2. Step 2: Differentiate from scanning and connection

    Advertising is broadcasting, not scanning or connecting.
  3. Final Answer:

    To broadcast small packets of data repeatedly to nearby devices -> Option A
  4. Quick Check:

    Advertising = broadcast small data [OK]
Hint: Advertising means sending out info repeatedly [OK]
Common Mistakes:
  • Confusing advertising with scanning
  • Thinking advertising establishes connections
  • Assuming advertising encrypts data
2. Which of the following is the correct command to start BLE scanning using the Linux tool bluetoothctl?
easy
A. ble scan start
B. start scan
C. scan start
D. scan on

Solution

  1. Step 1: Recall bluetoothctl scan command

    The correct command to start scanning is exactly scan on.
  2. Step 2: Check other options for syntax

    Other options are incorrect commands or invalid syntax in bluetoothctl.
  3. Final Answer:

    scan on -> Option D
  4. Quick Check:

    bluetoothctl scan on = start scanning [OK]
Hint: Use exact command 'scan on' in bluetoothctl [OK]
Common Mistakes:
  • Using 'start scan' instead of 'scan on'
  • Typing commands not supported by bluetoothctl
  • Confusing scan commands with advertising commands
3. Given this Python snippet using a BLE library to scan devices:
devices = scanner.scan(5.0)
for dev in devices:
print(dev.addr)

What will this code output?
medium
A. Empty list because scan time is too short
B. List of device addresses found during 5 seconds scan
C. Error because scan() needs no arguments
D. List of device names found during 5 seconds scan

Solution

  1. Step 1: Understand scan() usage with timeout

    The scan method scans for devices for given seconds and returns device objects.
  2. Step 2: Identify printed attribute

    Printing dev.addr outputs device MAC addresses found.
  3. Final Answer:

    List of device addresses found during 5 seconds scan -> Option B
  4. Quick Check:

    scan(5.0) returns devices; dev.addr prints addresses [OK]
Hint: scan(timeout) returns devices; print dev.addr for addresses [OK]
Common Mistakes:
  • Thinking scan() takes no arguments
  • Confusing device address with device name
  • Assuming scan always returns empty list
4. You wrote this code to scan BLE devices but get no output:
scanner = Scanner()
devices = scanner.scan()
for dev in devices:
print(dev.addr)

What is the likely problem?
medium
A. print(dev.addr) is incorrect attribute
B. Scanner() class does not exist
C. Missing scan timeout argument causes no devices found
D. scan() method should be called with 'start' keyword

Solution

  1. Step 1: Check scan() method requirements

    scan() requires a timeout argument to specify scan duration.
  2. Step 2: Understand effect of missing timeout

    Without timeout, scan may return immediately with no devices.
  3. Final Answer:

    Missing scan timeout argument causes no devices found -> Option C
  4. Quick Check:

    scan() needs timeout to find devices [OK]
Hint: Always provide scan timeout to get results [OK]
Common Mistakes:
  • Omitting scan timeout argument
  • Assuming dev.addr is invalid
  • Thinking scan() uses 'start' keyword
5. You want to filter BLE scan results to only show devices advertising a specific service UUID. Which approach correctly applies this filter in Python?
hard
A. Use a list comprehension: [dev for dev in devices if '1234' in dev.getScanData()]
B. Check if '1234' in dev.addr for each device
C. Filter devices by comparing dev.name to '1234'
D. Use devices.filter('1234') method directly

Solution

  1. Step 1: Understand filtering by service UUID

    Service UUIDs appear in scan data, not in address or name.
  2. Step 2: Use list comprehension with getScanData()

    getScanData() returns advertised data; check if UUID '1234' is present.
  3. Final Answer:

    Use a list comprehension: [dev for dev in devices if '1234' in dev.getScanData()] -> Option A
  4. Quick Check:

    Filter by UUID in scan data using list comprehension [OK]
Hint: Filter devices by checking UUID in scan data list [OK]
Common Mistakes:
  • Checking UUID in device address
  • Filtering by device name instead of UUID
  • Using non-existent filter() method on devices
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard