MCPcopy Create free account
hub / github.com/antirez/freakwan / send_sample_dht22

Method send_sample_dht22

sensor.py:73–98  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

71 return encoded
72
73 def send_sample_dht22(self):
74 d = dht.DHT22(Pin(self.config['dht_pin']))
75 temp = 0
76 hum = 0
77 numtry = 0
78
79 # Sometimes the DHT22 may return a timeout error.
80 # If we run into the error multiple times, send a 0/0
81 # reading to notify that the sensor is damaged.
82 while numtry < 3 and temp == 0 and hum == 0:
83 numtry += 1
84 try:
85 d.measure()
86 temp = d.temperature()
87 hum = d.humidity()
88 except:
89 pass
90
91 data = self.encode_data({
92 MessageSensorDataTemperature: temp,
93 MessageSensorDataAirHumidity: hum
94 })
95 msg = Message(flags=MessageFlagsMedia,nick=self.fw.config['nick'],media_type=MessageMediaTypeSensorData,media_data=data,key_name=self.config['key_name'])
96 self.fw.send_asynchronously(msg,max_delay=0,num_tx=1,relay=True)
97 self.fw.scroller.print("you> T:%.2f, H:%.2f" % (d.temperature(),d.humidity()))
98 self.fw.refresh_view()

Callers 1

send_sampleMethod · 0.95

Calls 5

encode_dataMethod · 0.95
MessageClass · 0.85
send_asynchronouslyMethod · 0.80
refresh_viewMethod · 0.80
printMethod · 0.45

Tested by

no test coverage detected