Mercurial > ~darius > hgwebdir.cgi > iec1107
comparison 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 |
comparison
equal
deleted
inserted
replaced
7:8031548a5d48 | 8:08b192a6e189 |
---|---|
28 # http://www.domoticaforum.eu/viewtopic.php?f=71&t=7489 | 28 # http://www.domoticaforum.eu/viewtopic.php?f=71&t=7489 |
29 # | 29 # |
30 | 30 |
31 import datetime | 31 import datetime |
32 import exceptions | 32 import exceptions |
33 import optparse | |
33 import re | 34 import re |
34 import serial | 35 import serial |
35 import sys | 36 import sys |
36 import time | 37 import time |
37 | 38 |
151 | 152 |
152 def __str__(self): | 153 def __str__(self): |
153 return 'Time: %s, Meter: %s, Import: %d Wh, Export: %d Wh' % (self.readdate.strftime('%Y/%m/%d %H:%M'), | 154 return 'Time: %s, Meter: %s, Import: %d Wh, Export: %d Wh' % (self.readdate.strftime('%Y/%m/%d %H:%M'), |
154 self.meterid, self.importWh, self.exportWh) | 155 self.meterid, self.importWh, self.exportWh) |
155 def main(): | 156 def main(): |
156 if len(sys.argv) != 2: | 157 parser = optparse.OptionParser(usage = 'usage: %prog [options] port', |
157 print 'Bad usage' | 158 epilog = 'Read out from an IEC1107 meter') |
158 print '\t%s portname' % (sys.argv[0]) | 159 parser.add_option('-r', '--rrd', dest = 'rrd', action = 'store_true', default = False, help = 'Output in a format suitable for rrdtool') |
159 sys.exit(1) | 160 (opt, args) = parser.parse_args() |
161 if len(args) != 1: | |
162 parser.error('Need to specify port') | |
160 | 163 |
161 res = IEC1107Reading(sys.argv[1]) | 164 res = IEC1107Reading(args[0]) |
162 print res | 165 if opt.rrd: |
166 print '%s:%d:%d' % (res.readdate.strftime('%s'), res.importWh, res.exportWh) | |
167 else: | |
168 print res | |
163 | 169 |
164 if __name__ == '__main__': | 170 if __name__ == '__main__': |
165 main() | 171 main() |
166 | 172 |
167 # Meter number is 1288004 | |
168 # 1.8.0 is import | |
169 # 1.8.1 is ?? | |
170 # 1.8.2 is ?? | |
171 # 1.8.3 is ?? | |
172 # 2.8.0 is export | |
173 | |
174 # C.1(12880041.0(22:25 18-11-13) | |
175 # 1.8.1(0000000597*Wh) | |
176 # 1.8.2(0000000000*Wh) | |
177 # 1.8.3(0000264238*Wh) | |
178 # 1.8.0(0000264835*Wh) | |
179 # 2.8.0(0000511354*Wh) | |
180 | |
181 # ==> /?!<0D><0A> | |
182 # <== /ACE5SMLCD | |
183 # ==> <06>050<0D><0A> | |
184 # <== -- STX -- | |
185 # <== C.1(12880041.0(22:48 18-11-13) | |
186 # <== 1.8.1(0000000597*Wh) | |
187 # <== 1.8.2(0000000000*Wh) | |
188 # <== 1.8.3(0000264460*Wh) | |
189 # <== 1.8.0(0000265057*Wh) | |
190 # <== 2.8.0(0000511354*Wh) | |
191 # <== ! | |
192 # <== -- ETX -- | |
193 # <== -- BCC -- |