Frontend weiterarbeit, Client Server datenaustausch und sync, fertiggestellt.

This commit is contained in:
2024-04-19 16:48:23 +02:00
parent 04ad35a91f
commit cd2f302eb1
11 changed files with 228 additions and 112 deletions

View File

@@ -31,7 +31,16 @@ def calcSomeStuff():
while True:
# Neue Konfig holen
config = json.dumps(serverrequests.get_config(ID))
try:
config = json.dumps(serverrequests.get_config(ID))
# Versuche, das JSON zu laden
except:
# Falls ein Fehler auftritt oder kein JSON zurückkommt, lade config.json
with open('config.json', 'r') as file:
config = json.dumps(json.load(file))
if JsonHandling.JsonHandling.check_config_has_changed(config):
producers = energyproducer.EnergyProducer.create_producerlist_from_json(config)
@@ -48,10 +57,17 @@ while True:
main.EnergyUserFactory.distribute_energy(users, -1*(meter_values["Meter_Sum"]["PowerReal_P_Sum"]))
user_values = energyuser.EnergyUser.get_all_current_values(users)
Collector.collect_and_store_data(producer_values, meter_values, user_values)
try:
a = json.loads(config)['last_timestamp']
except:
a = "1970-01-01 00:00"
Collector.collect_and_store_data(producer_values, meter_values, user_values, a)
data = Collector.data
serverrequests.set_data(ID, data)
try:
if next(iter(data)) != a:
serverrequests.set_data(ID, data)
except:
pass
time.sleep(5)