forked from Woutrrr/Omnik-Data-Logger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLiveStats.py
82 lines (62 loc) · 2.57 KB
/
LiveStats.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
#!/usr/bin/python
from InverterMsg import InverterMsg # Import the Msg handler
import sys
import socket # Needed for talking to inverter
import datetime # Used for timestamp
################
### Settings ###
################
# Inverter
ip = '192.168.1.15'
port = 8899
#######################
### End of Settings ###
#######################
#s = socket.socket() # Create a socket object
#s.connect((ip, port))
#s.sendall('\x68\x02\x40\x30\xa6\x68\xe6\x23\xa6\x68\xe6\x23\x01\x00\xa1\x16')
#data = s.recv(128)
#s.close # Close the socket when done
# Create a TCP/IP socket
#sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# Connect the socket to the port where the server is listening
server_address = ((ip, port))
message = '\x68\x02\x40\x30\xcb\x64\xec\x23\xcb\x64\xec\x23\x01\x00\xef\x16'
for res in socket.getaddrinfo(ip, port, socket.AF_INET , socket.SOCK_STREAM):
af, socktype, proto, canonname, sa = res
try:
print >>sys.stderr, 'connecting to %s port %s' % server_address
s = socket.socket(af, socktype, proto)
except socket.error as msg:
s = None
continue
try:
s.connect(sa)
except socket.error as msg:
s.close()
s = None
continue
break
if s is None:
print 'could not open socket'
sys.exit(1)
s.sendall(message)
data = s.recv(1024)
s.close()
#print 'Received', repr(data)
#sock.sendall('\x68\x02\x40\x30\xa6\x68\xe6\x23\xa6\x68\xe6\x23\x01\x00\xa1\x16')
#data = sock.recv(128)
#sock.close
msg = InverterMsg(data) # This is where the magic happens ;)
now = datetime.datetime.now()
print "Time: ", now.strftime('%H:%M')
print "Date: ", now.strftime('%Y%m%d')
print "ID: {0}".format(msg.getID())
print "E Today: {0:>5} Total: {1:<5}".format(msg.getEToday(), msg.getETotal())
print "H Total: {0:>5} Temp: {1:<5}".format(msg.getHTotal(), msg.getTemp())
print "PV1 V: {0:>5} I: {1:>4}".format(msg.getVPV(1), msg.getIPV(1))
print "PV2 V: {0:>5} I: {1:>4}".format(msg.getVPV(2), msg.getIPV(2))
print "PV3 V: {0:>5} I: {1:>4}".format(msg.getVPV(3), msg.getIPV(3))
print "L1 P: {0:>5} V: {1:>5} I: {2:>4} F: {3:>5}".format(msg.getPAC(1), msg.getVAC(1), msg.getIAC(1), msg.getFAC(1))
print "L2 P: {0:>5} V: {1:>5} I: {2:>4} F: {3:>5}".format(msg.getPAC(2), msg.getVAC(2), msg.getIAC(2), msg.getFAC(2))
print "L3 P: {0:>5} V: {1:>5} I: {2:>4} F: {3:>5}".format(msg.getPAC(3), msg.getVAC(3), msg.getIAC(3), msg.getFAC(3))