From 183a869a8e2ed07c7c0091240760b2608e14b115 Mon Sep 17 00:00:00 2001 From: Dave Locke <34027679+lockedj@users.noreply.github.com> Date: Fri, 1 Jul 2022 15:41:43 +0100 Subject: [PATCH] Add pause between inverter read cycles --- GivTCP/read.py | 23 ++++++++++++----------- GivTCP/settings_template.py | 4 +++- GivTCP/startup.sh | 8 ++++---- README.md | 3 ++- 4 files changed, 21 insertions(+), 17 deletions(-) diff --git a/GivTCP/read.py b/GivTCP/read.py index 5515f0c2..5ac8dcae 100644 --- a/GivTCP/read.py +++ b/GivTCP/read.py @@ -447,20 +447,21 @@ def self_run(loop_timer): time.sleep(1) def self_run2(): - counter=0 - runAll(True) + counter = 0 + fullrefresh = True while True: - counter=counter+1 + runAll(fullrefresh) + counter = counter + 1 if exists(".forceFullRefresh"): - runAll(True) + fullrefresh = True os.remove(".forceFullRefresh") - counter=0 - elif counter==20: - counter=0 - runAll(True) + counter = 0 + elif counter == 20: + counter = 0 + fullrefresh = True else: - runAll(False) - time.sleep(1) + fullrefresh = False + time.sleep(int(GiV_Settings.selfRunLoopTimer)) ####### Addiitonal Publish options can be added here. @@ -541,4 +542,4 @@ def iterate_dict(array): # Create a publish safe version of the output (c if len(sys.argv)==2: globals()[sys.argv[1]]() elif len(sys.argv)==3: - globals()[sys.argv[1]](sys.argv[2]) + globals()[sys.argv[1]](sys.argv[2]) \ No newline at end of file diff --git a/GivTCP/settings_template.py b/GivTCP/settings_template.py index 9a4551ce..02a01cda 100644 --- a/GivTCP/settings_template.py +++ b/GivTCP/settings_template.py @@ -19,4 +19,6 @@ class GiV_Settings: influxURL="http://localhost:8086" influxToken="" influxBucket="GivEnergy" - influxOrg="GivTCP" \ No newline at end of file + influxOrg="GivTCP" +#Other settings + selfRunLoopTimer = "10" # Time in seconds to pause between inverter read cycles \ No newline at end of file diff --git a/GivTCP/startup.sh b/GivTCP/startup.sh index fca9721a..e68326ee 100644 --- a/GivTCP/startup.sh +++ b/GivTCP/startup.sh @@ -23,7 +23,8 @@ then rm $FILE3 #delete file and re-create fi -if [ -z "$INVERTOR_IP" ]; then +if [ -z "$INVERTOR_IP" ] +then echo 'IP not set in ENV' for i in 1 2 3 do @@ -64,6 +65,7 @@ printf " influxToken=\"$INFLUX_TOKEN\"\n" >> $FILE printf " influxBucket=\"$INFLUX_BUCKET\"\n" >> $FILE printf " influxOrg=\"$INFLUX_ORG\"\n" >> $FILE printf " HA_Auto_D=$HA_AUTO_D\n" >> $FILE +printf " selfRunLoopTimer=\"$SELF_RUN_LOOP_TIMER\"\n" >>$FILE printf " first_run= True\n" >> $FILE #TODO Update givTCP if a newer release is available @@ -88,6 +90,4 @@ fi GUPORT=$(($GIVTCPINSTANCE+6344)) echo Starting Gunicorn on port "$GUPORT" -gunicorn -w 3 -b :"$GUPORT" GivTCP.REST:giv_api #Use for on-demand read and control - - +gunicorn -w 3 -b :"$GUPORT" GivTCP.REST:giv_api #Use for on-demand read and control \ No newline at end of file diff --git a/README.md b/README.md index d1f21506..42f14ca6 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,7 @@ From here your invertor data is available through either MQTT or REST as describ | ENV Name | Example | Description | | ----------------------- | ------------- | -------------------------------- | | INVERTOR_IP |192.168.10.1 | Docker container can auto detect Invertors if running on your host network. If this fails then add the IP manually to this ENV | -| NUMBATTERIES | 1 | Number of battery units connected to the invertor | +| NUM_BATTERIES | 1 | Number of battery units connected to the invertor | | MQTT_OUTPUT | True | Optional if set to True then MQTT_ADDRESS is required | | MQTT_ADDRESS | 127.0.0.1 | Optional (but required if OUTPUT is set to MQTT) | | MQTT_USERNAME | bob | Optional | @@ -55,6 +55,7 @@ From here your invertor data is available through either MQTT or REST as describ | INFLUX_BUCKET |giv_bucket| Optional - If using influx this is data bucket to use| | INFLUX_ORG |giv_tcp| Optional - If using influx this is the org that the token is assigned to | | HA_AUTO_D | True | Optional - If set to true and MQTT is enabled, it will publish Home Assistant Auto Discovery messages, which will allow Home Assistant to automagically create all entitites and devices to allow read and control of your Invertor | +| SELF_RUN_LOOP_TIMER |10| Time in seconds to pause between inverter read cycles | ## GivTCP Read data