@@ -41,15 +41,17 @@ def the_callback(data):
4141 This will print the pin number, its reported value and
4242 the date and time when the change occurred
4343
44- :param data: [pin, current reported value, pin_mode, timestamp]
44+ :param data: [report_type, pin, dht_type, error_value,
45+ humidity, temperature, timestamp]
4546 """
4647
47- tlist = time .localtime (data [5 ])
48- ftime = f'{ tlist .tm_year } -{ tlist .tm_mon :02} -{ tlist .tm_mday :02} ' \
49- f'{ tlist .tm_hour :02} :{ tlist .tm_min :0} :{ tlist .tm_sec :02} '
48+ if not data [3 ]:
49+ tlist = time .localtime (data [6 ])
50+ ftime = f'{ tlist .tm_year } -{ tlist .tm_mon :02} -{ tlist .tm_mday :02} ' \
51+ f'{ tlist .tm_hour :02} :{ tlist .tm_min :0} :{ tlist .tm_sec :02} '
5052
51- print (f'Pin: { data [1 ]} DHT Type: { data [2 ]} Humidity:{ data [3 ]} , '
52- f'Temperature: { data [4 ]} Timestamp: { ftime } ' )
53+ print (f'Pin: { data [1 ]} DHT Type: { data [2 ]} Humidity:{ data [4 ]} , '
54+ f'Temperature: { data [5 ]} Timestamp: { ftime } ' )
5355
5456
5557def dht (my_board , callback = None ):
@@ -63,36 +65,65 @@ def dht(my_board, callback=None):
6365 """
6466
6567 # set the pin mode - for pin 6 differential is set explicitly
66- my_board .set_pin_mode_dht (6 , sensor_type = 22 , differential = .01 , callback = callback )
67- my_board .set_pin_mode_dht (7 , sensor_type = 11 , callback = callback )
68+ my_board .set_pin_mode_dht (8 , sensor_type = 11 , differential = .05 , callback = callback )
69+ my_board .set_pin_mode_dht (9 , sensor_type = 22 , differential = .05 , callback = callback )
70+
71+ my_board .set_pin_mode_dht (10 , sensor_type = 22 , differential = .05 , callback = callback )
72+ my_board .set_pin_mode_dht (11 , sensor_type = 11 , differential = .05 , callback = callback )
6873
6974 # a flag to change the differential value after the first 5 seconds
7075 changed = False
7176 while True :
7277 try :
7378 time .sleep (POLL_TIME )
7479
75- # poll the first DHT
76- value = board .dht_read (6 )
80+ # poll the first dht
81+ value = board .dht_read (8 )
7782
7883 # format the time string and then print the data
7984 tlist = time .localtime (value [2 ])
8085 ftime = f'{ tlist .tm_year } -{ tlist .tm_mon :02} -{ tlist .tm_mday :02} ' \
8186 f'{ tlist .tm_hour :02} :{ tlist .tm_min :0} :{ tlist .tm_sec :02} '
82- print (f'poll pin 6 : humidity={ value [0 ]} temp={ value [1 ]} '
87+ print (f'poll pin 8 : humidity={ value [0 ]} temp={ value [1 ]} '
8388 f'time of last report: { ftime } ' )
8489
8590 # poll the second DHT and print the values
86- value = board .dht_read (7 )
91+ value = board .dht_read (9 )
8792 tlist = time .localtime (value [2 ])
8893 ftime = f'{ tlist .tm_year } -{ tlist .tm_mon :02} -{ tlist .tm_mday :02} ' \
8994 f'{ tlist .tm_hour :02} :{ tlist .tm_min :0} :{ tlist .tm_sec :02} '
90- print (f'poll pin 7: humidity={ value [0 ]} temp={ value [1 ]} '
95+ print (f'poll pin 9: humidity={ value [0 ]} temp={ value [1 ]} '
96+ f'time of last report: { ftime } ' )
97+
98+ # poll the third dht
99+
100+ value = board .dht_read (10 )
101+
102+ # format the time string and then print the data
103+ tlist = time .localtime (value [2 ])
104+ ftime = f'{ tlist .tm_year } -{ tlist .tm_mon :02} -{ tlist .tm_mday :02} ' \
105+ f'{ tlist .tm_hour :02} :{ tlist .tm_min :0} :{ tlist .tm_sec :02} '
106+ print (f'poll pin 10: humidity={ value [0 ]} temp={ value [1 ]} '
107+ f'time of last report: { ftime } ' )
108+
109+ # poll the fourth DHT
110+ value = board .dht_read (11 )
111+ tlist = time .localtime (value [2 ])
112+ ftime = f'{ tlist .tm_year } -{ tlist .tm_mon :02} -{ tlist .tm_mday :02} ' \
113+ f'{ tlist .tm_hour :02} :{ tlist .tm_min :0} :{ tlist .tm_sec :02} '
114+ print (f'poll pin 11: humidity={ value [0 ]} temp={ value [1 ]} '
91115 f'time of last report: { ftime } ' )
92116 if not changed :
93117 # explicitly change the differential values
94- my_board .set_pin_mode_dht (6 , sensor_type = 22 , differential = 20.0 , callback = callback )
95- my_board .set_pin_mode_dht (7 , sensor_type = 11 , differential = 2.0 , callback = callback )
118+
119+ my_board .set_pin_mode_dht (8 , sensor_type = 11 , differential = 2.0 ,
120+ callback = callback )
121+ my_board .set_pin_mode_dht (9 , sensor_type = 22 , differential = 20.0 ,
122+ callback = callback )
123+ my_board .set_pin_mode_dht (10 , sensor_type = 22 , differential = 20.0 ,
124+ callback = callback )
125+ my_board .set_pin_mode_dht (11 , sensor_type = 11 , differential = 2.0 ,
126+ callback = callback )
96127 changed = True
97128 except KeyboardInterrupt :
98129 board .shutdown ()
0 commit comments