Skip to content

Commit

Permalink
solarworld
Browse files Browse the repository at this point in the history
  • Loading branch information
LKuemmel committed Feb 23, 2022
1 parent 71788d6 commit f72974f
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 68 deletions.
2 changes: 1 addition & 1 deletion modules/bezug_solarworld/main.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ fi

openwbDebugLog ${DMOD} 2 "Bezug Solarworld IP: ${solarworld_emanagerip}"

python3 /var/www/html/openWB/modules/bezug_solarworld/solarworld.py "${solarworld_emanagerip}" >>$MYLOGFILE 2>&1
bash "$OPENWBBASEDIR/packages/legacy_run.sh" "bezug_solarworld.solarworld" "${solarworld_emanagerip}" >>$MYLOGFILE 2>&1
ret=$?

openwbDebugLog ${DMOD} 2 "RET: ${ret}"
Expand Down
63 changes: 28 additions & 35 deletions modules/bezug_solarworld/solarworld.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,48 +1,41 @@
#!/usr/bin/env python3
from datetime import datetime, timezone
import os
import re
from typing import List
import logging
import requests
import sys
import traceback

solarworld_emanagerip = str(sys.argv[1])
from helpermodules.cli import run_using_positional_cli_args

Debug = int(os.environ.get('debug'))
myPid = str(os.getpid())
log = logging.getLogger("Solarworld EVU")


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(solarworld_emanagerip: str):
log.debug('Solarworld IP: ' + solarworld_emanagerip)

# Auslesen eines Solarworl eManagers über die integrierte JSON-API
emanagerantwort = requests.get(
'http://'+solarworld_emanagerip+'/rest/solarworld/lpvm/powerAndBatteryData', timeout=3).json()
try:
em_in_watt = emanagerantwort["PowerIn"]
except:
traceback.print_exc()
exit(1)
try:
em_out_watt = emanagerantwort["PowerOut"]
except:
traceback.print_exc()
exit(1)

if Debug >= 2:
DebugLog('Solarworld IP: ' + solarworld_emanagerip)
# Bezug ist entweder -Out oder In; bei Einspeisung ist 'em_in_watt' immer 0
bezug_watt = int(em_in_watt - em_out_watt)

# Auslesen eines Solarworl eManagers über die integrierte JSON-API
emanagerantwort = requests.get(
'http://'+solarworld_emanagerip+'/rest/solarworld/lpvm/powerAndBatteryData', timeout=5).json()
try:
em_in_watt = emanagerantwort["PowerIn"]
except:
traceback.print_exc()
exit(1)
try:
em_out_watt = emanagerantwort["PowerOut"]
except:
traceback.print_exc()
exit(1)
# wenn eManager aus bzw. keine Antwort ersetze leeren Wert durch eine 0
ra = '^-?[0-9]+$'

# Bezug ist entweder -Out oder In; bei Einspeisung ist 'em_in_watt' immer 0
bezug_watt = int(em_in_watt - em_out_watt)
log.debug('Leistung: ' + str(bezug_watt))
with open("/var/www/html/openWB/ramdisk/wattbezug", "w") as f:
f.write(str(bezug_watt))

# wenn eManager aus bzw. keine Antwort ersetze leeren Wert durch eine 0
ra = '^-?[0-9]+$'

if Debug >= 1:
DebugLog('Leistung: ' + str(bezug_watt))
with open("/var/www/html/openWB/ramdisk/wattbezug", "w") as f:
f.write(str(bezug_watt))

exit(0)
def main(argv: List[str]):
run_using_positional_cli_args(update, argv)
3 changes: 2 additions & 1 deletion modules/wr_solarworld/main.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ fi

openwbDebugLog ${DMOD} 2 "PV IP: ${solarworld_emanagerip}"

python3 /var/www/html/openWB/modules/wr_solarworld/solarworld.py "${solarworld_emanagerip}" >>$MYLOGFILE 2>&1
bash "$OPENWBBASEDIR/packages/legacy_run.sh" "wr_solarworld.solarworld" "${solarworld_emanagerip}" >>$MYLOGFILE 2>&1
ret=$?

openwbDebugLog ${DMOD} 2 "RET: ${ret}"


pvwatt=$(</var/www/html/openWB/ramdisk/pvwatt)
echo $pvwatt
56 changes: 25 additions & 31 deletions modules/wr_solarworld/solarworld.py
Original file line number Diff line number Diff line change
@@ -1,46 +1,40 @@
#!/usr/bin/env python3
from datetime import datetime, timezone
import os
from typing import List
import logging
import re
import requests
import sys
import traceback

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

solarworld_emanagerip = str(sys.argv[1])
log = logging.getLogger("Solarworld 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(solarworld_emanagerip: str):
log.debug('PV Solarworld IP:' + solarworld_emanagerip)

# Auslesen eines Solarworld eManagers über die integrierte JSON-API
emanagerantwort = requests.get(
"http://"+solarworld_emanagerip+"/rest/solarworld/lpvm/powerAndBatteryData", timeout=3).json()

if Debug >= 2:
DebugLog('PV Solarworld IP:' + solarworld_emanagerip)
try:
wr_watt = int(emanagerantwort["PowerTotalPV"])
except:
traceback.print_exc()
exit(1)

# Auslesen eines Solarworld eManagers über die integrierte JSON-API
emanagerantwort = requests.get(
"http://"+solarworld_emanagerip+"/rest/solarworld/lpvm/powerAndBatteryData", timeout=5).json()
# wenn eManager aus bzw. keine Antwort ersetze leeren Wert durch eine 0
ra = '^-?[0-9]+$'

try:
wr_watt = int(emanagerantwort["PowerTotalPV"])
except:
traceback.print_exc()
exit(1)
if re.search(ra, str(wr_watt)) == None:
wr_watt = 0

# wenn eManager aus bzw. keine Antwort ersetze leeren Wert durch eine 0
ra = '^-?[0-9]+$'
# PV ezeugte Leistung muss negativ sein
pvwatt = 0 - wr_watt
log.debug("PV-Leistung: "+str(pvwatt)+" W")
with open("/var/www/html/openWB/ramdisk/pvwatt", "w") as f:
f.write(str(pvwatt))

if re.search(ra, str(wr_watt)) == None:
wr_watt = 0

# PV ezeugte Leistung muss negativ sein
pvwatt = 0 - wr_watt
if Debug >= 1:
DebugLog("PV-Leistung: "+str(pvwatt)+" W")
with open("/var/www/html/openWB/ramdisk/pvwatt", "w") as f:
f.write(str(pvwatt))

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

0 comments on commit f72974f

Please sign in to comment.