Real-time monitoring of indoor temperature and humidity with Raspberry Pi
1. Material preparation:
DHT11温湿度传感器
树莓派
杜邦线
2. Sensor wiring:
GND:连接树莓派6号引脚(grand)
VCC:连接树莓派1号引脚(3.3V)
DATA:连接树莓派2的3号引脚(GPIO2)
Three, write the main program
sudo mkdir dht11
cd dht11
sudo nano wendu.py
Send [program] via official account to get
Write the program, ctrl x save and exit
Fourth, configure onenet
Click on Developer Center
Create a new product
After creating it,
remember the key
Click on the device management on the left to add a device
Remember the device id after adding
Click on the data flow template on the left, add temp and hum
Click on Application Management on the left
Click create app
Click to edit
Select two line graphs, you can edit the line graphs on the right, select the device you just added, and select the data stream temperature temp humidity select hum
After making changes, click save
Five, write temperature data program
sudo nano tmp.py
Code written in the document
Note: Replace the position of the red circle with the key and device ID that you just remembered
Save and exit after writing
6. Write and upload humidity data code
sudo nano hum.py
Code written in the document
Same as above to change the key and device ID in the code
Write to save and exit
Seven, set automatic execution
sudo crontab -e
Click 2
Write the following code at the end
*/1 * * * * python /home/pi/dht11/tmp.py
*/1 * * * * python /home/pi/dht11/hum.py
*/1 * * * * python /home/pi/dht11/wendu.py
Save and exit after writing
Eight, click on onenet device management
In your device, you can see the application you just set up, click to see the temperature and humidity data