Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add files via upload
# 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
def on_connect(client, userdata, flags, rc):
    if rc == 0:
        print("Connected to MQTT broker")
        client.subscribe(energy_topic)
        client.subscribe(temperature_topic)
    else:
        print(f"Failed to connect, return code {rc}")
  • Loading branch information
kaurm105 committed Jul 31, 2024
1 parent 74693d9 commit 57dda48
Showing 1 changed file with 0 additions and 0 deletions.
Binary file added Screenshot 2024-07-30 144825.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 57dda48

Please sign in to comment.