Is your cat always elusive at home, driving you crazy? Don’t worry! Today, we will unveil a powerful cat localization system based on BLE beacons, ESP32, and machine learning—Cat-Localizer! It can help you track your cat’s location in real-time, putting an end to the troubles of “cat searching”!
How Cat-Localizer Works
The core idea of Cat-Localizer is to utilize low-energy Bluetooth (BLE) beacons, multiple inexpensive ESP32 detectors, and a machine learning model to achieve indoor cat localization. The workflow of the entire system is as follows:
- Beacon Emission: Attach a small BLE beacon to your cat, which will continuously emit BLE signals.
- Signal Detection: ESP32 detectors placed at different locations in the house will receive these BLE signals and measure the signal strength (RSSI).
- Data Upload: Each ESP32 will send the measured RSSI data to the server database.
- Location Prediction: A Python program retrieves the latest RSSI data from all ESP32 detectors in the database and uses a trained machine learning model to predict the cat’s location.
Highlights: The advantage of Cat-Localizer is that it requires a relatively small number of detectors to accurately predict the cat’s location through the machine learning model, even in complex house structures.
Hardware Setup
- Target to be Tracked: A cat (or dog, other animals, or even objects).
- BLE Beacon: Any BLE beacon can be used.
- BLE Detectors: It is recommended to use 4-6 ESP32s, which are inexpensive and perform well. Raspberry Pi can also be used, but it is more costly.
- Data Processing Server: A computer or Raspberry Pi can be used to store and process data and run the prediction program. Ensure that the ESP32 can connect to the server’s WiFi network.
- Optional: A device with an LCD display can be used to show the cat’s location in real-time.
Software Setup
- BLE Beacon: No configuration or code is required.
- ESP32 Detectors: The project provides simple C/Arduino code for scanning BLE signals and sending data to the server. The code can be adjusted and optimized as needed, such as adding multiple MAC address filtering features.
- Raspberry Pi (Optional): If using Raspberry Pi as a detector, you can use
<span>btmon</span>
and<span>hcitool lescan</span>
commands for BLE scanning and send data to the database. - Server:
- Database: You can use InfluxDB, MySQL, or even simple text files as a database.
- Python Environment: It is recommended to use Python 3.8 and install libraries such as scikit-learn and pandas. The project provides a conda environment file to facilitate setting up the same environment, ensuring consistency in model training and prediction.
- Prediction Program: The Python program is responsible for retrieving data from the database and using the trained model for location prediction.
Training and Testing the Machine Learning Model
-
Data Collection: It is necessary to collect RSSI data from each ESP32 detector at different locations and record the actual position of the beacon at that time. This data will be used to train the machine learning model. The data table is similar to:
<span>measurement id, time, target, esp32-attic, esp32-room_k, esp32-office, esp32-doors</span>
, where each row represents a measurement result. -
Model Training and Evaluation: The project uses various machine learning algorithms (such as Multi-Layer Perceptron Classifier) and data preprocessing methods (such as Min-Max Scaler) and evaluates their performance through cross-validation. The best-performing model is selected for deployment.
-
Model Results: Experimental results show that the MLP classifier combined with Min-Max Scaler achieved the best balanced accuracy (approximately 0.88).
Location Detection
The project provides code snippets for location detection, which can read data from the database or files and then use the trained model for prediction.
Tips for Improving Accuracy
- Optimize the placement of ESP32 detectors to cover the entire space and obtain unique signal patterns.
- Optimize machine learning algorithms and parameters.
- Increase the number of ESP32 detectors.
- Consider the battery level of the BLE beacon, as it may affect the transmission power.
Conclusion
Cat-Localizer provides a flexible and powerful framework for building an indoor cat localization system. Although it requires some hands-on skills and programming knowledge, its powerful features and relatively low cost make it a project worth trying. By carefully configuring the hardware, collecting sufficient data, and selecting the appropriate machine learning model, you can establish an accurate and practical cat localization system, making your cat searching journey easy and enjoyable!
Project Address:https://github.com/filipsPL/cat-localizer