Mercurial > ~darius > hgwebdir.cgi > iec1107
diff iec1107.py @ 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 | b686ad203c1e |
children | c1892bd1460a |
line wrap: on
line diff
--- 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 --