summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Lamparter <equinox@diac24.net>2016-10-10 23:32:26 +0000
committerroot <root@beaglebone.local.sublab.org>2016-10-10 23:32:26 +0000
commita78cca8863b3c84569ba2776433ffdee471ff2ef (patch)
treea5c0043960efb6b6f9fdb4f4a1c81919809766dc
parent0591adffc658d9e5a7b47feb59282b2505a32209 (diff)
envmon: simplify after onewire problem is fixed
onewire had a kernel bug in managing bus power...
-rw-r--r--envmon/onewire-sysfs.py21
-rwxr-xr-xenvmon/onewire2graphite.py32
2 files changed, 20 insertions, 33 deletions
diff --git a/envmon/onewire-sysfs.py b/envmon/onewire-sysfs.py
index d889768..f42afee 100644
--- a/envmon/onewire-sysfs.py
+++ b/envmon/onewire-sysfs.py
@@ -32,8 +32,6 @@ class SensorFacade(object):
def __init__(self, addr, name):
self._addr = addr
self._name = name
- self._cached = None
- self._cachets = None
self._backoff = None
def _path(self):
@@ -62,33 +60,22 @@ class SensorFacade(object):
@property
def temperature(self):
- if self._cachets > time.time() - 50:
- return self._cached
if self._backoff > time.time():
- if self._cachets > time.time() - 250:
- return self._cached
return None
try:
rv = self.get_temperature()
if rv > 65 or rv < -25:
raise OutOfRange, (self._path(), rv)
- self._cached = rv
- self._cachets = time.time()
- self._backoff = None
- print '\033[32m', self._name, 'read', self._cached, '\033[m'
- return self._cached
+ # print '\033[32m', self._name, 'read', rv, '\033[m'
+ return rv
except SensorNotPresent:
self._backoff = time.time() + 2 + random.expovariate(1./3.) * 2
- print '\033[31m', self._name, 'SensorNotPresent back-off', self._backoff - time.time(), '\033[m'
- if self._cachets > time.time() - 250:
- return self._cached
+ # print '\033[31m', self._name, 'SensorNotPresent back-off', self._backoff - time.time(), '\033[m'
raise
except OutOfRange:
self._backoff = time.time() + 15 + random.expovariate(1./4.) * 10
- print '\033[33m', self._name, 'OutOfRange back-off', self._backoff - time.time(), '\033[m'
- if self._cachets > time.time() - 250:
- return self._cached
+ # print '\033[33m', self._name, 'OutOfRange back-off', self._backoff - time.time(), '\033[m'
raise
def sensor(name):
diff --git a/envmon/onewire2graphite.py b/envmon/onewire2graphite.py
index 4b7743e..81c6b50 100755
--- a/envmon/onewire2graphite.py
+++ b/envmon/onewire2graphite.py
@@ -22,22 +22,22 @@ while True:
nextslot = time.time() + 65
nextslot = nextslot - (nextslot % 60)
- while nextslot - time.time() > 5.0:
- for sensor in sensors:
- try:
- vals.setdefault(sensor, None)
- vals[sensor] = sensobj[sensor].temperature
- except onewire.SensorNotPresent, e:
- print >>sys.stderr, sensor, 'SensorNotPresent:', str(e)
- except onewire.OutOfRange, e:
- # print >>sys.stderr, sensor, 'OutOfRange:', str(e)
- pass
- except Exception:
- print >>sys.stderr, "On %s: Could not retrieve temperature for '%s':" % (
- time.strftime('%a, %d %b %Y %T %z'), sensor)
- sys.excepthook(*sys.exc_info())
- print >>sys.stderr, '========================================'
- time.sleep(0.5)
+ time.sleep(max(nextslot - len(sensors) * 0.8 - time.time(), 0))
+
+ for sensor in sensors:
+ try:
+ vals.setdefault(sensor, None)
+ vals[sensor] = sensobj[sensor].temperature
+ except onewire.SensorNotPresent, e:
+ print >>sys.stderr, sensor, 'SensorNotPresent:', str(e)
+ except onewire.OutOfRange, e:
+ # print >>sys.stderr, sensor, 'OutOfRange:', str(e)
+ pass
+ except Exception:
+ print >>sys.stderr, "On %s: Could not retrieve temperature for '%s':" % (
+ time.strftime('%a, %d %b %Y %T %z'), sensor)
+ sys.excepthook(*sys.exc_info())
+ print >>sys.stderr, '========================================'
time.sleep(max(nextslot - time.time(), 0))
goodvals = [sensor for sensor in sensors if vals.get(sensor, None) is not None]