Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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