
Simple Raspberry Pi Temperature tracker for my room. Backend is a python script that stores the temperature from a dht22 sensor in a MySQL database (stores 1,440 mesurements per day). Runs every minute via a cronjob.
- Raspberry Pi
- dht22 sensor
- python3
- adafruit-python-shell - https://github.com/adafruit/Adafruit_Python_Shell
- Adafruit_CircuitPython_DHT - https://github.com/adafruit/Adafruit_CircuitPython_DHT
- PyMySQL - https://github.com/PyMySQL/PyMySQL
The database this project uses is MySQL with python integration via PyMySQL. The table name that you push data to can be configured in the config file. The table should be created with the followingbut can be created how you wish. Just note that you might need to change definitions in database.py to suite your needs.
CREATE TABLE `newtable` (
`dateunix` varchar(64) NOT NULL,
`datestr` DATETIME NOT NULL,
`temperature` DECIMAL(6,1) NOT NULL,
`humidity` VARCHAR(8) NOT NULL
);
- host - The hostname/address of your MySQL server
- database - The database that your table resides in
- table - The table name that you want to store your data
- user - Login account for MySQL, should have access to the above database + table
- password - The password for the login account
[Database]
host = localhost
database = yourdatabase
table = yourtable
user = youruser
password = userpasswordFor debugging, you can directly run the tracker.py script with the following. Make sure to include --config and point to your config.ini file.
python3 ./tracker.py --config="/path/to/config.ini"I use a cronjob to run the script every minute. That's done with the following crontab -e entry. Make sure to setup the cronjob as root else our script won't have access to GPIO.
* * * * * cd /home/steffan/TemperatureTracker && /usr/bin/python3.11 ./tracker.py --config="./config.ini" 2>&1
made by steffan
❤️