Timing and Formatadaptions

This commit is contained in:
Dirk Alders 2021-10-13 08:53:50 +02:00
parent afedf43bdf
commit 6ab2629fb1
2 changed files with 155 additions and 155 deletions

6
bmp.py
View File

@ -20,7 +20,7 @@ else:
class bmp_180(background_task): class bmp_180(background_task):
RUN_SLEEP_TIME = 0.5 RUN_SLEEP_TIME = 2.0
SMBUS_DELAY = 0.5 SMBUS_DELAY = 0.5
MIN_REFRESH_RATE = RUN_SLEEP_TIME + 3 * SMBUS_DELAY MIN_REFRESH_RATE = RUN_SLEEP_TIME + 3 * SMBUS_DELAY
KEY_TEMPERATURE = 'temperature' KEY_TEMPERATURE = 'temperature'
@ -35,9 +35,11 @@ class bmp_180(background_task):
def __run__(self): def __run__(self):
data = self.__bmp_data_transmission__() data = self.__bmp_data_transmission__()
if data is not None: if data is not None:
logger.debug('BMP-Communication: Successfully: %s', repr(data)) logger.info('BMP-Communication successful: %s', repr(data))
if self.__data_callback__ is not None: if self.__data_callback__ is not None:
self.__data_callback__(**data) self.__data_callback__(**data)
else:
logger.debug('BMP-Communication failed: No data received')
def __bmp_data_transmission__(self): def __bmp_data_transmission__(self):
if not DEBUG: if not DEBUG:

12
dht.py
View File

@ -19,7 +19,7 @@ else:
from . import DEBUG from . import DEBUG
class dht_22(background_task): class dht_22(background_task):
RUN_SLEEP_TIME = 2.0 RUN_SLEEP_TIME = 4.0
MIN_REFRESH_RATE = RUN_SLEEP_TIME MIN_REFRESH_RATE = RUN_SLEEP_TIME
KEY_TEMPERATURE = 'temperature' KEY_TEMPERATURE = 'temperature'
KEY_HUMIDITY = 'humidity' KEY_HUMIDITY = 'humidity'
@ -43,15 +43,15 @@ class dht_22(background_task):
# check data # check data
if self.__temp_monitor__.process(data[self.KEY_TEMPERATURE], data[self.KEY_TIME]) and self.__hum_monitor__.process(data[self.KEY_HUMIDITY], data[self.KEY_TIME]): if self.__temp_monitor__.process(data[self.KEY_TEMPERATURE], data[self.KEY_TIME]) and self.__hum_monitor__.process(data[self.KEY_HUMIDITY], data[self.KEY_TIME]):
# #
logger.debug('DHT-Communication: Successfully: %s', repr(data)) logger.info('DHT-Communication successful: %s', repr(data))
self.__monitor__.process(data) self.__monitor__.process(data)
if self.__data_callback__ is not None: if self.__data_callback__ is not None:
self.__data_callback__(**data) self.__data_callback__(**data)
if self.__monitor__.status(): if self.__monitor__.status():
logger.warning("DHT measurement stopped caused by too many identical values!") logger.warning("DHT-Communication failed: Measurement stopped caused by suspicious constant values!")
self.close() self.close()
else: else:
logger.warning("DHT-Gradient to high: Ignoring data %s!", repr(data)) logger.debug("DHT-Communication failed: Gradient to high. Ignoring data %s!", repr(data))
@ -69,7 +69,7 @@ class dht_22(background_task):
time.sleep(self.RUN_SLEEP_TIME) time.sleep(self.RUN_SLEEP_TIME)
except RuntimeError as error: except RuntimeError as error:
# Errors happen fairly often, DHT's are hard to read, just keep going # Errors happen fairly often, DHT's are hard to read, just keep going
logger.debug('DHT-Communication: ' + error.args[0]) logger.debug('DHT-Communication failed: ' + error.args[0])
time.sleep(2.0) time.sleep(2.0)
except Exception as error: except Exception as error:
self.__dht_device__.exit() self.__dht_device__.exit()
@ -127,8 +127,6 @@ class dht_22_monitor(object):
else: else:
self.__init_statevars__() self.__init_statevars__()
if self.__max_const_measurements__ > self.__max_const_treshold__: if self.__max_const_measurements__ > self.__max_const_treshold__:
if not self.__fail__:
logger.warning("DHT measurement values are suspicious constant!")
self.__fail__ = True self.__fail__ = True
def status(self): def status(self):