diff options
Diffstat (limited to 'envmon')
-rwxr-xr-x | envmon/onewire2graphite.py | 30 | ||||
-rwxr-xr-x | envmon/outdoor2graphite.py | 35 |
2 files changed, 65 insertions, 0 deletions
diff --git a/envmon/onewire2graphite.py b/envmon/onewire2graphite.py new file mode 100755 index 0000000..73e6b8d --- /dev/null +++ b/envmon/onewire2graphite.py @@ -0,0 +1,30 @@ +#!/usr/bin/python + +import time +import sys + +import onewire +import socket + +CARBON_SERVER = 'sonar.local.sublab.org' +CARBON_PORT = 2003 + +prefix = "envmon.beaglebone_local_sublab_org." + +sock = socket.socket() +sock.connect((CARBON_SERVER, CARBON_PORT)) + +while True: + message = '' + for sensor in onewire.sensors(): + try: + message += "%s %f %d\n" % (prefix + sensor, onewire.sensor(sensor).temperature, time.time()) + 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, '========================================' + if message: + print message + sock.sendall(message) + time.sleep(300-len(onewire.sensors())) diff --git a/envmon/outdoor2graphite.py b/envmon/outdoor2graphite.py new file mode 100755 index 0000000..de58698 --- /dev/null +++ b/envmon/outdoor2graphite.py @@ -0,0 +1,35 @@ +#!/usr/bin/python + +import time +import sys + +import socket + +import weather + +location = '20065491' # Leipzig + +CARBON_SERVER = 'sonar.local.sublab.org' +CARBON_PORT = 2003 + +prefix = "envmon.beaglebone_local_sublab_org." + +sock = socket.socket() +sock.connect((CARBON_SERVER, CARBON_PORT)) + +while True: + message = '' + try: + data = weather.weather(location) + message += '%s %s %d\n' % (prefix + 'outside', + data.temperature, + time.time()) + except Exception: + sys.stderr.write('Exception occured at %s:\n' % time.strftime('%a, %d %b %Y %T %z')) + sys.excepthook(*sys.exc_info()) + sys.stderr.write('========================================\n') + time.sleep(60) + else: + sock.sendall(message) + time.sleep(300) + |