Browse code

Initial commit

Bernd Wurst authored on08/03/2012 15:58:38
Showing1 changed files
1 1
new file mode 100755
... ...
@@ -0,0 +1,107 @@
1
+#!/usr/bin/python
2
+# -* coding: utf-8 *-
3
+
4
+# This program is free software: you can redistribute it and/or modify
5
+# it under the terms of the GNU General Public License as published by
6
+# the Free Software Foundation, either version 3 of the License, or
7
+# (at your option) any later version.
8
+# This program is distributed in the hope that it will be useful,
9
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
+# GNU General Public License for more details.
12
+
13
+# You should have received a copy of the GNU General Public License
14
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
15
+
16
+# Developed 2009-2010 by Bernd Wurst <bernd@schokokeks.org> 
17
+# for own use.
18
+# Released to the public in 2012.
19
+
20
+
21
+import time, sys, os
22
+from solarmax import SolarMax
23
+
24
+from sqlite3 import dbapi2 as sqlite
25
+DB_FILE=sys.argv[1]
26
+
27
+inverters = { '192.168.0.201': [1,],
28
+              '192.168.0.202': [2,],
29
+              '192.168.0.203': [3,],
30
+              '192.168.0.204': [4,],
31
+            }
32
+
33
+
34
+smlist = []
35
+for host in inverters.keys():
36
+  sm = SolarMax(host, 12345)
37
+  sm.use_inverters(inverters[host])
38
+  smlist.append(sm)
39
+
40
+
41
+allinverters = []
42
+for host in inverters.keys():
43
+  allinverters.extend(inverters[host])
44
+
45
+dbconn = sqlite.connect(DB_FILE)
46
+db = dbconn.cursor()
47
+
48
+while True:
49
+  pac_gesamt = 0.0
50
+  daysum_gesamt = 0.0
51
+
52
+  count = 0
53
+  for sm in smlist:
54
+    for (no, ivdata) in sm.inverters().iteritems():
55
+      try:
56
+        (inverter, current) = sm.query(no, ['PAC', 'KDY', 'KT0', 'IDC', 'UDC', 'IL1', 'UL1', 'FDAT', 'SYS'])
57
+        count += 1
58
+      except:
59
+        # Kommunikationsfehler, evtl. Wechselrichter aus
60
+        print 'Kommunikationsfehler, WR %i' % no
61
+        continue
62
+    
63
+      ivmax = ivdata['installed']
64
+      ivname = ivdata['desc']
65
+      PAC = current['IL1'] * current['UL1']
66
+      percent = int((PAC/ivmax) * 100)
67
+      PDC = current['IDC'] * current['UDC']
68
+      (status, errors) = sm.status(no)
69
+      if errors:
70
+        print 'WR %i: %s (%s)' % (no, status, errors)
71
+      
72
+
73
+      #print '''
74
+      #WR %i (%s)
75
+        #Status: %s
76
+        #Aktuell: %9.1f Watt / errechnet: %8.1f W (%i %% von %i Watt)
77
+        #P_DC:    %9.1f Watt (Wirkungsgrad: %i %%)
78
+        #Gesamt heute:   %8.1f   kWh
79
+        #Gesamt bisher:  %8.1f   kWh (seit %s)
80
+      #''' % (inverter, ivname, status, current['PAC'], PAC, percent, ivmax, PDC, int((float(PAC)/PDC) * 100), current['KDY'], current['KT0'], current['FDAT'].date())
81
+      try:
82
+        # K├Ânnte gelocked sein
83
+        # System ist 2 in diesem Fall. Fix.
84
+        db.execute('''INSERT INTO performance (time, inverter, system, pac, daysum, total) VALUES (strftime('%%s','now'), %i, 2, %i, %i, %i)'''
85
+                  % (inverter, int(current['PAC']), int(current['KDY']*1000), int(current['KT0']*1000)))
86
+      except:
87
+        pass
88
+      pac_gesamt += current['PAC']
89
+      daysum_gesamt += current['KDY']
90
+  try:
91
+    dbconn.commit()
92
+  except:
93
+    pass
94
+  if count < len(allinverters):
95
+    print 'Zu wenig Wechselrichter (%i < %i)' % (count, len(allinverters))
96
+
97
+  #print '='*80
98
+  #print 'GESAMT:  %9.2f Watt    / Heute: %8.1f kWh' % (pac_gesamt, daysum_gesamt)
99
+  time.sleep(10)
100
+
101
+
102
+
103
+
104
+
105
+
106
+
107
+