Log error when client probe takes a 185.0 reading

this indicates some power issue with the probe(s) and does not really mean
that's the temperature.  so we don't want the server to send out "high temp"
email etc. but rather just a technical error email

https://www.controlbyweb.com/support/faq/temp-sensor-reading-error.html
This commit is contained in:
Lance Edgar 2018-10-05 20:53:09 -05:00
parent 74de10e74c
commit 85e8ed9832

View file

@ -72,46 +72,60 @@ class TempmonClient(Daemon):
# main loop: take readings, pause, repeat # main loop: take readings, pause, repeat
while True: while True:
self.take_readings(client_uuid)
time.sleep(self.delay)
session = Session() def take_readings(self, client_uuid):
"""
Take new readings for all enabled probes on this client.
"""
session = Session()
try:
client = session.query(tempmon.Client).get(client_uuid)
self.delay = client.delay or 60
if client.enabled:
for probe in client.enabled_probes():
self.take_reading(session, probe)
except:
log.exception("Failed to read/record temperature data (but will keep trying)")
session.rollback()
else:
# make sure we show as being online
if not client.online:
client.online = True
try: try:
client = session.query(tempmon.Client).get(client_uuid) session.commit()
self.delay = client.delay or 60
if client.enabled:
for probe in client.enabled_probes():
self.take_reading(session, probe)
except: except:
log.exception("Failed to read/record temperature data (but will keep trying)") log.exception("Failed to read/record temperature data (but will keep trying)")
session.rollback() session.rollback()
else: finally:
# make sure we show as being online session.close()
if not client.online:
client.online = True
try:
session.commit()
except:
log.exception("Failed to read/record temperature data (but will keep trying)")
session.rollback()
finally:
session.close()
time.sleep(self.delay)
def take_reading(self, session, probe): def take_reading(self, session, probe):
""" """
Take a single reading and add to Rattail database. Take a single reading and add to Rattail database.
""" """
reading = tempmon.Reading() reading = tempmon.Reading()
reading.client = probe.client
reading.probe = probe
reading.degrees_f = self.read_temp(probe) reading.degrees_f = self.read_temp(probe)
reading.taken = datetime.datetime.utcnow()
session.add(reading) # a reading of 185.0 °F indicates some sort of power issue. when this
return reading # happens we log an error (which sends basic email) but do not record
# the temperature. that way the server doesn't see the 185.0 reading
# and send out a "false alarm" about the temperature being too high.
# https://www.controlbyweb.com/support/faq/temp-sensor-reading-error.html
if reading.degrees_f == 185.0:
log.error("got reading of 185.0 from probe: %s", probe.description)
else: # we have a good reading
reading.client = probe.client
reading.probe = probe
reading.taken = datetime.datetime.utcnow()
session.add(reading)
return reading
def read_temp(self, probe): def read_temp(self, probe):
""" """
@ -126,7 +140,9 @@ class TempmonClient(Daemon):
equals_pos = lines[1].find('t=') equals_pos = lines[1].find('t=')
if equals_pos != -1: if equals_pos != -1:
temp_string = lines[1][equals_pos+2:] temp_string = lines[1][equals_pos+2:]
# temperature data comes in as celsius
temp_c = float(temp_string) / 1000.0 temp_c = float(temp_string) / 1000.0
# convert celsius to fahrenheit
temp_f = temp_c * 9.0 / 5.0 + 32.0 temp_f = temp_c * 9.0 / 5.0 + 32.0
return round(temp_f,4) return round(temp_f,4)