Bluetooth & BLE · Study deck
Python BLE: Scanning and Connections
A Bluetooth Low Energy (BLE) scanner listens for adverts, the short broadcasts nearby devices send.
Radio Remi is your guide for this deck.

After studying this chapter
Learning objectives
You will be able to:
- Implement Production BLE Scanners: Configure device filtering by RSSI threshold and name patterns using the bleak library
- Analyze GATT Services: Connect to BLE devices and enumerate services and characteristics to assess device capabilities
- Distinguish Beacon Protocols: Compare iBeacon and Eddystone advertisement packet structures and justify protocol selection for a given use case
- Design Proximity Detection Systems: Apply RSSI smoothing algorithms and construct zone-based presence detection with exponential moving averages
Major section
Start With the Decision
A Bluetooth Low Energy (BLE) scanner listens for adverts, the short broadcasts nearby devices send.
- The code must filter for the right device before connecting.
- A timeout is the limit on how long it waits for that connection.
Major section
In 60 Seconds
BLE is the low-energy branch of Bluetooth: RSSI is a number that shows the received signal level.
- The program must find the right tag, connect only when needed, read the expected value, and continue after the tag moves away.
- Signal strength can support a rough zone, but it is not a tape measure.
Major section
In 60 Seconds (continued)
Walls, bodies, radio power, and device position can move the reading.
- Under the Hood explains runtime limits and the maths behind rough signal zones.
- A name may be absent or copied.
- An awaited task lets other work run while it waits.
- A long block in a callback can hold up new data and clean shutdown.
Major section
In 60 Seconds (continued)
Production apps need RSSI filtering, GATT service exploration, and exponential smoothing for proximity -- zone-based classification (immediate/near/far) is far more reliable than precise distance calculations due to RSSI variability.
- The program should end without a stuck scan or hidden task.
- For long runs, add a reconnect rule.
- Smooth only enough to support the named zone.
Major section
In 60 Seconds (continued)
For the museum case it might be, "Find tag A, read its heat value, and store one fresh row." That line keeps a scan demo from growing into an unsafe service by accident.
- Recheck after any of these change.
- A script that works once is a start, not a support plan.
- BLE development in Python uses the bleak library for cross-platform async scanning, connecting, and GATT interaction.
Major section
Key Concepts
BleakClient: bleak class representing a connection to a BLE peripheral; provides methods for service discovery, read, write, start_notify, stop_notify.
- BleakScanner: bleak class for BLE device discovery; supports filtering by service UUID, device name, and RSSI threshold.
- asyncio.run(): Python coroutine runner; required for bleak operations which are all async; use asyncio.get_event_loop() for integration with existing async frameworks.
Major section
Python BLE Implementation Pattern
In this pattern, the Python host is the BLE Central and GATT client.
- While scanning it is acting as an Observer; after selection it initiates the connection and reads, writes, or subscribes to the peripheral's GATT server.
Major section
BLE Scanner with Device Filtering
For implementation review, keep a repeatable scanner log: adapter used, scan timeout, target name or service UUID, RSSI threshold, advertisements received, advertisements rejected by filters, and the selected device identifier.
- The script should keep a short sample window and select the strongest stable match instead of connecting to the first advertisement packet it sees.
Major section
BLE Proximity Detector
A typical approach trace should show the raw RSSI, smoothed RSSI, estimated distance, and current zone at each sample.
- A higher alpha reacts faster but lets more noise through.
- A lower alpha is steadier but takes longer to follow real movement.
- Values around 0.2 to 0.3 are common starting points for zone-based proximity.
Deck summary
Key takeaways
A Bluetooth Low Energy (BLE) scanner listens for adverts, the short broadcasts nearby devices send.
- BLE is the low-energy branch of Bluetooth: RSSI is a number that shows the received signal level.
- Walls, bodies, radio power, and device position can move the reading.
- Production apps need RSSI filtering, GATT service exploration, and exponential smoothing for proximity -- zone-based classification (immediate/near/far) is far more reliable than precise distance calculations due to RSSI variability.
- BleakClient: bleak class representing a connection to a BLE peripheral; provides methods for service discovery, read, write, start_notify, stop_notify.
Retrieval practice
Recall check 1 of 6

Radio Remi says: answer from memory, then check your reasoning.
Q1A BLE implementation works once in a demo. What evidence is still needed before accepting the design?
Show answer
Answer: D BLE implementation review needs observable behavior, not just a one-time demo result.
Retrieval practice
Recall check 2 of 6

Radio Remi says: answer from memory, then check your reasoning.
Q2An async BLE app stops receiving data after a disconnect. What should its event flow handle?
Show answer
Answer: A BLE links can drop during normal use, so the app needs a reconnect path.
Retrieval practice
Recall check 3 of 6

Radio Remi says: answer from memory, then check your reasoning.
Q3A Bleak client connects but cannot read the expected value. What should it inspect next?
Show answer
Answer: A The device must expose the expected GATT path and operation.
Retrieval practice
Recall check 4 of 6

Radio Remi says: answer from memory, then check your reasoning.
Q4A venue needs beacon IDs grouped by building area and individual display. Which format matches that field plan?
Show answer
Answer: C Those fields support grouping and a distinct beacon identity.
Retrieval practice
Recall check 5 of 6

Radio Remi says: answer from memory, then check your reasoning.
Q5A beacon must broadcast a compact web link. Which format fits that job?
Show answer
Answer: A That frame carries a compact link in its advertisement.
Retrieval practice
Recall check 6 of 6

Radio Remi says: answer from memory, then check your reasoning.
Q6A proximity zone flips back and forth as RSSI varies. What should the app add?
Show answer
Answer: A Smoothing reduces jumps caused by noisy radio samples.
Print reference
Answers
Answer key.
- D · BLE implementation review needs observable behavior, not just a one-time demo result.
- A · BLE links can drop during normal use, so the app needs a reconnect path.
- A · The device must expose the expected GATT path and operation.
- C · Those fields support grouping and a distinct beacon identity.
- A · That frame carries a compact link in its advertisement.
- A · Smoothing reduces jumps caused by noisy radio samples.