I updated this project on 11.11.2019 so it uses sqlite and takes less space. Old version, using mysql is at : https://github.com/jarekj9/mitempjjv1
It will not work on RPI 1/zero due to architecture. I tested it on RPI 3B+, on fresh raspbian 10 buster install (full).
It works with "Mi Bluetooth Temperature & Humidity Monitor":
Project consists of 2 parts:
- Script poll_sensor.py, which reads data from sensor via bluetooth and writes data to sqlite database
- Docker container, that reads data from sqlite and presents interactive graphs in web browser:
INSTRUCTIONS:
1.Install docker:
sudo curl -sSL https://get.docker.com | sh
sudo apt-get install libffi-dev
sudo pip3 install docker-compose
sudo usermod -aG docker pi
logout
- Re-login to rpi and download project folder:
git clone https://github.com/jarekj9/mitempjj.git
cd mitempjj
- Create image and run container:
docker-compose up -d
Check with command 'docker ps' if container is running.
- Install additional python3 packages:
sudo pip3 install -r requirements.txt
- Check xiaomi sensor MAC address and add it to file:
sudo blescan
(The MAC should have description like: Complete Local Name: 'MJ_HT_V1'
Edit this mac in file:
mac-address.txt
- If you use firewall, allow connections to rpi on tcp port 8083
Simple example:
firewall-cmd --add-port=8083/tcp --permanent
systemctl restart firewalld
- Running script 'poll_sensor.py' will save sensor data to sqlite DB. This will add it to crontab so it runs every 10 minutes (just replace '/your_path'):
(crontab -l 2>/dev/null; echo "*/10 * * * * cd /your_path && python3 /your_path/poll_sensor.py") | crontab -
View data on http://<raspberry pi IP>:8083/temperature_sensor/
Simple Schema:
+--------------+ +----------------------+
| | | |
| MI SENSOR | | PC with www browser |
| | | |
+-------+------+ +------------+---------+
| |
| |
| |
| |
| |192.168.X.X:8083
+------------------+Raspberry PI+--------------------+
| | | |
| v ++docker container+------+ |
| +-----+----+ | | | |
| | polling | | +--------------+----+ | |
| | script | | | www server(django)| | |
| | | | | port 8083 | | |
| +---------++ | | | | |
| | | +-----+-------------+ | |
| | | | | |
| | | | | |
| v | v | |
| ++------------+--------+--+ | |
| | shared volume: | | |
| | database/mitepjjj.db | | |
| | (sqlite) | | |
| +-------------+-----------+ | |
| | | |
| +------------------------+ |
+----------------------------------------------------+
v2 11.11.2019