From 49928c13e93f1b05579ac14bc71166833df0d5e7 Mon Sep 17 00:00:00 2001
From: "Lovepreet Kaur (lovepre21)" <lovepre21@coventry.ac.uk>
Date: Thu, 1 Aug 2024 12:51:59 +0100
Subject: [PATCH] Create Lovepreet Individual contribution

---
 Lovepreet Individual contribution | 37 +++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)
 create mode 100644 Lovepreet Individual contribution

diff --git a/Lovepreet Individual contribution b/Lovepreet Individual contribution
new file mode 100644
index 0000000..4afa32f
--- /dev/null
+++ b/Lovepreet Individual contribution	
@@ -0,0 +1,37 @@
+# Publisher function for energy
+def publish_energy_data(client):
+    while True:
+        energy_usage = random.uniform(0.5, 2.0)  # Simulate energy usage in kWh
+        message = f"{energy_usage:.2f}"
+        client.publish(energy_topic, message)
+        print(f"Published Energy: {message} kWh")
+        time.sleep(5)  # Publish every 5 seconds
+
+
+
+# Subscriber callback
+def on_message(client, userdata, message):
+    topic = message.topic
+    payload = message.payload.decode()
+    if topic == energy_topic:
+        energy_usage = float(payload)
+        print(f"Received Energy: {energy_usage} kWh")
+        if energy_usage > 1.5:
+            print("High energy usage detected! Turning off non-essential devices.")
+        else:
+            print("Energy usage is within the normal range.")
+    elif topic == temperature_topic:
+        temperature = float(payload)
+        print(f"Received Temperature: {temperature} °C")
+        # Add any specific handling for temperature data here ( manraj preet and lovepreet (me) ) worked together on this topic
+
+
+
+
+
+# Run the publisher functions in separate threads
+energy_thread = threading.Thread(target=publish_energy_data, args=(publisher_client,))
+temperature_thread = threading.Thread(target=publish_temperature_data, args=(publisher_client,))
+
+energy_thread.start()
+temperature_thread.start()