Skip to content
This repository has been archived by the owner on May 12, 2022. It is now read-only.

Commit

Permalink
Merge pull request #35
Browse files Browse the repository at this point in the history
Incorporate DHT changes for stability
  • Loading branch information
MrYsLab authored May 30, 2021
2 parents 080493d + 4d05fcb commit 15f4eea
Show file tree
Hide file tree
Showing 7 changed files with 202 additions and 261 deletions.
61 changes: 46 additions & 15 deletions examples/dht.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,17 @@ def the_callback(data):
This will print the pin number, its reported value and
the date and time when the change occurred
:param data: [pin, current reported value, pin_mode, timestamp]
:param data: [report_type, pin, dht_type, error_value,
humidity, temperature, timestamp]
"""

tlist = time.localtime(data[5])
ftime = f'{tlist.tm_year}-{tlist.tm_mon:02}-{tlist.tm_mday:02} ' \
f'{tlist.tm_hour:02}:{tlist.tm_min:0}:{tlist.tm_sec:02}'
if not data[3]:
tlist = time.localtime(data[6])
ftime = f'{tlist.tm_year}-{tlist.tm_mon:02}-{tlist.tm_mday:02} ' \
f'{tlist.tm_hour:02}:{tlist.tm_min:0}:{tlist.tm_sec:02}'

print(f'Pin: {data[1]} DHT Type: {data[2]} Humidity:{data[3]}, '
f'Temperature: {data[4]} Timestamp: {ftime}')
print(f'Pin: {data[1]} DHT Type: {data[2]} Humidity:{data[4]}, '
f'Temperature: {data[5]} Timestamp: {ftime}')


def dht(my_board, callback=None):
Expand All @@ -63,36 +65,65 @@ def dht(my_board, callback=None):
"""

# set the pin mode - for pin 6 differential is set explicitly
my_board.set_pin_mode_dht(6, sensor_type=22, differential=.01, callback=callback)
my_board.set_pin_mode_dht(7, sensor_type=11, callback=callback)
my_board.set_pin_mode_dht(8, sensor_type=11, differential=.05, callback=callback)
my_board.set_pin_mode_dht(9, sensor_type=22, differential=.05, callback=callback)

my_board.set_pin_mode_dht(10, sensor_type=22, differential=.05, callback=callback)
my_board.set_pin_mode_dht(11, sensor_type=11, differential=.05, callback=callback)

# a flag to change the differential value after the first 5 seconds
changed = False
while True:
try:
time.sleep(POLL_TIME)

# poll the first DHT
value = board.dht_read(6)
# poll the first dht
value = board.dht_read(8)

# format the time string and then print the data
tlist = time.localtime(value[2])
ftime = f'{tlist.tm_year}-{tlist.tm_mon:02}-{tlist.tm_mday:02} ' \
f'{tlist.tm_hour:02}:{tlist.tm_min:0}:{tlist.tm_sec:02}'
print(f'poll pin 6: humidity={value[0]} temp={value[1]} '
print(f'poll pin 8: humidity={value[0]} temp={value[1]} '
f'time of last report: {ftime}')

# poll the second DHT and print the values
value = board.dht_read(7)
value = board.dht_read(9)
tlist = time.localtime(value[2])
ftime = f'{tlist.tm_year}-{tlist.tm_mon:02}-{tlist.tm_mday:02} ' \
f'{tlist.tm_hour:02}:{tlist.tm_min:0}:{tlist.tm_sec:02}'
print(f'poll pin 7: humidity={value[0]} temp={value[1]} '
print(f'poll pin 9: humidity={value[0]} temp={value[1]} '
f'time of last report: {ftime}')

# poll the third dht

value = board.dht_read(10)

# format the time string and then print the data
tlist = time.localtime(value[2])
ftime = f'{tlist.tm_year}-{tlist.tm_mon:02}-{tlist.tm_mday:02} ' \
f'{tlist.tm_hour:02}:{tlist.tm_min:0}:{tlist.tm_sec:02}'
print(f'poll pin 10: humidity={value[0]} temp={value[1]} '
f'time of last report: {ftime}')

# poll the fourth DHT
value = board.dht_read(11)
tlist = time.localtime(value[2])
ftime = f'{tlist.tm_year}-{tlist.tm_mon:02}-{tlist.tm_mday:02} ' \
f'{tlist.tm_hour:02}:{tlist.tm_min:0}:{tlist.tm_sec:02}'
print(f'poll pin 11: humidity={value[0]} temp={value[1]} '
f'time of last report: {ftime}')
if not changed:
# explicitly change the differential values
my_board.set_pin_mode_dht(6, sensor_type=22, differential=20.0, callback=callback)
my_board.set_pin_mode_dht(7, sensor_type=11, differential=2.0, callback=callback)

my_board.set_pin_mode_dht(8, sensor_type=11, differential=2.0,
callback=callback)
my_board.set_pin_mode_dht(9, sensor_type=22, differential=20.0,
callback=callback)
my_board.set_pin_mode_dht(10, sensor_type=22, differential=20.0,
callback=callback)
my_board.set_pin_mode_dht(11, sensor_type=11, differential=2.0,
callback=callback)
changed = True
except KeyboardInterrupt:
board.shutdown()
Expand Down
Loading

0 comments on commit 15f4eea

Please sign in to comment.