A low-cost BLE-based distance estimation, occupancy detection and counting system