Bluetooth & BLE · Study deck

Python BLE: RSSI Smoothing and Zones

One weak Bluetooth Low Energy (BLE) packet can make a nearby beacon, a device that broadcasts short radio messages, 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: 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: That mapping connects the Python examples to interoperable interfaces and prevents a link-layer success from being mistaken for an application-contract success.
  • Explain: An all-in-one module still needs sound host wiring, local power decoupling, good board placement, and clear space around its antenna.
  • Explain: Properties say what a client may attempt; the schema says how both sides interpret bytes, units, and versions.
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 Module Architecture

The host controller interface carries commands and data into the baseband block.

  • An all-in-one module still needs sound host wiring, local power decoupling, good board placement, and clear space around its antenna.
BLE module hardware components
BLE module hardware components
iotclass.org

Major section

Visual: BLE GATT Profile Implementation

Properties say what a client may attempt; the schema says how both sides interpret bytes, units, and versions.

  • The worked service makes the distinction concrete: its temperature value is a two-byte signed integer scaled by 0.01 °C.
  • A real client must decode that value and prove the promised read, write, or notification behaviour.
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

That link alone does not mean GATT is ready.

  • The peers may still need to set up trust, find a service, and subscribe to a value.
  • Each step is a separate test point.
  • If one fails, follow the return arrow to the first safe step to try again.
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

RFCOMM and the Bluetooth radio carry the byte stream across the air.

  • At the other end, a virtual COM port lets old serial software use that stream.
  • The simple app view hides more work in the link: the peers must pair, connect, buffer data, and recover after a drop.

Key terms

SPP
SPP is handy for setup and old debug tools, but it still needs timeouts and a clear retry plan.
Bluetooth SPP for serial communication
Bluetooth SPP for serial communication
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 host controller interface carries commands and data into the baseband block.
  • Properties say what a client may attempt; the schema says how both sides interpret bytes, units, and versions.
  • That link alone does not mean GATT is ready.
  • 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?

AIt responds faster to movement while adding more RSSI noise.
BIt smooths RSSI more but responds more slowly to movement.
CIt changes only the first RSSI value, never ongoing response time.
DIt stops classifying zones and emits raw RSSI without smoothing.
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?

ABecause it raises transmission power for every nearby advertiser.
BBecause it removes every device other than the one later connected.
CBecause it focuses the scan on nearby targets using signal strength.
DBecause Bluetooth requires RSSI thresholds for all scanner operation.
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.

Q4A proximity zone flips when a person briefly blocks the radio path. What should the field test change?

AIgnore flips because advertising success proves zone classification works.
BTune smoothing and hysteresis against RSSI traces from the venue.
CTreat every raw RSSI sample as an exact person-to-radio distance.
DRaise thresholds everywhere without first measuring the site signal.
Show answer

Answer: B Measured variation should set the zone decision rule.

iotclass.org

Retrieval practice

Recall check 4 of 4

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

Q5What Linux host path passes BLE library requests to BlueZ and its adapters?

APython Application
BD-Bus / BlueZ
CBLE Python Library
DBLE Hardware (HCI)
Show answer

Answer: B Linux routes library requests through D-Bus to the BlueZ host stack and its adapters.

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 · Measured variation should set the zone decision rule.
  2. B · Linux routes library requests through D-Bus to the BlueZ host stack and its adapters.
  3. A · BLE characteristics accept bytearray values.
iotclass.org