The default zone thresholds (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.
NEAR_THRESHOLD=-60, MEDIUM_THRESHOLD=-75) are conservative starting points. Signal strength varies significantly depending on the Raspberry Pi’s Bluetooth adapter, nearby walls and furniture, and the type of devices being detected. The calibrate_ble.py script performs a live scan in your target environment and recommends thresholds derived from the actual signal distribution.
What the tool does
calibrate_ble.py runs a 20-second passive BLE scan using BleakScanner with the same callback mechanism as the main agent. During the scan it prints each detected advertisement in real time so you can observe how RSSI changes as you move a device closer or further away. After the scan completes it prints:
- Per-device statistics — average, maximum, and minimum RSSI, detection count, and dwell time.
- Percentile-based threshold recommendations — the top 30 % of signal strengths becomes
near_threshold, the top 70 % becomesmedium_threshold. - A signal distribution histogram across five distance bands.
Running the calibration tool
The tool must run with the same BLE capabilities as the main agent. Activate the virtual environment and run it directly:Real-time output during the scan
As devices are detected the tool prints one line per advertisement:| RSSI range | Label |
|---|---|
| ≥ −50 dBm | MUY CERCA (< 1 m) |
| −60 to −51 dBm | CERCA (1–2 m) |
| −70 to −61 dBm | MEDIO (2–4 m) |
| −80 to −71 dBm | LEJOS (4–8 m) |
| < −80 dBm | MUY LEJOS (> 8 m) |
Summary output after the scan
After the 20-second window the tool prints a full summary:Recommended thresholds
At the bottom of the output the tool calculates thresholds from all collected RSSI values using two percentiles:near_threshold. The 70th-percentile value becomes medium_threshold. Signals weaker than medium_threshold are classified as FAR.
Signal distribution histogram
The final section shows how many readings fell in each distance band, with a bar chart:MUY LEJOS you may have too few devices nearby during calibration — repeat the scan with more representative traffic.
Applying the recommended thresholds
Open.env and update the two threshold variables with the values printed by the tool:
Calibration tips
Run at expected crowd density
Run at expected crowd density
RSSI distributions shift when many devices are present simultaneously. Run calibration during a period that reflects your typical operating conditions — not in an empty room if the space is usually busy.
Use representative device types
Use representative device types
Different hardware (phones, smartwatches, fitness trackers) broadcasts at different power levels. Include at least one device of each type you expect to count.
Run multiple calibration passes
Run multiple calibration passes
A single 20-second run may not capture enough variation. Run the tool two or three times at different times of day and average the recommended thresholds.
Walls and obstructions matter
Walls and obstructions matter
A wall between the Raspberry Pi and a device can drop RSSI by 10–20 dBm. Calibrate with the Pi in its final mounted position and with the room in its normal state.
No devices detected?
No devices detected?
If the summary shows zero unique devices, check that:
- The Bluetooth service is running:
sudo systemctl status bluetooth - At least one BLE-capable device (smartwatch, fitness tracker, wireless earphones) is nearby and actively broadcasting
- Smartphone Bluetooth is enabled — note that many phones do not emit BLE advertisements unless an app is actively using Bluetooth