-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy path__main__.py
More file actions
76 lines (66 loc) · 2.32 KB
/
__main__.py
File metadata and controls
76 lines (66 loc) · 2.32 KB
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
import goodweConfig
import GoodweFactory
import pvoutput
import csvoutput
import time
import getpass
import os
def mainloop( goodwe, pvoutput, csv, process):
# Main processing loop
#
# Do for ever.
try:
while True:
interval = 5.0*60
try: # Read Goodwe data from goodwe-power.com
# print "read sample"
gw = goodwe.read_sample_data()
except Exception, arg:
interval = 1.0*60
print "Read data Error: " + str(arg)
else:
if goodwe.is_online():
# write CSV file
# print "CSV sample"
csv.write_data( gw)
# print "Process sample"
process.processSample( gw)
else:
# Wait for the inverter to come online
print "Inverter is not online: " + gw.to_string()
interval = 30.0*60
csv.reset()
process.reset()
# Wait for the next sample
# print "sleep " + str(interval) + " seconds before next sample"
time.sleep(interval)
except KeyboardInterrupt:
print "Keyboard Initerrupt"
goodwe.terminate()
if __name__ == "__main__":
# Main entry point for the Goodwe to PVoutput logging script. Creates the
# objects needed and sets the URL and system IDs. These are read from the
# config file in ${HOME}/.goodwe2pvoutput
#
home = os.environ['HOME']
configfile = os.path.join(home,'.goodwe2pvoutput')
config = goodweConfig.goodweConfig( configfile)
factory = GoodweFactory.GoodweFactory( config)
config.to_string()
pvoutput = pvoutput.pvoutput( config.get_pvoutput_url(),
config.get_pvoutput_system_id(),
config.get_pvoutput_api())
csv = csvoutput.csvoutput( config.get_csv_dir(), 'Goodwe_PV_data')
goodwe, process = factory.create( pvoutput)
try:
goodwe.initialize()
print config.get_input_source() + " initialized"
except Exception, ex:
print ex
if config.get_temp_monitor():
print "Setting up temperature monitoring."
import tempMonitor
tempMonitor.tempMonitor( goodwe, config.get_gpio_fan_pins())
# Perform main loop
mainloop( goodwe, pvoutput, csv, process)
#---------------- End of file ------------------------------------------------