forked from snaptec/openWB
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
56 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |