forked from snaptec/openWB
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreadlovato.py
127 lines (110 loc) · 4.18 KB
/
readlovato.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/usr/bin/python
import sys
import os
import time
import getopt
import struct
from pymodbus.client.sync import ModbusTcpClient
client = ModbusTcpClient('192.168.193.15', port=8899)
#from pymodbus.transaction import ModbusRtuFramer
#client = ModbusTcpClient('192.168.0.7', port=8899, framer=ModbusRtuFramer)
#Voltage
resp = client.read_input_registers(0x0001,2, unit=0x02)
voltage1 = float(resp.registers[1] / 100)
f = open('/var/www/html/openWB/ramdisk/evuv1', 'w')
f.write(str(voltage1))
f.close()
resp = client.read_input_registers(0x0003,2, unit=0x02)
voltage1 = float(resp.registers[1] / 100)
f = open('/var/www/html/openWB/ramdisk/evuv2', 'w')
f.write(str(voltage1))
f.close()
resp = client.read_input_registers(0x0005,2, unit=0x02)
voltage1 = float(resp.registers[1] / 100)
f = open('/var/www/html/openWB/ramdisk/evuv3', 'w')
f.write(str(voltage1))
f.close()
#Counters
resp = client.read_input_registers(0x1a1f,2, unit=0x02)
all = format(resp.registers[0], '04x') + format(resp.registers[1], '04x')
finalbezug = int(struct.unpack('>i', all.decode('hex'))[0])
f = open('/var/www/html/openWB/ramdisk/bezugkwh', 'w')
f.write(str(finalbezug))
f.close()
resp = client.read_input_registers(0x1a21,2, unit=0x02)
all = format(resp.registers[0], '04x') + format(resp.registers[1], '04x')
finaleinspeisung = int(struct.unpack('>i', all.decode('hex'))[0])
f = open('/var/www/html/openWB/ramdisk/einspeisungkwh', 'w')
f.write(str(finaleinspeisung))
f.close()
#phasen watt
resp = client.read_input_registers(0x0013,2, unit=0x02)
all = format(resp.registers[0], '04x') + format(resp.registers[1], '04x')
finalw1 = int(struct.unpack('>i', all.decode('hex'))[0] / 100)
f = open('/var/www/html/openWB/ramdisk/bezugw1', 'w')
f.write(str(finalw1))
f.close()
resp = client.read_input_registers(0x0015,2, unit=0x02)
all = format(resp.registers[0], '04x') + format(resp.registers[1], '04x')
finalw2 = int(struct.unpack('>i', all.decode('hex'))[0] / 100)
f = open('/var/www/html/openWB/ramdisk/bezugw2', 'w')
f.write(str(finalw2))
f.close()
resp = client.read_input_registers(0x0017,2, unit=0x02)
all = format(resp.registers[0], '04x') + format(resp.registers[1], '04x')
finalw3 = int(struct.unpack('>i', all.decode('hex'))[0] / 100)
f = open('/var/www/html/openWB/ramdisk/bezugw3', 'w')
f.write(str(finalw3))
f.close()
finalw= finalw1 + finalw2 + finalw3
#total watt
#resp = client.read_input_registers(0x0039,2, unit=0x02)
#all = format(resp.registers[0], '04x') + format(resp.registers[1], '04x')
#finalw = int(struct.unpack('>i', all.decode('hex'))[0] / 100)
f = open('/var/www/html/openWB/ramdisk/wattbezug', 'w')
f.write(str(finalw))
f.close()
#ampere l1
resp = client.read_input_registers(0x0007, 2, unit=0x02)
all = format(resp.registers[0], '04x') + format(resp.registers[1], '04x')
lla1 = float(struct.unpack('>i', all.decode('hex'))[0]) / 10000
f = open('/var/www/html/openWB/ramdisk/bezuga1', 'w')
f.write(str(lla1))
f.close()
#ampere l2
resp = client.read_input_registers(0x0009, 2, unit=0x02)
all = format(resp.registers[0], '04x') + format(resp.registers[1], '04x')
lla2 = float(struct.unpack('>i', all.decode('hex'))[0]) / 10000
f = open('/var/www/html/openWB/ramdisk/bezuga2', 'w')
f.write(str(lla2))
f.close()
#ampere l3
resp = client.read_input_registers(0x000b, 2, unit=0x02)
all = format(resp.registers[0], '04x') + format(resp.registers[1], '04x')
lla3 = float(struct.unpack('>i', all.decode('hex'))[0]) / 10000
f = open('/var/www/html/openWB/ramdisk/bezuga3', 'w')
f.write(str(lla3))
f.close()
#evuhz
resp = client.read_input_registers(0x0031,2, unit=0x02)
evuhz= float(resp.registers[1])
evuhz= float(evuhz / 100)
f = open('/var/www/html/openWB/ramdisk/evuhz', 'w')
f.write(str(evuhz))
f.close()
#Power Factor
resp = client.read_input_registers(0x0025,2, unit=0x02)
evupf1 = float(resp.registers[1]) / 10000
f = open('/var/www/html/openWB/ramdisk/evupf1', 'w')
f.write(str(evupf1))
f.close()
resp = client.read_input_registers(0x0027,2, unit=0x02)
evupf2 = float(resp.registers[1]) / 10000
f = open('/var/www/html/openWB/ramdisk/evupf2', 'w')
f.write(str(evupf2))
f.close()
resp = client.read_input_registers(0x0029,2, unit=0x02)
evupf3 = float(resp.registers[1]) / 10000
f = open('/var/www/html/openWB/ramdisk/evupf3', 'w')
f.write(str(evupf3))
f.close()