This page covers the problems most commonly encountered when deploying and operating the BLE People Counter. Each section describes the symptom, the likely cause, and the steps to resolve it.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.
BLE scanner finds no devices
BLE scanner finds no devices
No devices detected in this scan on every cycle.Likely causes:- The Bluetooth adapter is off or not recognized by the OS.
- The
cap_net_rawandcap_net_admincapabilities were not applied to the Python binary. - The
bluetoothsystem service is not running.
Verify the adapter is up
UP RUNNING. If the adapter is missing or DOWN, try:Re-apply BLE capabilities
install.sh script sets the required capabilities on the virtual-environment Python binary. If the venv was recreated or updated, run this command again:ImportError: Bleak not installed
ImportError: Bleak not installed
Pi can't connect to the MQTT broker
Pi can't connect to the MQTT broker
Sin broker MQTT configurado, se usará MockMQTTClient (simulado) or connection refused errors.Cause: The MQTT_BROKER variable is not set, is set to the default placeholder broker.emqx.io, or the broker is unreachable from the Pi’s network.The agent checks for this condition explicitly:- Set
MQTT_BROKERin.envto your broker’s hostname or IP address. - Set
MQTT_USERNAMEandMQTT_PASSWORDif your broker requires authentication. - Confirm the Pi can reach the broker:
- Check that port 1883 (or your configured
MQTT_PORT) is open:
Pi can't connect to the HTTP backend
Pi can't connect to the HTTP backend
No se pudo conectar al backend, entrando en modo offline or HTTP connection errors in the log file.Cause: HTTP_BASE_URL is wrong, the backend is not running, or a firewall is blocking the connection.Resolution:Verify the URL in .env
https://your-backend.fly.dev. No trailing slash.Check the API key
HTTP_API_KEY in .env to the same value as API_KEY on the backend. A 401 response from the health check suggests a key mismatch.Backend won't start
Backend won't start
docker compose up exits immediately or the backend container restarts in a loop.Cause: Most often the database is not ready yet, or DATABASE_URL is misconfigured.Resolution:Verify the database is healthy
docker-compose.yml uses a healthcheck so the backend waits for Postgres:POSTGRES_USER / POSTGRES_PASSWORD / POSTGRES_DB environment variables.Alembic migration errors
Alembic migration errors
alembic, revision, or missing database columns.Cause: The database schema is out of date or migrations have not been applied.Resolution:Frontend shows 'Error al cargar datos'
Frontend shows 'Error al cargar datos'
VITE_API_URLis not set or points to the wrong URL.- The backend is returning CORS errors because the frontend’s origin is not in the allowed list.
- The backend is down.
Check the API URL environment variable
VITE_API_URL is set to the full backend URL (e.g., https://your-backend.fly.dev). After changing environment variables in Vercel, redeploy.Inspect the browser console
cors_origins in backend-cloud/src/config.py and redeploy the backend.WebSocket not connecting
WebSocket not connecting
ws:// instead of wss:// for HTTPS frontends), CORS restrictions on the WebSocket upgrade, or the backend port is not reachable.Resolution:- Frontends served over HTTPS must use
wss://for WebSocket connections. Aws://URL will be blocked by the browser. - Confirm
WEBSOCKET_ENABLEDistrueon the backend (it is the default). - The Fly.io configuration forces HTTPS and forwards WebSocket upgrades automatically. If using Docker Compose behind a reverse proxy (nginx, Caddy), ensure the proxy passes the
UpgradeandConnectionheaders. - Check the browser Network tab → WS tab for the exact error code and message.
Estimated people count seems wrong
Estimated people count seems wrong
DEVICES_PER_PERSON ratio does not match actual device density, or MAC randomization is inflating counts.Resolution:Run the calibration script
calibrate_ble.py in the actual deployment space with a known number of people:Update thresholds via the API
systemd service keeps restarting
systemd service keeps restarting
systemctl status ble-scanner shows the service repeatedly entering activating and failed states. The restart counter climbs.Cause: A fatal error at startup — most commonly a configuration error in .env, a missing Python dependency, or a permissions problem.Resolution:Follow the service logs
Check .env for required variables
sys.exit(1) if DEVICE_ID is missing or COMMUNICATION_MODE is invalid:Run the agent manually to reproduce the error