How many people are in my living room?
November 7, 2024I'm currently living in a community house (Newspeak House) that hosts hundreds of people each week in the event hall, and dozens of people for smaller gatherings in the living room and coworking space.
We have several monitors mounted on the walls inherited from previous residents, so I was inspired to put them to use by approximating and displaying how many people were in the space at any given time over the last ~48 hours.
Here's what I used:
- A Raspberry Pi Zero 2 W plugged in to the back of a monitor
- bluepy - Python package to access Bluetooth Low Energy (BLE) devices - ie the one on the Pi
- Bluetooth Company Identifiers - a csv matching a Bluetooth SIG number (broadcast by most devices) to a vendor. I used this to tell apart iPhones, PCs, Androids, by manufacturer
- A Flask server showing the chart, made with Matplotlib
- Epiphany browser to show the webpage with the limited memory on the Pi
Every 60 seconds, the Pi scans for visible Bluetooth devices for 30 seconds (some devices are only visible for intermittent periods, so I made the scanning window large), then deduplicates based on MAC address (this also seems to change, so it's not foolproof). It logs all of that in a csv file.
A second script then aggregates the device count, does some adjustments (basically fudging factors I experimented with to try to go from number of devices to number of people), and then plots it using Matplotlib on a simple Flask webpage.