18 Python BLE: RSSI Smoothing and Zones
More
Depth: Practitioner
Progress saves as you read. Mark sections complete as you go; your progress appears in the sidebar.
18.1 Start With the Decision
This section: Start With the Decision — One weak Bluetooth Low Energy (BLE) packet can make a nearby beacon, a device that broadcasts short radio messages, look far away.
One weak Bluetooth Low Energy (BLE) packet can make a nearby beacon, a device that broadcasts short radio messages, look far away. RSSI is a rough measure of received signal strength, not a distance reading. Smooth a trace of several RSSI readings before a zone, a broad area rather than an exact point, can trigger an action.
18.2 Route Overview
This section: Route Overview — This is part 2 of 3.
This is part 2 of 3. Review Python BLE: Scanning and Connections for the preceding evidence.
18.3 Learning Objectives
This section: Learning Objectives
- Smooth RSSI samples before classifying proximity zones.
- Test zone thresholds against path-loss and radio noise.
18.4 Chapter Roadmap
This section: Chapter Roadmap
- Phoebe’s Field Notes: Why RSSI Distance Moves in Multipliers
- Try It: RSSI Smoothing and Zone Classification
- Putting Numbers to It
- RSSI Limitations
- Checkpoint: RSSI Smoothing and Zones
- Try It: ESP32 BLE Advertiser (Pairs with Python Scanner)
- BLE Power Optimization Decision Flow
- Visual Reference Gallery
- Visual: BLE Module Architecture
- Visual: BLE GATT Profile Implementation
- Visual: BLE Connection Flow
- Visual: BLE Stack Architecture
- Visual: Bluetooth Serial Port Profile
- Knowledge Check
- Deployment Pattern: BLE Proximity System for Retail Analytics
- Checkpoint: Deployment Trade-Offs
- Concept Relationships:
- See Also
- Practice Activities
- Interactive Quiz: Match Python BLE Concepts
- Interactive Quiz: Sequence the Python BLE Implementation
- Label the Diagram
- Code Challenge
- Start With the Story
The EMA filter’s effective window length and response time are:
where is the smoothing factor and is the sampling rate (Hz).
Example: RSSI sampling at 1 Hz (once per second) with :
- Effective window: samples
- Time to reach 95% of new value: seconds
Compare with (more smoothing):
- Effective window: samples
- Response time: seconds
Lower smooths more aggressively but reacts slower to real movement. For proximity detection, balances noise reduction with reasonable tracking speed.
This section:
RSSI-based distance estimation has inherent limitations:
- Multipath fading: Reflections cause +/-6 dBm variance
- Body shadowing: Human body attenuates 5-15 dBm
- Antenna orientation: Different orientations vary +/-10 dBm
- Environmental factors: Walls, furniture, humidity affect signal
Recommendation: Use zone-based classification (immediate/near/far) rather than precise distance calculations. For sub-meter accuracy, consider UWB technology instead.
This section:
This section:
Checkpoint: RSSI Smoothing and Zones
You now know:
- The chapter’s zone boundaries are immediate above
-55 dBm, near from about-55 dBmto-70 dBm, and far below-70 dBm. - EMA smoothing uses
smoothed_rssi = alpha * new_rssi + (1 - alpha) * prev_smoothed, so lowering alpha from0.3to0.1smooths more but slows response from about10seconds to about30seconds at1 Hz. - RSSI can vary by multipath, body shadowing, antenna orientation, and environment, so BLE proximity evidence should defend broad zones rather than exact meters.
This section:
18.5 BLE Power Optimization Decision Flow
This section: BLE Power Optimization Decision Flow — When building battery-powered BLE devices, power optimization is critical.
When building battery-powered BLE devices, power optimization is critical. Inspect Figure 18.1 to turn that broad goal into an ordered design review: begin with the application’s actual data-rate and latency need, then choose whether the device needs a connection at all before tuning radio parameters.
Read Figure 18.1 from the data-rate question into its connection and beacon branches. A connected product tunes connection interval; a broadcaster tunes advertising interval. Both paths then converge on sleep mode and transmit power. 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. Record those trade-offs alongside the measured current trace.
18.6 Visual Reference Gallery
This section: Visual Reference Gallery
Before treating a BLE module as one opaque part, inspect Figure 18.2 to link code-visible behaviour to the controller, radio path, antenna network, and power blocks that produce it.
Read Figure 18.2 from the host link to the antenna. The host controller interface carries commands and data into the baseband block. The radio then turns those bits into an RF signal. Antenna matching guides that signal to the antenna. Check the power block last, since a weak supply or poor sleep control can upset every other part. An all-in-one module still needs sound host wiring, local power decoupling, good board placement, and clear space around its antenna.
Inspect Figure 18.3 to ask what a client may do, how both sides read each value, and how they agree that notices are active.
Read Figure 18.3 from characteristic properties to value schema and version. Properties say what a client may attempt; the schema says how both sides interpret bytes, units, and versions. Check permissions and security before following descriptors to the CCCD subscription state, because a notify property alone does not prove that notifications were enabled. 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. A connection-only test never reaches these application-contract checks.
Inspect Figure 18.4 to ask which step failed when radio discovery succeeds but the app session still cannot exchange a value.
Read Figure 18.4 from the scan to the app exchange. Pause after the radio link forms. 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. Keep the granted interval, peer delay, link timeout, MTU, notice rate, and drop reason in one record. A fast scan has little value if the later steps or the return path cannot be seen and tested.
Inspect Figure 18.5 to locate which layer owns a symptom before changing application code. The controller/host split is especially important when a module exposes HCI rather than running the complete application stack internally.
Read Figure 18.5 upward from PHY and Link Layer through L2CAP, ATT, GATT, and GAP, noting where HCI separates controller duties from host protocols. RF loss belongs near the bottom; attribute permissions and values belong near ATT/GATT; discovery roles and advertising behavior belong to GAP. That mapping connects the Python examples to interoperable interfaces and prevents a link-layer success from being mistaken for an application-contract success.
When a product already speaks UART, inspect Figure 18.6 to see which serial behaviour SPP keeps and which new timing or link faults it adds.
Follow Figure 18.6 from the UART to the host app. 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. SPP is handy for setup and old debug tools, but it still needs timeouts and a clear retry plan. Test short writes, link loss, and repeat connections as well as a steady stream.
18.7 Knowledge Check
This section: Knowledge Check
18.8 Deployment Pattern: BLE Proximity System for Retail Analytics
This 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.
Retail analytics systems often use BLE proximity detection to estimate customer dwell time and foot-traffic patterns. A typical design places Python gateways on small Linux computers near entrances and key departments, then classifies nearby beacon traffic into immediate, near, and far zones.
System Specifications:
- Scan interval:
2 seconds, balancing detection speed against gateway CPU load. - RSSI threshold:
-75 dBm, filtering devices beyond the useful local radius. - EMA alpha:
0.2, prioritizing stability over responsiveness for dwell-time estimates. - Zone boundaries:
-55 dBmand-70 dBm, mapping readings to immediate, near, and far zones. - Minimum samples:
3, requiring consecutive readings before assigning a zone. - Gateway density:
4to6gateways for a medium retail floor, adjusted after site survey testing.
Why EMA Alpha = 0.2 (Not 0.3)?
An alpha of 0.3 responds faster than 0.2; neither is a standard setting. For an illustrative step from -60 to -80 dBm with a -70 dBm far threshold and one sample every 2 seconds, alpha 0.3 crosses the threshold after 2 new readings (4 seconds), while alpha 0.2 crosses after 4 (8 seconds). A slower filter can suppress a brief body-shadowing dip, but it also delays a real departure; tune alpha and hysteresis from site traces.
Battery Impact on Beacons:
Assume a BLE beacon with a 1000 mAh battery advertising at 1 Hz:
- Advertising current per event:
8 mA. - Event duration, including radio ramp-up:
3 ms. - Events per day at
1 Hz:86,400. - Daily energy at
1 Hz:8 mA x 0.003 s x 86,400 = 2,073.6 mA-s, and dividing by3,600converts to0.576 mAh/day. - Estimated battery life at
1 Hz:1000 mAh / 0.576 mAh = 1,736 daysfrom advertising alone — sleep current and sensor reads shorten this in practice. - Estimated battery life at
10 Hz: about174 days, because daily energy rises to5.76 mAh/day.
This is why many deployments prefer 1 Hz advertising with gateway-side EMA smoothing. 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.
This section:
Checkpoint: Deployment Trade-Offs
You now know:
- The retail pattern combines a
2 secondsscan interval,-75 dBmfilter, alpha0.2,-55 dBmand-70 dBmzone boundaries, and3consecutive samples before assigning a zone. - For a
1000 mAhbeacon advertising at1 Hz, the chapter’s arithmetic gives0.576 mAh/dayand about1,736 daysfrom advertising alone. - Raising the rate to
10 Hzimproves responsiveness but cuts the advertising-only estimate to about174 days, so gateway-side smoothing is often the better maintenance choice.
This section: — At this point the script has enough design context to be reviewed.
At this point the script has enough design context to be reviewed. The remaining sections test whether the same choices survive quizzes, runtime limits, disconnections, and common implementation mistakes.
This section:
- 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.
- GATT explorer and service discovery: Enumerating UUIDs maps device capabilities before data access.
- 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.
This section:
18.9 See Also
This section: See Also
- BLE Hands-On Labs - Complete project implementations with heart rate monitors and positioning
- BLE Code Examples - Basic Python scanner patterns and GATT concepts
- Bluetooth Security - Understanding secure device pairing
- Bluetooth Applications - Real-world BLE deployment case studies
18.10 Practice Activities
This section: Practice Activities
18.11 Start With the Story
This section: Start With the Story — A laptop running Python can turn BLE from a black box into a repeatable inspection tool.
A laptop running Python can turn BLE from a black box into a repeatable inspection tool. Scans, filters, UUIDs, GATT reads, notifications, RSSI samples, and exceptions become evidence a team can rerun.
Use this chapter to make automation serve the design review. Write the smallest Bleak script that observes the claim, log the result, and connect the script output back to the device behavior it is meant to prove.
18.12 Continue to the Next Part
This section: Continue to the Next Part — Carry this evidence into Python BLE: Runtime Boundaries and Positioning, which begins with Deep Dive: Bleak Role Boundaries and Runtime Limits.
Carry this evidence into Python BLE: Runtime Boundaries and Positioning, which begins with Deep Dive: Bleak Role Boundaries and Runtime Limits.
Find help
3 reviewed answers.
Where should I start in a module?
Open the module page from the sidebar to see its chapters in order. Use the module map to return to a topic you need.
Modules and pathsReviewed
What can I try when a project does not work?
Check the symptom, then work through the diagnostic steps. Keep the error message and the smallest example that reproduces it.
When you are stuckReviewed
How do interactive examples work?
Use the interactive guide to check how examples and simulations work before changing your project.
Interactive examples guideReviewed
