The system classifies every detected device into one of three proximity zones based on its Received Signal Strength Indicator (RSSI). Getting the zone thresholds right for your specific environment is the single most effective way to improve counting accuracy. This guide explains what the zones mean, how to measure real-world RSSI values, and how to push updated thresholds to the system.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/AngelAmoSanchez/TFG-RaspberryPi-BLE/llms.txt
Use this file to discover all available pages before exploring further.
What the zones mean
Signal strength is measured in dBm — a negative number where values closer to zero indicate stronger (nearer) signals. The three zones map to approximate physical distances:| Zone | RSSI range | Approximate distance |
|---|---|---|
NEAR | ≥ −60 dBm | 0 – 2 m |
MEDIUM | ≥ −75 dBm and < −60 dBm | 2 – 5 m |
FAR | < −75 dBm | > 5 m |
src/scanner/detection.py:
DetectionProcessor.classify_zone:
Default thresholds
The defaults are set insrc/config.py and in the backend’s src/config.py:
How environment affects RSSI
RSSI is not a reliable proxy for distance — it varies significantly based on:- Obstacles — walls, shelving, and people between the device and the Pi attenuate the signal. A device that reads −55 dBm in an open corridor might read −75 dBm through a wall at the same physical distance.
- Interference — Wi-Fi (2.4 GHz), microwave ovens, and other BLE devices all compete for the same spectrum.
- Device type — transmit power varies by manufacturer. A smartwatch typically broadcasts at lower power than a phone, producing weaker RSSI at the same distance.
- Antenna orientation — holding a phone in a pocket or bag changes the effective signal level by 5–15 dBm.
Always calibrate thresholds in the actual deployment environment, not in a lab or open space. A single calibration session with a few representative devices is enough to set workable thresholds.
Using calibrate_ble.py to measure RSSI
The calibrate_ble.py script scans for 20 seconds, records RSSI history for every visible device, and then prints summary statistics and suggested thresholds.
Copy the script to the Pi and install Bleak
The script requires Bleak. If you have already run
install.sh, Bleak is already installed in the virtual environment.Run the calibration scan
Stand at the distance you want to define as the boundary between two zones, then run:While the scan runs, walk toward and away from the Pi with a phone, smartwatch, or other BLE device. The script prints live RSSI readings:
Read the summary output
After 20 seconds the script prints per-device statistics and suggested thresholds:The suggested thresholds are percentile-based: the top 30 % of observed signal strengths define the NEAR boundary, the top 70 % define the MEDIUM boundary.
Updating thresholds via the dashboard
The ThresholdSettings component in the frontend provides a form where you can enter new threshold values and save them. Changes take effect immediately and trigger retroactive reclassification of all stored detections.Updating thresholds via the API
You can also update thresholds directly with aPUT request to the settings endpoint:
backend-cloud/src/api/routes/settings.py):
near_threshold > medium_threshold; if that condition is not met it returns HTTP 400.
A successful response includes reclassification statistics:
−60 / −75), send:
- GET current thresholds
- PUT new thresholds
- POST reset to defaults
Retroactive reclassification
When you update thresholds, the backend immediately reclassifies every historical detection record in the database using the new boundaries. Therecalculated block in the API response tells you how many records moved to each zone.
This means historical charts and counts in the dashboard automatically reflect the new thresholds after you save, without any data loss.
The DEVICES_PER_PERSON ratio
The backend estimates the number of people from the number of detected devices using a simple divisor:
1.5, set in both backend-cloud/src/config.py and in fly.toml:
1.5 means the system assumes each person is represented by an average of 1.5 detected device entries per scan cycle.
When to adjust it:
Estimated count is consistently too high
Estimated count is consistently too high
Increase
DEVICES_PER_PERSON. If your venue has many people who carry multiple active BLE devices (smartwatches, earphones) or if MAC randomization is frequent, try values between 2.0 and 3.0.Estimated count is consistently too low
Estimated count is consistently too low
Decrease
DEVICES_PER_PERSON. In venues where many visitors do not carry phones (children’s events, manufacturing floors) or where Bluetooth is commonly disabled, try values closer to 1.0.How to measure the right value
How to measure the right value
Do a manual count in a controlled session: let N known people walk past the Pi, record the raw device count from the API, then calculate
ratio = device_count / N. Run this a few times and average the results.DEVICES_PER_PERSON environment variable on the backend and restart the service.