-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpv.py
More file actions
31 lines (28 loc) · 959 Bytes
/
pv.py
File metadata and controls
31 lines (28 loc) · 959 Bytes
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
# Auslesen der PV-Leistung ünder das Kostal Web-Interace
import urllib
global last_value
if not 'last_value' in globals():
last_value = 0
# Auslesen PV-Seite
def read_pv_voltage():
password_mgr = urllib.request.HTTPPasswordMgrWithDefaultRealm()
top_level_url = "http://192.168.178.38"
password_mgr.add_password(None, top_level_url, "pvserver", "pvwr")
handler = urllib.request.HTTPBasicAuthHandler(password_mgr)
opener = urllib.request.build_opener(handler)
try:
f = opener.open(top_level_url)
except Exception as e:
print('exception reading pv-voltage')
return last_value
myfile = f.read()
myfilestr = myfile.decode("utf-8");
i = myfilestr.index('aktuell')
splitstr=myfilestr[i+65:i+95]
j = splitstr.index("</td>")
result = splitstr[0:j]
try:
converted_num = int(result)
except ValueError:
converted_num = int("0")
return converted_num