Skip to content

Instantly share code, notes, and snippets.

@insom
Created October 23, 2011 21:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save insom/1307924 to your computer and use it in GitHub Desktop.
Save insom/1307924 to your computer and use it in GitHub Desktop.
Export Current Cost power meter readings to a file readable by collectd
#!/usr/bin/python
import os
import serial
import re
s = serial.Serial('/dev/ttyUSB0', 57600)
FILENAME = '/tmp/cctable'
TMPNAME = FILENAME + '.new'
while True:
data = s.readline().strip()
rx = re.compile(r'<tmpr>([0-9\.]+)</tmpr>.*<watts>([0-9]+)</watts>')
bits = rx.findall(data)
if bits:
first, = bits
temp, watts = first
f = open(TMPNAME, 'w')
f.write("sensor0\t%s\t%s" % (temp, watts))
f.close()
os.rename(TMPNAME, FILENAME)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment