import paho.mqtt.client as mqtt
# Callback function for when the client connects to the broker
def on_connect(client, userdata, flags, rc):
if rc == 0:
print("Connected successfully")
else:
print(f"Failed to connect, return code {rc}")
# Callback function for when a message is received
def on_message(client, userdata, msg):
print(f"Received message: {msg.topic} - {msg.payload.decode()}")
# Create a new MQTT client instance
client = mqtt.Client()
# Set the username and password
client.username_pw_set("XX", "")
# Assign the callback functions
client.on_connect = on_connect
client.on_message = on_message
# Connect to the MQTT broker
client.connect(