vitormhenrique / OctoPrint-Enclosure

OctoPrint Enclosure Plugin
GNU General Public License v3.0
395 stars 201 forks source link

Retry when DHT temp sensor read fails #455

Closed markleary closed 2 years ago

markleary commented 2 years ago

DHT sensor reads fail fairly often, causing the enclosure plugin to report a value of 0. When this happens, octoprint logs the exception:

Traceback (most recent call last):
  File "/home/pi/oprint/lib/python3.7/site-packages/octoprint_enclosure/getDHTTemp.py", line 19, in <module>
     humidity = dht_dev.humidity
  File "/home/pi/.local/lib/python3.7/site-packages/adafruit_dht.py", line 284, in humidity
     self.measure()
  File "/home/pi/.local/lib/python3.7/site-packages/adafruit_dht.py", line 230, in measure
    raise RuntimeError("A full buffer was not returned. Try again.")
RuntimeError: A full buffer was not returned. Try again.

This seem to be a well known issue, the adafruit_dht docs recommend catching the failed read exception and retrying. I no longer get false 0 degree readings with this change.

mattia952 commented 2 months ago

the error are in python script getDHTTemp.py in octoprint_enclosure directory! maybe adafruit_dht library change from last review. for fixing i this dictionary:

'5': board.D5 '6': board.D6 '7': board.D7 '8': board.D8 '9': board.D9 '10': board.D10 '11': board.D11 '12': board.D12 '13': board.D13 '14': board.D14 '15': board.D15 '16': board.D16 '17': board.D17 '18': board.D18 '19': board.D19 '20': board.D20 '21': board.D21 '22': board.D22 '23': board.D23 '24': board.D24 '25': board.D25 '26': board.D26 '27': board.D27

and define pin = board_pin[sys.argv[2]]

now the line: dht_dev = sensor(pin) works correctly