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)

image-20201007225352711
Insert picture description here

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

Insert picture description here

Click on Developer Center

Create a new product

Insert picture description here
Insert picture description here

After creating it,
remember the key
Insert picture description here

Click on the device management on the left to add a device

image-20201007225430417

Remember the device id after adding

image-20201007225436413

Click on the data flow template on the left, add temp and hum

image-20201007225446349
Insert picture description here

Click on Application Management on the left

Click create app

Insert picture description here

Click to edit

Insert picture description here
Insert picture description here

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

Insert picture description here

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

Insert picture description here

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

Insert picture description here

Insert picture description here

Guess you like

Origin blog.csdn.net/qq_41676577/article/details/112856681