This project logs temperature and humidity data from a AHT20 (or AM2301B) sensor connected to a Raspberry Pi and stores the data in a MariaDB database. The data is collected every 10 minutes using a cron job.
- Raspberry Pi with I²C enabled
- Python 3.7+
- Virtual environment (
venv
) - MariaDB server
- Required Python packages:
adafruit-circuitpython-ahtx0
pymysql
- Clone the Repository
git clone https://github.com/magoulet/temperature-logger.git
cd temperature-logger
- Create and Activate a Virtual Environment
python3 -m venv .venv
source .venv/bin/activate
- Install Required Packages
pip install adafruit-circuitpython-ahtx0 pymysql
Copy config.py.example
to config.py
and update according to your needs.
- Create the Shell Script
Copy run_script.sh.example
to run_script.sh
and update according to your setup details.
- Make the Shell Script Executable
chmod +x run_script.sh
- Test the Script Manually
run_script.sh
- Open the crontab configuration:
crontab -e
- Add the following line to run the script every 10 minutes:
*/10 * * * * /home/user/projects/temperature-logger/run_script.sh | logger -t temperature-logger
making sure to update the path based on your local setup.
- View logs:
journalctl -t temperature-logger
- Follow logs in real-time:
journalctl -t temperature-logger -f
- View logs:
grep "temperature-logger" /var/log/syslog
- Follow logs in real-time:
tail -f /var/log/syslog | grep "temperature-logger"
This project is licensed under the MIT License.