Mercurial > ~darius > hgwebdir.cgi > iec1107
changeset 8:08b192a6e189
Add RRD output mode.
Trim comments
author | Daniel O'Connor <darius@dons.net.au> |
---|---|
date | Wed, 20 Nov 2013 23:44:55 +1030 |
parents | 8031548a5d48 |
children | 139e267c9965 |
files | README iec1107.py |
diffstat | 2 files changed, 28 insertions(+), 33 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/README Wed Nov 20 23:44:55 2013 +1030 @@ -0,0 +1,16 @@ +An RRD can be created like so.. + +rrdtool create ~/meter.rrd \ + DS:import:COUNTER:600:U:U \ + DS:export:COUNTER:600:U:U \ + RRA:AVERAGE:0.5:1:105120 \ + RRA:AVERAGE:0.5:12:105120 \ + RRA:MAX:0.5:1:105120 \ + RRA:MAX:0.5:12:105120 \ + RRA:MIN:0.5:1:105120 \ + RRA:MIN:0.5:12:105120 + +Then data added with.. +rrdtool update ~/meter.rrd `ssh -ay -i ~/.ssh/id_rpi pi@raspberrypi python iec1107/iec1107.py -r /dev/ttyUSB0` + +
--- a/iec1107.py Wed Nov 20 23:26:45 2013 +1030 +++ b/iec1107.py Wed Nov 20 23:44:55 2013 +1030 @@ -30,6 +30,7 @@ import datetime import exceptions +import optparse import re import serial import sys @@ -153,41 +154,19 @@ return 'Time: %s, Meter: %s, Import: %d Wh, Export: %d Wh' % (self.readdate.strftime('%Y/%m/%d %H:%M'), self.meterid, self.importWh, self.exportWh) def main(): - if len(sys.argv) != 2: - print 'Bad usage' - print '\t%s portname' % (sys.argv[0]) - sys.exit(1) + parser = optparse.OptionParser(usage = 'usage: %prog [options] port', + epilog = 'Read out from an IEC1107 meter') + parser.add_option('-r', '--rrd', dest = 'rrd', action = 'store_true', default = False, help = 'Output in a format suitable for rrdtool') + (opt, args) = parser.parse_args() + if len(args) != 1: + parser.error('Need to specify port') - res = IEC1107Reading(sys.argv[1]) - print res + res = IEC1107Reading(args[0]) + if opt.rrd: + print '%s:%d:%d' % (res.readdate.strftime('%s'), res.importWh, res.exportWh) + else: + print res if __name__ == '__main__': main() -# Meter number is 1288004 -# 1.8.0 is import -# 1.8.1 is ?? -# 1.8.2 is ?? -# 1.8.3 is ?? -# 2.8.0 is export - -# C.1(12880041.0(22:25 18-11-13) -# 1.8.1(0000000597*Wh) -# 1.8.2(0000000000*Wh) -# 1.8.3(0000264238*Wh) -# 1.8.0(0000264835*Wh) -# 2.8.0(0000511354*Wh) - -# ==> /?!<0D><0A> -# <== /ACE5SMLCD -# ==> <06>050<0D><0A> -# <== -- STX -- -# <== C.1(12880041.0(22:48 18-11-13) -# <== 1.8.1(0000000597*Wh) -# <== 1.8.2(0000000000*Wh) -# <== 1.8.3(0000264460*Wh) -# <== 1.8.0(0000265057*Wh) -# <== 2.8.0(0000511354*Wh) -# <== ! -# <== -- ETX -- -# <== -- BCC --