forked from stik79/DeltaPVOutput
-
Notifications
You must be signed in to change notification settings - Fork 11
/
power-now.py
executable file
·82 lines (61 loc) · 2.48 KB
/
power-now.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#A simple script to read values from a delta inverter and post them to
#PVoutput.org
import time, subprocess,serial
from delta30EUG4TRInv import Delta30EU_G4_TR_Inverter
from time import localtime, strftime
from config import Configuration
from mysql import MysqlInserter
if __name__ == '__main__':
connection = serial.Serial('/dev/ttyUSB0',Configuration.serialBaud, timeout=Configuration.serialTimeoutSecs)
localtime = time.localtime(time.time())
t_date = 'd={0}'.format(strftime('%Y%m%d'))
t_time = 't={0}'.format(strftime('%H:%M'))
inv1 = Delta30EU_G4_TR_Inverter(Configuration.RS485IDS[0], connection)
inv2 = Delta30EU_G4_TR_Inverter(Configuration.RS485IDS[1], connection)
acPower1 = inv1.call('AC Power')
print ("1: AC Power: " + str(acPower1) + " W")
dcPower1 = inv1.call('DC Power')
print ("1: DC Power: " + str(dcPower1) + " W")
dcVoltage1 = inv1.call('DC Voltage')
print ("1: DC Voltage: " + str(dcVoltage1) + " V")
dcCurrent1 = inv1.call('DC Current')
print ("1: DC Current: " + str(dcCurrent1) + " A")
try:
print "1: Efficiency: %.2f%%" % (100.0*int(acPower1)/int(dcPower1))
except:
pass
energyDay1 = inv1.call('Energy Day')
print ("1: Energy Day: " + str(energyDay1) + " wh\n")
acPower2 = inv2.call('AC Power')
print ("2: AC Power: " + str(acPower2) + " W")
dcPower2 = inv2.call('DC Power')
print ("2: DC Power: " + str(dcPower2) + " W")
dcVoltage2 = inv2.call('DC Voltage')
print ("2: DC Voltage: " + str(dcVoltage2) + " V")
dcCurrent2 = inv2.call('DC Current')
print ("2: DC Current: " + str(dcCurrent2) + " A")
try:
print "2: Efficiency: %.2f%%" % (100.0*int(acPower2)/int(dcPower2))
except:
pass
energyDay2 = inv2.call('Energy Day')
print ("2: Energy Day: " + str(energyDay2) + " Wh\n")
connection.close()
try:
print ("Total: AC Power: " + str(int(acPower1) + int(acPower2)) + " W")
except:
pass
try:
print ("Total DC Power: " + str(int(dcPower1) + int(dcPower2)) + " W")
except:
pass
try:
print ("Total Energy Day: " + str(int(energyDay1) + int(energyDay2)) + " Wh\n")
except:
pass
try:
m = MysqlInserter()
m.insert(1, dcVoltage1, dcPower1, acPower1)
m.insert(2, dcVoltage2, dcPower2, acPower2)
except:
print "Error inserting into mysql"