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.2.x
    • Modity signal-slots type
    • Remote del
  • V0.1.x
    • 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.connect("127.0.0.1")

    def closeEvent(self, event):
        print("Window is closing")
        self.mqtt.disconnect()
        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.2.2.tar.gz (3.3 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.2.2-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pyside6_pahomqtt-0.2.2.tar.gz
  • Upload date:
  • Size: 3.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for pyside6_pahomqtt-0.2.2.tar.gz
Algorithm Hash digest
SHA256 0f5779ce9082e23a11ac2a8b37a6a0217c2a54a2c172c4441959018946506098
MD5 bb2660d7eb5dc9ced8cca14f5dd6c359
BLAKE2b-256 33f3638d9946f15ec953e733722f28e239a6d0b42a91e74e9bf8d4507b374ef5

See more details on using hashes here.

File details

Details for the file pyside6_pahomqtt-0.2.2-py3-none-any.whl.

File metadata

File hashes

Hashes for pyside6_pahomqtt-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 46214a84455b168068c08125112803779beeddcde60e28450880166200b8ac0c
MD5 a8e4e30dfe094f9acb39604ad33b539e
BLAKE2b-256 df993e69bb49832184860fe451fe67dd29e50586d5d2cbb6b4d02d2c15e1f9f1

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