Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
BTSASS_SE/leo benny reporting and blocking.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
34 lines (25 sloc)
826 Bytes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import paho.mqtt.client as mqtt | |
# Define the callback functions | |
def on_connect(client, userdata, flags, rc): | |
if rc == 0: | |
print("Connected to broker") | |
else: | |
print(f"Connection failed with code {rc}") | |
def on_message(client, userdata, message): | |
print(f"Received message: {message.payload.decode()}") | |
# Create an MQTT client | |
client = mqtt.Client() | |
# Set the callback functions | |
client.on_connect = on_connect | |
client.on_message = on_message | |
# Set the broker and port | |
broker_address = "broker.hivemq.com" | |
port = 8883 | |
# Connect to the broker | |
client.connect(broker_address, port) | |
# Subscribe to the "blocking" topic | |
client.subscribe("blocking") | |
# Publish a report message | |
client.publish("report", "Blocked user: user123") | |
# Start the MQTT loop | |
client.loop_forever() |