Skip to content

Commit

Permalink
sunwaves
Browse files Browse the repository at this point in the history
  • Loading branch information
LKuemmel committed Feb 23, 2022
1 parent a3e3f77 commit 5356c9d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 37 deletions.
3 changes: 1 addition & 2 deletions modules/wr_sunwaves/main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ fi
openwbDebugLog ${DMOD} 2 "PV IP: ${wrsunwavesip}"
openwbDebugLog ${DMOD} 2 "PV Passwort: ${wrsunwavespw}"


python3 /var/www/html/openWB/modules/wr_sunwaves/sunwaves.py "${wrsunwavesip}" "${wrsunwavespw}" >>$MYLOGFILE 2>&1
bash "$OPENWBBASEDIR/packages/legacy_run.sh" "wr_sunwaves.sunwaves" "${wrsunwavesip}" "${wrsunwavespw}" >>$MYLOGFILE 2>&1
ret=$?

openwbDebugLog ${DMOD} 2 "RET: ${ret}"
Expand Down
64 changes: 29 additions & 35 deletions modules/wr_sunwaves/sunwaves.py
Original file line number Diff line number Diff line change
@@ -1,48 +1,42 @@
#!/usr/bin/env python3
from datetime import datetime, timezone
import os
import logging
import re
import requests
from requests.auth import HTTPDigestAuth
import sys
from typing import List

Debug = int(os.environ.get('debug'))
myPid = str(os.getpid())
from helpermodules.cli import run_using_positional_cli_args

wrsunwavesip = str(sys.argv[1])
wrsunwavespw = str(sys.argv[2])
log = logging.getLogger("Sunwaves WR")


def DebugLog(message):
local_time = datetime.now(timezone.utc).astimezone()
print(local_time.strftime(format="%Y-%m-%d %H:%M:%S") + ": PID: " + myPid + ": " + message)
def update(wrsunwavesip: str, wrsunwavespw: str):
log.debug('PV Sunwaves IP:' + wrsunwavesip)
log.debug('PV Sunwaves Passwort:' + wrsunwavespw)

params = (('CAN', '1'),)
variable = requests.get("http://"+wrsunwavesip+"/data/ajax.txt",
params=params,
auth=HTTPDigestAuth("customer", wrsunwavespw),
timeout=3)
variable.encoding = 'utf-8'
variable = variable.text.replace("\n", "")

if Debug >= 2:
DebugLog('PV Sunwaves IP:' + wrsunwavesip)
DebugLog('PV Sunwaves Passwort:' + wrsunwavespw)
count = 0

for v in variable:
if count == 1:
pvwatt = re.search('^[0-9]+$', v).group()
pvwatt = pvwatt*-1
log.debug('WR Leistung: ' + str(pvwatt))
with open("/var/www/html/openWB/ramdisk/pvwatt", "w") as f:
f.write(str(pvwatt))
if count == 16:
log.debug('WR Energie: ' + str(v*1000))
with open("/var/www/html/openWB/ramdisk/pvkwh", "w") as f:
f.write(str(v*1000))
count = count+1

params = (('CAN', '1'),)
variable = requests.get("http://"+wrsunwavesip+"/data/ajax.txt", params=params, auth=HTTPDigestAuth("customer", wrsunwavespw))
variable.encoding = 'utf-8'
variable = variable.text.replace("\n", "")

count = 0

for v in variable:
if count == 1:
pvwatt = re.search('^[0-9]+$', v).group()
pvwatt = pvwatt*-1
if Debug >= 1:
DebugLog('WR Leistung: ' + str(pvwatt))
with open("/var/www/html/openWB/ramdisk/pvwatt", "w") as f:
f.write(str(pvwatt))
if count == 16:
if Debug >= 1:
DebugLog('WR Energie: ' + str(v*1000))
with open("/var/www/html/openWB/ramdisk/pvkwh", "w") as f:
f.write(str(v*1000))
count = count+1

exit(0)
def main(argv: List[str]):
run_using_positional_cli_args(update, argv)

0 comments on commit 5356c9d

Please sign in to comment.