Bluetooth & BLE · Study deck

Python BLE: RSSI Smoothing and Zones

One weak BLE packet can make a nearby beacon look far away.

Radio Remi is your guide for this deck.

implpythonindoor
Radio Remi, the module guide, in a scene from this chapter.
iotclass.org

After studying this chapter

Learning objectives

You will be able to:

  • Explain: This order connects latency and power tuning to correctness: shortening discovery or connection time is useful only when security, service discovery, subscriptions, data exchange, and reconnect behavior remain observable and reliable.
  • Explain: The sequence matters because reducing TX power cannot compensate for a radio that wakes too often, and a long sleep schedule is unacceptable if it breaks the promised response time.
  • Explain: Raising the advertising rate by 10x can make detection feel faster, but it also turns a maintenance interval measured in years into one measured in months.
  • Smooth RSSI samples before classifying proximity zones.
iotclass.org

Major section

BLE Power Optimization Decision Flow

The sequence matters because reducing TX power cannot compensate for a radio that wakes too often, and a long sleep schedule is unacceptable if it breaks the promised response time.

  • When building battery-powered BLE devices, power optimization is critical.
BLE power optimization decision flow from data-rate need through connection interval, advertising interval, sleep mode, and TX power tuning
BLE power optimization decision flow from data-rate need through connection interval, advertising interval, sleep mode, and TX power tuning
iotclass.org

Major section

Visual: BLE GATT Profile Implementation

The evidence path at the end asks whether real clients can read, write, and receive notifications with the agreed encoding.

  • That ordered review connects the Python implementation to interoperable behavior and exposes contracts that a connection-only test would miss.
BLE GATT client-server contract covering properties, schema, security, descriptors, subscription state, and evidence
BLE GATT client-server contract covering properties, schema, security, descriptors, subscription state, and evidence
iotclass.org

Major section

Visual: BLE Connection Flow

The path matters because each boundary can succeed while a later one still fails, and each failure needs different evidence.

  • This order connects latency and power tuning to correctness: shortening discovery or connection time is useful only when security, service discovery, subscriptions, data exchange, and reconnect behavior remain observable and reliable.
BLE connection evidence path from discovery through link, security, GATT readiness, application exchange, and recovery
BLE connection evidence path from discovery through link, security, GATT readiness, application exchange, and recovery
iotclass.org

Major section

Visual: BLE Stack Architecture

That mapping connects the Python examples to interoperable interfaces and prevents a link-layer success from being mistaken for an application-contract success.

  • The controller/host split is especially important when a module exposes HCI rather than running the complete application stack internally.
BLE protocol stack layers
BLE protocol stack layers
iotclass.org

Major section

Visual: Bluetooth Serial Port Profile

The application can retain a serial-stream interface, but pairing, link establishment, buffering, disconnection, and reconnection now sit in the path.

  • That makes SPP useful for legacy debugging and configuration while requiring explicit timeout and recovery handling.
Bluetooth SPP for serial communication
Bluetooth SPP for serial communication
iotclass.org

Major section

Deployment Pattern: BLE Proximity System for Retail Analytics

Retail analytics systems often use BLE proximity detection to estimate customer dwell time and foot-traffic patterns.

  • A customer stepping behind a display rack causes a sudden 10-15 dBm drop.
  • With alpha 0.2, it takes 4 readings (8 seconds) -- long enough for the customer to move again, preventing a spurious zone change.
  • Raising the advertising rate by 10x can make detection feel faster, but it also turns a maintenance interval measured in years into one measured in months.
iotclass.org

Major section

Concept Relationships:

RSSI filtering and zone-based detection: Threshold filtering reduces noise from distant devices before zone classification runs.

  • EMA smoothing and proximity detection: Exponential moving average stabilizes noisy RSSI readings so zones do not flicker.
  • Beacon protocols and indoor positioning: iBeacon and Eddystone formats provide repeatable advertisement structures for location services.
  • bleak and cross-platform support: One async Python API can target Windows, macOS, and Linux backends.
iotclass.org

Deck summary

Key takeaways

The sequence matters because reducing TX power cannot compensate for a radio that wakes too often, and a long sleep schedule is unacceptable if it breaks the promised response time.

  • The evidence path at the end asks whether real clients can read, write, and receive notifications with the agreed encoding.
  • The path matters because each boundary can succeed while a later one still fails, and each failure needs different evidence.
  • That mapping connects the Python examples to interoperable interfaces and prevents a link-layer success from being mistaken for an application-contract success.
iotclass.org

Retrieval practice

Recall check 1 of 4

Radio Remi says: answer from memory, then check your reasoning.

Q1A BLE proximity system uses EMA smoothing with alpha=0.3 at 1 Hz. How does reducing alpha to 0.1 affect the system?

AThe system responds faster to movement but with more RSSI noise
BIt smooths more but responds more slowly
CAlpha has no effect on response time — it only changes the initial RSSI reading
DThe system stops classifying zones and only outputs raw RSSI values
Show answer

Answer: B With alpha=0.1, effective window = 2/0.1 - 1 = 19 samples and 95% response time = -ln(0.05)/0.1 = 30 seconds. This greater smoothing reduces false zone transitions in noisy environments like crowded retail spaces.

iotclass.org

Retrieval practice

Recall check 2 of 4

Radio Remi says: answer from memory, then check your reasoning.

Q2Why is RSSI threshold filtering important in production BLE scanners?

AIt increases the Bluetooth transmission power of nearby devices
BIt eliminates all devices except the one you want to connect to
CIt focuses scanning on nearby targets
DIt is required by the Bluetooth specification for all scanning operations
Show answer

Answer: C Setting a minimum RSSI threshold (e.g., -70 dBm) filters out distant devices, reducing processing overhead and focusing discovery on devices within a useful range.

Q3What is the standard BLE GATT service UUID for the Heart Rate Service?

A0x180F (Battery Service)
B0x180D (Heart Rate Service)
C0x181A (Environmental Sensing)
D0x1816 (Cycling Speed and Cadence)
Show answer

Answer: B 0x180D is the Bluetooth SIG-assigned UUID for the Heart Rate Service.

iotclass.org

Retrieval practice

Recall check 3 of 4

Radio Remi says: answer from memory, then check your reasoning.

Q4Why do BLE proximity systems use zone-based classification (immediate/near/far) rather than precise distance calculations?

ABLE devices cannot measure RSSI values accurately enough for any distance estimation
BRSSI is too variable for precise distance
CThe Bluetooth specification only defines three distance zones and does not support continuous ranging
DPrecise distance calculations require UWB hardware, which BLE devices do not have
Show answer

Answer: B RSSI can vary by +/-6 dBm from multipath fading, 5-15 dBm from body shadowing, and +/-10 dBm from antenna orientation.

iotclass.org

Retrieval practice

Recall check 4 of 4

Radio Remi says: answer from memory, then check your reasoning.

Q5Place each BLE Python runtime layer where it lives so you can trace an application call through the host stack to the radio controller.

APython Application
BC++ Application
CJava Application
DRust Application
Show answer

Answer: A The three regions separate Python intent, host-side BLE services, and controller hardware so you can diagnose which boundary owns a failed scan, GATT call, or radio exchange.

Q6Complete the code to write a value to a BLE GATT characteristic:

Avalue = bytearray([1 if state else 0])
Bvalue = str(state).encode('utf-8')
Cvalue = bytes(state)
Dvalue = int(state).to_bytes(1)
Show answer

Answer: A BLE characteristics accept bytearray values.

iotclass.org

Print reference

Answers 1 of 2

Answer key.

  1. B · With alpha=0.1, effective window = 2/0.1 - 1 = 19 samples and 95% response time = -ln(0.05)/0.1 = 30 seconds. This greater smoothing reduces false zone transitions in noisy environments like crowded retail spaces.
  2. C · Setting a minimum RSSI threshold (e.g., -70 dBm) filters out distant devices, reducing processing overhead and focusing discovery on devices within a useful range.
  3. B · 0x180D is the Bluetooth SIG-assigned UUID for the Heart Rate Service.
iotclass.org

Print reference

Answers 2 of 2

Answer key.

  1. B · RSSI can vary by +/-6 dBm from multipath fading, 5-15 dBm from body shadowing, and +/-10 dBm from antenna orientation.
  2. A · The three regions separate Python intent, host-side BLE services, and controller hardware so you can diagnose which boundary owns a failed scan, GATT call, or radio exchange.
  3. A · BLE characteristics accept bytearray values.
iotclass.org