Skip to content

Commit

Permalink
fix wr_json für einschlafende WR
Browse files Browse the repository at this point in the history
WR liefert kein numerisches Ergebnis.
  • Loading branch information
DetMoerk committed Sep 27, 2021
1 parent 4ee5ba0 commit 23f9d32
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions modules/wr_json/read_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@
import sys
import traceback
import jq
import re
from datetime import datetime, timezone
import os

Debug = int(os.environ.get('debug'))
myPid = str(os.getpid())


renumeric ='^-?[0-9]+$'

jsonurl = str(sys.argv[1])

jsonwatt = str(sys.argv[2])
Expand All @@ -22,7 +26,7 @@ def DebugLog(message):
local_time = datetime.now(timezone.utc).astimezone()
print(local_time.strftime(format = "%Y-%m-%d %H:%M:%S") + ": PID: "+ myPid +": " + message)


numcheck = re.compile(renumeric)

if Debug >= 2:
DebugLog('PV' + str(numpv) + ' JQ Watt: ' + jsonwatt)
Expand All @@ -32,16 +36,23 @@ def DebugLog(message):

response = requests.get(jsonurl, timeout=5).json()
if Debug>=2:
DebugLog('JSON Response: ' + str(response))
DebugLog('JSON Response: ' + str(response))
try:
watt = jq.compile(jsonwatt).input(response).first()
if Debug>=1:
DebugLog('Leistung: ' + str(watt))
if not numcheck.match(str(watt)):
DebugLog('Leistung (Watt) nicht numerisch. Bitte Filterausdruck ueberpruefen -->0')
watt=0

watt=int(watt)
if watt >= 0:
watt = watt*(-1)
if numpv == 1:
with open(RAMDISKDIR + "pvwatt", "w") as f:
f.write(str(watt))
else:
DebugLog(RAMDISKDIR + "pv" + str(numpv) + "watt"+ "W:"+str(watt))
with open(RAMDISKDIR + "pv" + str(numpv) + "watt" , "w") as f:
f.write(str(watt))
except:
Expand Down

0 comments on commit 23f9d32

Please sign in to comment.