summaryrefslogtreecommitdiff
path: root/envmon/onewire2graphite.py
blob: 73e6b8d8f8256da1fd1575ece24e5a4251680a19 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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()))