Hello all I am looking for help with a simple python3 code that I am using for taking dht22 sensor readings and logging them for influxdb and grafana (works great by the way), My problem is that the code will run for a random amount of time then just stops, Im sure its from a dht read error but I need it to keep running regardless of a read error. If someone could take my code and fix it (show me where or whats missing) I would be much appreciative :)
import time import logging import Adafruit_DHT as adht logging.basicConfig(filename='temperature.log', filemode='a', format='%(created)f %(message)s', level=logging.INFO) try: while True: h,t = adht.read_retry(adht.DHT22, 23) logging.info('Temp={0:0.1f} C and Humidity={1:0.1f} %'.format(t, h)) # Wait for * seconds print("Waiting for 60 seconds… Sensor 0") time.sleep(60) else: print("Failed to retrieve data from DHT22 sensor") print('------------------------------------') time.sleep(60) # Delay in seconds. except:KeyboardInterrupt pass
buran write Nov-15-2020, 05:01 PM:
Please, use proper tags when post code, traceback, output, etc. This time I have added tags for you.
See BBcode help for more info.
Please, use proper tags when post code, traceback, output, etc. This time I have added tags for you.
See BBcode help for more info.