別人的專題。
- 顯示目前觀測數值
- 每 30 分鐘自動記錄數值
- Raspberry Pi
- DHT11/ DHT22
- Python 3.7 and above
-
Install
sudo apt update sudo apt install mariadb-server
-
Login to MariaDB (Default password is your RPi's password)
sudo mysql -u root -p
-
Create a user for this project
CREATE USER 'dht22'@'localhost' IDENTIFIED BY 'password';
-
Create DATABASE
CREATE DATABASE dht22 CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_unicode_ci';
-
Permission 777, wow
GRANT ALL PRIVILEGES ON dht22.* TO 'dht22'@'localhost'; FLUSH PRIVILEGES;
-
Create TABLE
// Switch to database use dht22; // Create table CREATE TABLE `history` ( `id` INT NOT NULL AUTO_INCREMENT, `time` DATETIME NOT NULL, `temp` INT NOT NULL, `hum` INT NOT NULL, `dirtHum` INT NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB; // Modify time col ALTER TABLE `history` MODIFY `time` datetime DEFAULT CURRENT_TIMESTAMP
-
Install dependencies
pip install -r requirements.txt or pip3 install -r requirements.txt
-
Start the server
python main.py or python3 main.py