def loop_dht(o):
global d
global oled
global CLIENT_ID
global client
global a1
global a2
global a3
delay = o
topic = 'micro/{0}/temperature'.format(CLIENT_ID.decode("utf-8"))
while True:
try:
d.measure()
oled.fill(0)
soils = [{'id': 1, 'value': read_soil(a1)},
{'id': 2, 'value': read_soil(a2)},
{'id': 3, 'value': read_soil(a3)}]
oled.text('SOIL SENSOR', 20, 5)
oled.text('T: {0:.1f}C,{1:.1f}%'.format(d.temperature(), d.humidity()), 3, 20)
oled.text('A1:{0} A2:{1}'.format(soils[0]['value']['msg'],soils[1]['value']['msg']), 3, 35)
oled.text('A3:{0}'.format(soils[2]['value']['msg']), 3, 50)
oled.show()
msg = json.dumps({
'Id': CLIENT_ID,
'heap': gc.mem_free(),
'temperature': '{0:.2f}'.format(d.temperature()),
'humidity': '{0:.2f}'.format(d.humidity()),
'soils': soils
})
print(msg)
client.publish(topic, msg)
except OSError as e:
if e.args[0] == errno.ETIMEDOUT:
print('error dht: ', e)
time.sleep(delay)
评论列表
文章目录