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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
| #A simple script to read values from a delta inverter and post them to
#PVoutput.org
import time, subprocess,serial,argparse,sys
from deltaInv import DeltaInverter
from w1thermsensor import W1ThermSensor
from time import localtime, strftime
import MySQLdb as mdb
#PVOutput.org API Values - UPDATE THESE TO YOURS!
SYSTEMID="xxxx"
APIKEY="xxxxx"
sensor = W1ThermSensor()
value = sensor.get_temperature()
t_temp1 = 'v7={0}'.format(value)
parser = argparse.ArgumentParser()
if __name__ == '__main__':
parser.add_argument('-v','--verbose',help='Enable verbose output to stderr',default=False,dest='verbose_mode',required=False,action='store_true')
parser_results = parser.parse_args()
#Edit your serial connection as required!!
connection = serial.Serial('/dev/ttyUSB1',19200,timeout=0.4);
localtime = time.localtime(time.time())
t_date = 'd={0}'.format(strftime('%Y%m%d'))
t_time = 't={0}'.format(strftime('%H:%M'))
inv1 = DeltaInverter(1) #init Inverter 1
#Get the Daily Energy thus far
cmd = inv1.getCmdStringFor('Day Wh')
connection.write(cmd)
response = connection.read(100)
#if no response the inverter is asleep
if response:
value = inv1.getValueFromResponse(response)
t_energy = 'v1={0}'.format(value)
t_energy1 = value
#instanteous power
cmd = inv1.getCmdStringFor('AC Power')
connection.write(cmd)
response = connection.read(100)
value = inv1.getValueFromResponse(response)
t_power = 'v2={0}'.format(value)
t_power1 = value
#DC Voltage
cmd = inv1.getCmdStringFor('DC Volts1')
connection.write(cmd)
response = connection.read(100)
value = inv1.getValueFromResponse(response)
t_volts = 'v6={0}'.format(value)
#Temp - this appears to be onboard somewhere not the heatsink
cmd = inv1.getCmdStringFor('AC Temp')
connection.write(cmd)
response = connection.read(100)
value = inv1.getValueFromResponse(response)
t_temp = 'v5={0}'.format(value)
#AC Voltage
cmd = inv1.getCmdStringFor('AC Volts')
connection.write(cmd)
response = connection.read(100)
value = inv1.getValueFromResponse(response)
t_volts1 = 'v8={0}'.format(value)
#if verbose mode
if parser_results.verbose_mode==True:
sys.stderr.write('Date: %s, Time: %s\n' %(t_date, t_time))
sys.stderr.write('Energy Today: %sWh, Instantaneous Power: %sW\n' %(t_energy,t_power))
sys.stderr.write('Volts: %s, Temp: %s oC\n' % (t_volts,t_temp))
sys.stderr.write('Volts1: %s, Temp1: %s oC\n' % (t_volts1,t_temp1))
sys.stderr.flush()
#Send it all off to PVOutput.org
cmd = ['/usr/bin/curl',
'-d', t_date,
'-d', t_time,
'-d', t_energy,
'-d', t_power,
'-d', t_volts,
'-d', t_temp,
'-d', t_temp1,
'-d', t_volts1,
'-H', 'X-Pvoutput-Apikey: ' + APIKEY,
'-H', 'X-Pvoutput-SystemId: ' + SYSTEMID,
'http://pvoutput.org/service/r2/addstatus.jsp']
ret = subprocess.call (cmd)
else:
print "No response from inverter - shutdown? No Data sent to PVOutput.org"
con = mdb.connect('localhost', 'xxxx', 'xxx', 'deltapv')
with con:
cur = con.cursor()
cur.execute("INSERT INTO klump4uzw(t_energy,t_power) VALUES (%s,%s) ", (t_energy1,t_power1))
cur.close()
print t_temp, t_temp1, t_power, t_energy, t_volts, t_volts1
connection.close() |