Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import paho.mqtt.publish as publish
- import tkinter.scrolledtext as tkst
- import paho.mqtt.subscribe as subscribe
- import paho.mqtt.client as mqtt
- import datetime
- class Mqtt_handler(object):
- def __init__(self,client_id,password,username):
- self.client = None
- self.client_id = client_id
- self.password = password
- self.username = username
- def log_me_in(self):
- print("I will try to login omg niggers")
- print(self.client_id, self.password, self.username)
- self.client = mqtt.Client(client_id=self.client_id)
- self.client.on_connect = self.on_connect
- self.client.on_message = self.on_message
- try:
- self.client.username_pw_set(self.username, password=self.password)
- self.client.connect("pcfeib425t", 1883, 60)
- self.client.loop_start()
- except TimeoutError:
- print("Connection timeout. Remote MQTT broker is currently unavailable. Check whether the broker is running.")
- exit(0)
- @staticmethod
- def on_connect(client, userdata, flags, rc):
- print("Connected with result code "+str(rc))
- # Subscribing in on_connect() means that if we lose the connection and
- # reconnect then subscriptions will be renewed.
- client.subscribe("/mschat/all/#")
- # The callback for when a PUBLISH message is received from the server.
- @staticmethod
- def on_message(self, userdata, msg):
- #app.printOutMessages(msg.topic+" "+str(msg.payload))
- print(msg.topic+" "+str(msg.payload))
Add Comment
Please, Sign In to add comment