From 606bd029677a11077fea6564cef960f391473fd0 Mon Sep 17 00:00:00 2001 From: Bart Koolen Date: Sun, 2 Mar 2025 17:06:26 +0100 Subject: [PATCH] Added Glucose check code Ding toegevoegt zodat je kan aangeven hoelang geleden je hebt gespoten --- src/GlucoseCheck.py | 29 +++++++++++++++++++++++------ src/ServerCheck.py | 18 ++++++++++++------ 2 files changed, 35 insertions(+), 12 deletions(-) diff --git a/src/GlucoseCheck.py b/src/GlucoseCheck.py index e291760..a207a49 100644 --- a/src/GlucoseCheck.py +++ b/src/GlucoseCheck.py @@ -126,16 +126,33 @@ def on_message(client, userdata, msg): #This runs everytime a mqtt message global last_bolus_time global last_bolus_type args = msg.payload.decode() + args_list = args.split(" ") if not args: #Empty string + print("koekwous") return - elif args[0] == "c": #Sets compesation var - last_bolus_type = 0 - elif args[0] == "e": #Sets eating var - last_bolus_type = 1 - last_bolus_time = time.time() + elif args_list[0][0] == "c": #Sets compesation var + if len(args_list) > 1: + try: + last_bolus_time = time.time() - 3600 * float(args_list[1]) + last_bolus_type = 0 + except Exception as e: + Mqtt.publish(send_topic, f"Error: {e}") + else: + last_bolus_type = 0 + last_bolus_time = time.time() + elif args_list[0][0] == "e": #Sets eating var + if len(args_list) > 1: + try: + last_bolus_time = time.time() - 3600 * float(args_list[1]) + last_bolus_type = 1 + except Exception as e: + Mqtt.publish(send_topic, f"Error: {e}") + else: + last_bolus_type = 1 + last_bolus_time = time.time() print("Bolussen") - print(last_bolus_type) + print(last_bolus_time) Mqtt = mqtt.Client(mqtt.CallbackAPIVersion.VERSION2) #Creates a mqqt object Mqtt.on_connect = on_connect #Create callback on connect diff --git a/src/ServerCheck.py b/src/ServerCheck.py index 01caa22..f0f7ca6 100644 --- a/src/ServerCheck.py +++ b/src/ServerCheck.py @@ -35,7 +35,7 @@ class Site: #Custom classes for my dictionaries self.typeVar = typeVar webServers = {"Google" : Site(url="https://google.com", typeVar="URL"), #List with all the servers urls and names and types - "GameServer" : Site(url="http://192.168.1.251", typeVar="URL"), + "GameServer" : Site(url="http://192.168.0.251", typeVar="URL"), "SpiritBody" : Site(url="https://spiritbodyhealing.org", typeVar="URL"), "HeresYourSign": Site(url="https://heresyoursign.nl", typeVar="URL"), #"SMB_server": Site(url="192.168.1.250", typeVar="SMB"), @@ -153,9 +153,9 @@ def on_message(client, userdata, msg): #This runs everytime a mqtt message if User[i].name.lower() == user_topic: print(f"right: {user_topic}: {i}") if User[i].mute > 0: #Removes mute for user - User[keys[0]].mute = 0 - User[keys[1]].mute = 0 - #User[i].mute = 0 + #User[keys[0]].mute = 0 + #User[keys[1]].mute = 0 + User[i].mute = 0 else: User[i].mute = mute_time//interval_offline_message #This mutes for a time elif args[0] == "s": @@ -176,8 +176,14 @@ def main(): #This is the main loop while True: checkWebServer(webServers) #Update list of websites status messageStatus = statusCheck(False) #False is only on state change - if User[keys[0]].mute == 0 | User[keys[1]].mute == 0: # If anyone has muted it wont send message - Mqtt.publish(send_topic + "broadcast", messageStatus) + keys = list(User.keys()) + for i in keys: + if User[i].mute == 0: + print(User[i].name.lower()) + Mqtt.publish(send_topic + User[i].name.lower(), messageStatus) + sleep(1) + #if User[keys[0]].mute == 0 | User[keys[1]].mute == 0: # If anyone has muted it wont send message + # Mqtt.publish(send_topic + "broadcast", messageStatus) sleep(30) if User[keys[0]].mute > 0: #Counts down mute for User 0 User[keys[0]].mute = User[keys[0]].mute - 1