Skip to main content

This is a wrapping class for using paho-mqtt(V2.x) in pyside6.

Project description

This is a wrapping class for using paho-mqtt(V2.x) in pyside6.

History

  • V0.1.0
    • Convert paho-mqtt callbacks to qt signal-slots
    • Add wrapper method for paho-mqtt

Install

pip install PySide6-PahoMqtt

Example

from PySide6.QtWidgets import QApplication, QMainWindow
from PySide6.PahoMqtt import Client

class UI(QMainWindow):
    def __init__(self):
        super().__init__()
        
        self.mqtt = Client()
        self.mqtt.on_connect.connect(self.onConnect)
        self.mqtt.on_connect_fail.connect(self.onConnectFail)
        self.mqtt.on_disconnect.connect(self.onDisconnect)
        self.mqtt.on_publish.connect(self.onPublish)
        self.mqtt.on_subscribe.connect(self.onSubscribe)
        self.mqtt.on_message.connect(self.onMessage)
        self.mqtt.connection("mqtt.eclipseprojects.io")

    def closeEvent(self, event):
        print("Window is closing")
        self.mqtt.disconnection()
        event.accept()
        
    def onConnect(self, connect_flags, reason_code, properties):
        print(f"connect: {connect_flags}, {reason_code}, {properties}")
        
        if reason_code == 0:
            self.mqtt.subscribe("planxlabs/#")
            self.mqtt.publish("planxlabs/test", {"data": "Hello World"})
        else:
            print("fail")
    
    def onConnectFail(self):
        print("connect fail")   
        
    def onDisconnect(self, disconnect_flags, reason_code):
        print(f"disconnect: {disconnect_flags}, {reason_code}")   
                
    def onPublish(self, mid, reason_code):
        print(f"publish: {mid}, {reason_code}")
    
    def onSubscribe(self, mid, reason_code_list):
        print(f"subscribe: {mid}, {reason_code_list}")
    
    def onMessage(self, topic, payload, qos, retain, properties):
        print(f"message: {topic}, {payload}, {qos}, {retain}, {properties}")

if __name__ == "__main__":                            
    app = QApplication([])
    win = UI()
    win.show()
    app.exec()   

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyside6_pahomqtt-0.1.0.tar.gz (3.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

PySide6_PahoMqtt-0.1.0-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

Details for the file pyside6_pahomqtt-0.1.0.tar.gz.

File metadata

  • Download URL: pyside6_pahomqtt-0.1.0.tar.gz
  • Upload date:
  • Size: 3.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.13.0

File hashes

Hashes for pyside6_pahomqtt-0.1.0.tar.gz
Algorithm Hash digest
SHA256 b077384fb3c0acfacccf6847e7436c7b10ed2cd46bc19a59cec5979b83e8684f
MD5 b950a0e3ffe0898dc3cb84be8b4f28b2
BLAKE2b-256 d1cb48a5c31245615c2d14163dfa0e4fba4a1b78c3e1aff5ba7c78eb36a2f258

See more details on using hashes here.

File details

Details for the file PySide6_PahoMqtt-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for PySide6_PahoMqtt-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b2952878b9498da65421ed8dd3a52dd499c68620392b7a7197bed74be731afcb
MD5 319852e47587474bdde8a8df476d6fc9
BLAKE2b-256 2de73a7c8b93e7de0baa7c2f8e440a4f4329646e1377ebf6603e8f0dfd624573

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page