Filip Stefaniak Uses ESP32s, Raspberry Pis, BLE Beacons, and Machine Learning to Find His Cats

By leaning on machine learning, Stefaniak has been able to track his pets to any room of the house without the need for a receiver per room.

Organic chemist Filip Stefaniak has turned to machine learning for his latest project, a system for localizing a pet cat within a property using a wearable Bluetooth Low Energy beacon, Espressif ESP32 microcontrollers, Raspberry Pi single-board computers, and some clever coding to reduce the hardware bill.

"This is an overview of a pipeline for creating an in-house cat locator. Actually, it can be applied to any animal (including humans) or object, and any building," Stefaniak explains. "The system works as follows: The cat, [equipped] with a small BLE beacon, is emitting BLE signals; BLE signal is detected by ESP32s located here and there; they are measuring the signal strength of the BLE beacon."

"Each ESP32 sends data to the server (database). The python program is fetching the last measurements from all ESP32 detectors (i.e., signal strength values). Using trained machine learning models it predicts the location of the cat. The challenge here is to use a number of detectors which is significantly lower than the number of rooms and make ML [machine learning] do the rest."

The BLE beacon used in Stefaniak's project is a simple NotiOne button, without any of its extra functionality being used. Four ESP32 development boards act as the receiving units, though Stefaniak notes that Raspberry Pi single-board computers with built-in radios can also be used but that this approach "has not been thoroughly tested." Finally, a desktop computer β€” a Raspberry Pi "should also be good" β€” does the data processing, but could theoretically be replaced with a TinyML implementation running on the microcontrollers themselves.

Stefaniak trained the machine learning system with measurements taken in each room of the house - four primary rooms and two bathrooms - for received signal strength at each of the four reception nodes. 75 percent of the dataset was used for training, and 25 percent reserved as test data. The result: A balanced accuracy, following a little engineering, of 0.88.

"After some time of collecting the localization data for objects, we may create another ML model for predicting the localization of [the] object in time (i.e., if it is Monday morning, the cat is near the fridge, if it is Saturday afternoon, the cat is sleeping in the bathroom, etc)," Stefaniak suggests for further development. "This could involve another variables, like room temperature, humidity etc."

The source code for the project has been published to GitHub under the GNU General Public License 3.0.

Gareth Halfacree
Freelance journalist, technical author, hacker, tinkerer, erstwhile sysadmin. For hire: freelance@halfacree.co.uk.
Related articles
Sponsored articles
Related articles