Skip to content

Commit

Permalink
1.1.7
Browse files Browse the repository at this point in the history
  • Loading branch information
britkat1980 committed Aug 24, 2022
1 parent 4071959 commit a6d0f76
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 28 deletions.
6 changes: 6 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ ENV TZ="Europe/London"
ENV WEB_DASH=False
ENV WEB_DASH_PORT=3000

ENV SMARTTARGET=True
ENV GEAPI=""
ENV SOLCASTAPI=""
ENV SOLCASTSITEID=""


EXPOSE 6345 1883 3000

CMD ["python3", "/app/startup.py"]
21 changes: 11 additions & 10 deletions GivTCP/read.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
regcache="/config/GivTCP/regCache_"+str(GiV_Settings.givtcp_instance)+".pkl"
ratedata="/config/GivTCP/rateData_"+str(GiV_Settings.givtcp_instance)+".pkl"
lastupdate="/config/GivTCP/lastUpdate_"+str(GiV_Settings.givtcp_instance)+".pkl"
forcefullrefresh="/config/GivTCP/.forceFullRefresh_"+str(GiV_Settings.givtcp_instance)

def getData(fullrefresh): #Read from Invertor put in cache
plant=Plant(number_batteries=int(GiV_Settings.numBatteries))
Expand Down Expand Up @@ -116,11 +117,6 @@ def getData(fullrefresh): #Read from Invertor put in cache
raw["batteries"]=batteries
multi_output['raw']=raw

#Grab previous data from Pickle and validate any outrageous changes
if exists(regcache): # if there is a cache then grab it
with open(regcache, 'rb') as inp:
multi_output_old= pickle.load(inp)

try:
#Total Energy Figures
logger.info("Getting Total Energy Data")
Expand Down Expand Up @@ -155,11 +151,15 @@ def getData(fullrefresh): #Read from Invertor put in cache
checksum=0
for item in energy_today_output:
checksum=checksum+energy_today_output[item]
if checksum==0 and GEInv.system_time.hour==0 and GEInv.system_time.minute==0:
if checksum==0 and GEInv.system_time.hour==0 and GEInv.system_time.minute==0 and exists(regcache):
#remove regcache at midnight
logger.error("Energy Today is Zero and its midnight so removing regCache")
logger.critical("Energy Today is Zero and its midnight so resetting regCache")
os.remove(regcache)

#Grab previous data from Pickle and use it validate any outrageous changes
if exists(regcache): # if there is a cache then grab it
with open(regcache, 'rb') as inp:
multi_output_old= pickle.load(inp)

############ Core Power Stats ############

Expand Down Expand Up @@ -340,7 +340,8 @@ def getData(fullrefresh): #Read from Invertor put in cache
#Perform rate calcs

energy["Rates"]=ratecalcs(GEInv.e_grid_in_total)
energy["Rates"]['Average_ppkwh_today']=(energy["Rates"]['day_cost']+energy["Rates"]['night_cost'])/(energy['Today']['Load_Energy_Today_kWh'])
if (energy['Today']['Load_Energy_Today_kWh'])!=0:
energy["Rates"]['Average_ppkwh_today']=(energy["Rates"]['day_cost']+energy["Rates"]['night_cost'])/(energy['Today']['Load_Energy_Today_kWh'])

multi_output["Energy"]=energy

Expand Down Expand Up @@ -534,9 +535,9 @@ def self_run2():
runAll("True")
while True:
counter=counter+1
if exists(".forceFullRefresh"):
if exists(forcefullrefresh):
runAll("True")
os.remove(".forceFullRefresh")
os.remove(forcefullrefresh)
counter=0
elif counter==20:
counter=0
Expand Down
32 changes: 17 additions & 15 deletions GivTCP/write.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
from settings import GiV_Settings
from givenergy_modbus.client import GivEnergyClient

forcefullrefresh="/config/GivTCP/.forceFullRefresh_"+str(GiV_Settings.givtcp_instance)

if GiV_Settings.Log_Level.lower()=="debug":
if GiV_Settings.Debug_File_Location=="":
logging.basicConfig(level=logging.DEBUG, format="%(asctime)s - %(name)s [%(levelname)s] %(message)s", handlers=[logging.StreamHandler()])
Expand Down Expand Up @@ -36,7 +38,7 @@ def enableChargeTarget(payload):
elif payload['state']=="disable":
GivEnergyClient(host=GiV_Settings.invertorIP).disable_charge_target()
temp['result']="Setting Charge Target was a success"
open(".forceFullRefresh", 'w').close()
open(forcefullrefresh, 'w').close()
except:
e = sys.exc_info()
temp['result']="Setting Charge Target failed: " + str(e)
Expand All @@ -51,7 +53,7 @@ def enableChargeSchedule(payload):
elif payload['state']=="disable":
GivEnergyClient(host=GiV_Settings.invertorIP).disable_charge()
temp['result']="Setting Charge Enable was a success"
open(".forceFullRefresh", 'w').close()
open(forcefullrefresh, 'w').close()
except:
e = sys.exc_info()
temp['result']="Setting Charge Enable failed: " + str(e)
Expand All @@ -66,7 +68,7 @@ def enableDischargeSchedule(payload):
elif payload['state']=="disable":
GivEnergyClient(host=GiV_Settings.invertorIP).disable_discharge()
temp['result']="Setting Charge Enable was a success"
open(".forceFullRefresh", 'w').close()
open(forcefullrefresh, 'w').close()
except:
e = sys.exc_info()
temp['result']="Setting Charge Enable failed: " + str(e)
Expand All @@ -78,7 +80,7 @@ def setShallowCharge(payload):
try:
GivEnergyClient(host=GiV_Settings.invertorIP).set_shallow_charge(int(payload['val']))
temp['result']="Setting Charge Enable was a success"
open(".forceFullRefresh", 'w').close()
open(forcefullrefresh, 'w').close()
except:
e = sys.exc_info()
temp['result']="Setting Charge Enable failed: " + str(e)
Expand All @@ -93,7 +95,7 @@ def enableDischarge(payload):
elif payload['state']=="disable":
GivEnergyClient(host=GiV_Settings.invertorIP).set_shallow_charge(100)
temp['result']="Setting Discharge Enable was a success"
open(".forceFullRefresh", 'w').close()
open(forcefullrefresh, 'w').close()
except:
e = sys.exc_info()
temp['result']="Setting Discharge Enable failed: " + str(e)
Expand All @@ -108,7 +110,7 @@ def setChargeTarget(payload):
client=GivEnergyClient(host=GiV_Settings.invertorIP)
client.enable_charge_target(target)
temp['result']="Setting Charge Target was a success"
open(".forceFullRefresh", 'w').close()
open(forcefullrefresh, 'w').close()
except:
e = sys.exc_info()
temp['result']="Setting Charge Target failed: " + str(e)
Expand All @@ -125,7 +127,7 @@ def setBatteryReserve(payload):
try:
GivEnergyClient(host=GiV_Settings.invertorIP).set_battery_power_reserve(target)
temp['result']="Setting Battery Reserve was a success"
open(".forceFullRefresh", 'w').close()
open(forcefullrefresh, 'w').close()
except:
e = sys.exc_info()
temp['result']="Setting Battery Reserve failed: " + str(e)
Expand All @@ -144,7 +146,7 @@ def setChargeRate(payload):
try:
GivEnergyClient(host=GiV_Settings.invertorIP).set_battery_charge_limit(target)
temp['result']="Setting Charge Rate was a success"
open(".forceFullRefresh", 'w').close()
open(forcefullrefresh, 'w').close()
except:
e = sys.exc_info()
temp['result']="Setting Charge Rate failed: " + str(e)
Expand All @@ -164,7 +166,7 @@ def setDischargeRate(payload):
try:
GivEnergyClient(host=GiV_Settings.invertorIP).set_battery_discharge_limit(target)
temp['result']="Setting Discharge Rate was a success"
open(".forceFullRefresh", 'w').close()
open(forcefullrefresh, 'w').close()
except:
e = sys.exc_info()
temp['result']="Setting Discharge Rate failed: " + str(e)
Expand All @@ -183,7 +185,7 @@ def setChargeSlot1(payload):
try:
client.set_charge_slot_1((datetime.strptime(payload['start'],"%H:%M"),datetime.strptime(payload['finish'],"%H:%M")))
temp['result']="Setting Charge Slot 1 was a success"
open(".forceFullRefresh", 'w').close()
open(forcefullrefresh, 'w').close()
except:
e = sys.exc_info()
temp['result']="Setting Charge Slot 1 failed: " + str(e)
Expand All @@ -201,7 +203,7 @@ def setChargeSlot2(payload):
try:
client.set_charge_slot_2((datetime.strptime(payload['start'],"%H:%M"),datetime.strptime(payload['finish'],"%H:%M")))
temp['result']="Setting Charge Slot 2 was a success"
open(".forceFullRefresh", 'w').close()
open(forcefullrefresh, 'w').close()
except:
e = sys.exc_info()
temp['result']="Setting Charge Slot 2 failed: " + str(e)
Expand All @@ -219,7 +221,7 @@ def setDischargeSlot1(payload):
try:
client.set_discharge_slot_1((datetime.strptime(payload['start'],"%H:%M"),datetime.strptime(payload['finish'],"%H:%M")))
temp['result']="Setting Discharge Slot 1 was a success"
open(".forceFullRefresh", 'w').close()
open(forcefullrefresh, 'w').close()
except:
e = sys.exc_info()
temp['result']="Setting Discharge Slot 1 failed: " + str(e)
Expand All @@ -237,7 +239,7 @@ def setDischargeSlot2(payload):
try:
client.set_discharge_slot_2((datetime.strptime(payload['start'],"%H:%M"),datetime.strptime(payload['finish'],"%H:%M")))
temp['result']="Setting Discharge Slot 2 was a success"
open(".forceFullRefresh", 'w').close()
open(forcefullrefresh, 'w').close()
except:
e = sys.exc_info()
temp['result']="Setting Discharge Slot 2 failed: " + str(e)
Expand All @@ -264,7 +266,7 @@ def setBatteryMode(payload):
temp['result']="Invalid Mode requested"
return json.dumps(temp)
temp['result']="Setting Battery Mode was a success"
open(".forceFullRefresh", 'w').close()
open(forcefullrefresh, 'w').close()
except:
e = sys.exc_info()
temp['result']="Setting Battery Mode failed: " + str(e)
Expand All @@ -281,7 +283,7 @@ def setDateTime(payload):
#Set Date and Time on Invertor
GivEnergyClient(host=GiV_Settings.invertorIP).set_datetime(iDateTime)
temp['result']="Invertor time setting was a success"
open(".forceFullRefresh", 'w').close()
open(forcefullrefresh, 'w').close()
except:
e = sys.exc_info()
temp['result']="Setting Battery Mode failed: " + str(e)
Expand Down
4 changes: 2 additions & 2 deletions buildx.bat
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
::docker buildx build --platform linux/amd64,linux/arm64,linux/arm/v7,linux/arm/v6 -t britkat/giv_tcp-ma:dev --push .
docker buildx build --platform linux/amd64,linux/arm64,linux/arm/v7,linux/arm/v6 -t britkat/giv_tcp-ma:latest -t britkat/giv_tcp-ma:1.1.7 --push .
docker buildx build --platform linux/amd64,linux/arm64,linux/arm/v7,linux/arm/v6 -t britkat/giv_tcp-ma:palmtest --push .
::docker buildx build --platform linux/amd64,linux/arm64,linux/arm/v7,linux/arm/v6 -t britkat/giv_tcp-ma:latest -t britkat/giv_tcp-ma:1.1.7 --push .
13 changes: 12 additions & 1 deletion startup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from time import sleep
import logging
import shutil, shlex
import schedule

logging.basicConfig(level=logging.CRITICAL, format="%(asctime)s %(name)s - %(message)s", handlers=[logging.StreamHandler()])
logger = logging.getLogger("GivTCP_STARTUP")
Expand All @@ -16,6 +17,9 @@

# Check if config firectory exists and creates it if not

def job():
import GivTCP.palm_soc

if not os.path.exists('/config/GivTCP'):
os.makedirs('/config/GivTCP')
logger.critical("No config directory exists, so creating it...")
Expand Down Expand Up @@ -109,7 +113,11 @@
if os.getenv('MQTT_ADDRESS')=="127.0.0.1" and os.getenv('MQTT_OUTPUT')=="True":
logger.critical ("Starting Mosquitto on port "+str(os.getenv('MQTT_PORT')))
mqttBroker=subprocess.Popen(["/usr/sbin/mosquitto", "-c",PATH+"/mqtt.conf"])


#if str(os.getenv('SMARTTARGET'))==True:
# starttime=os.getenv('NIGHTRATESTART')
# schedule.every().day.at(starttime).do(job)

# Loop round checking all processes are running
while True:
for inv in range(1,int(os.getenv('NUMINVERTORS'))+1):
Expand Down Expand Up @@ -143,4 +151,7 @@
os.chdir(PATH)
logger.critical ("Starting Mosquitto on port "+str(os.getenv('MQTT_PORT')))
mqttBroker=subprocess.Popen(["/usr/sbin/mosquitto", "-c",PATH+"/mqtt.conf"])

#check if we need to run the smart target code
# schedule.run_pending()
sleep (60)

0 comments on commit a6d0f76

Please sign in to comment.