-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxtenderweb.py
175 lines (132 loc) · 6.1 KB
/
xtenderweb.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
from flask import Flask, render_template, send_file, jsonify, request
import xtender, threading, time
import json
#flask
app = Flask(__name__)
olist = []
# id , zeit in s
class XPollObjekt(object):
value = 1.0 #Speicher für die geholten werte
def __init__(self, id = 0, name = "name", unit = "", refreshtime = 0.0, a = 1.0) -> None:
self.id = id
self.name = name
self.unit = unit
self.refreshtime = refreshtime
self.updatetime = time.time()
self.raw = 0.0
self.a = a
self.init = True
def value (self):
return round (self.a * self.raw, 2)
#Liste mit zu pollenden Xtender Objekten
def init_poll_list(api):
olist.append(XPollObjekt(api.INFO_INPUT_VOLTAGE, "Netz-Eingangsspannung","V", 5.0))
olist.append(XPollObjekt(api.INFO_INPUT_CURRENT, "Netz-Eingangsstrom","A", 8.0))
olist.append(XPollObjekt(api.INFO_INPUT_POWER, "Netz-Eingangsleistung","W", 10.0,1000.0))
olist.append(XPollObjekt(api.INFO_BATTERY_VOLTAGE, "Batteriespannung","V", 10.0))
olist.append(XPollObjekt(api.INFO_OUTPUT_POWER, "Netz-Ausgangsleistung","W", 5.0, 1000.0))
olist.append(XPollObjekt(api.INFO_OUTPUT_CURRENT, "Netz-Ausgangsstrom","A", 5.0))
olist.append(XPollObjekt(api.INFO_STATE_OF_OUTPUT_RELAY, "Status Ausgangsrelais","on/off", 60.0))
olist.append(XPollObjekt(api.INFO_STATE_OF_TRANSFER_RELAY, "Status Tranferrelais","on/off", 60.0))
olist.append(XPollObjekt(api.INFO_BATTERY_CHARGE_CURRENT, "Batterie Ladestrom","A", 60.0))
def init_param_list(api):
olist.append(XPollObjekt(api.PARA_BATTERY_CHARGE_CURRENT, "Batterie Ladestrom","A", 0.0))
'''
printf("Inverter allowed \t1124 = %d, Prohibits = %d\n", read_bool(1124,""), read_bool(1539,""));
printf("Charger allowed \t1125 = %d, Prohibits = %d\n", read_bool(1125,""), read_bool(1540,""));
printf("Boost allowed \t1126 = %d, Prohibits = %d\n", read_bool(1126,""), read_bool(1541,""));
printf("Transfer allowed \t1128 = %d, Prohibits = %d\n", read_bool(1128,""), read_bool(1538,""));
printf("Battery priority \t1296 = %d, Prohibits = %d\n", read_bool(1296,""), read_bool(1579,""));
read_bool(1155,"Absorbtion allowed \t1155 = %x\n");
read_float(1138,"Battery charge current \t1138 = %.2f A\n");
read_float(1108,"Battery undervoltage \t1108 = %.2f V\n");
read_float(1110,"Restart undervoltage \t1110 = %.2f V\n");
read_float(1109,"Battery undervo load \t1109 = %.2f V\n");
read_float(1121,"Max Bat- Voltage \t1121 = %.2f V\n");
read_float(1140,"Floating Voltage \t1140 = %.2f V\n");
read_float(1143,"Battery Voltage level 1\t1143 = %.2f V\n");
read_float(1145,"Battery Voltage level 2\t1145 = %.2f V\n");
read_float(1164,"Egalisierungs- Voltage \t1164 = %.2f V\n");
read_float(1156,"Absorption Voltage \t1156 = %.2f V\n");
read_float(1172,"Reduced floating volt \t1172 = %.2f V\n");
bat_prio_v = read_float(1297,"Battery prio voltage \t1297 = %.2f V\n");
read_float(1143,"Voltage level 1 \t1143 = %.2f V\n");
read_float(1144,"Dauer Unterspannung \t1144 = %.2f min\n");
read_float(1187,"Standby level \t1187 = %.2f %\n");
//read_float(1286,"AC Output voltage \t1286 = %.2f V\n");
read_float(1107,"Maximum AC current \t1107 = %.2f A\n");
read_float(1138,"Battery charge current \t1138 = %.2f A\n");
read_float(1607,"Limitation Power Boost \t1607 = %.2f A\n");
// Fernsteuereingang geht 23.03.20
read_long_enum(1202,"Operating mode (AUX 1) \t1202 = %ld\n"); // def: auto = 1,
read_bool(1578,"Remote Activated by AUX 1 \t1578 = %d\n"); // state, 1=on
read_bool(1543,"Remote entry (AUX 1) active \t1543 = %d\n"); //
read_long_enum(1545,"Remote Aktivierungsmodus \t1545 = %ld\n"); //, Fernsteuereingang def:open:1/closed:0
read_float(1255, "Bat voltage deact.(AUX 1)\t1255 = %.2f V\n");
read_float(1247, "Battery voltage 1 act. (AUX 1)\t1247 = %.2f V\n");
read_float(1250, "Battery voltage 2 act. (AUX 1)\t1250 = %.2f V\n");
'''
def polling_thead():
Xtender = xtender.Xtender()
init_poll_list(Xtender.api)
init_param_list(Xtender.api)
while (True):
i = 0
while i < len(olist) :
o = olist[i]
if o.updatetime > 0:
if o.updatetime < time.time():
o.updatetime = time.time() + o.refreshtime
o.raw = Xtender.conn.read_id(o.id)
#print(time.time(), o.name, o.refreshtime, o.value , threading.get_ident())
else:
if o.init == True:
o.raw = Xtender.conn.read_id(o.id)
o.init = False
i += 1
time.sleep(0.2)
@app.before_first_request
def before_first_request():
th = threading.Thread(target=polling_thead)
th.start()
time.sleep(1)
print ("Thread gestartet")
@app.after_request
def after_request(response):
header = response.headers
header['Access-Control-Allow-Origin'] = '*'
return response
@app.route('/')
def hello():
return 'Hello, World!'
@app.route('/status')
def status():
return render_template('status.html')
@app.route('/script.js')
def script_js():
#return send_file('templates/script.js')
return render_template('script.js')
'''
@app.route('/status/<path:path>')
def status1(path):
return render_template("static", path)
'''
@app.route('/list')
def list():
b = {}
for obj in olist:
b.update({"id"+str(obj.id) : {"value":obj.value(),"name":obj.name,"unit":obj.unit}})
return jsonify(b)
@app.route( "/u_eingang" )
def f_u_eingang():
return jsonify( {"u_eingang": olist[0].value} )
@app.route( "/value_by_id" )
def f_value_by_id():
id = request.args.get("id", default = 3000, type = int)
j = "id_" + str(id)
print(id)
return jsonify( {j: xtender.read_id(id)} )
if __name__ == '__main__':
app.run(port=80, host='192.168.123.35', debug=True)
pass
print("Ende")