-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.py
More file actions
31 lines (25 loc) · 875 Bytes
/
run.py
File metadata and controls
31 lines (25 loc) · 875 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import sys
import time
from dht_reader.dht_reader import DHTReader
# Check if the correct number of arguments is provided
if len(sys.argv) != 5:
print('Usage: python run.py <dht_type> <chip_path> <line_offset> <sensor_reading_delay>')
sys.exit(1)
# DHT sensor type
dht_type = sys.argv[1]
# Path to the GPIO chip
chip_path = sys.argv[2]
# Offset of the GPIO line
line_offset = int(sys.argv[3])
# Delay between sensor readings in seconds
sensor_reading_delay = float(sys.argv[4])
dht_reader = DHTReader(dht_type, chip_path, line_offset)
while True:
try:
# Read sensor data
humidity, temperature_c, temperature_f = dht_reader.read_data()
print(f'Humidity: {humidity:.1f}% Temperature: {temperature_c:.1f}°C {temperature_f:.1f}°F')
except Exception as e:
print(str(e))
finally:
time.sleep(sensor_reading_delay)