MqttMonitor/MqttClient.py

branch
eric7
changeset 105
36ec7431ad04
parent 104
9a4c9b7f078c
child 114
8c0e9e602124
equal deleted inserted replaced
104:9a4c9b7f078c 105:36ec7431ad04
5 5
6 """ 6 """
7 Module implementing a PyQt wrapper around the paho MQTT client. 7 Module implementing a PyQt wrapper around the paho MQTT client.
8 """ 8 """
9 9
10 import enum
11
12 from PyQt6.QtCore import ( 10 from PyQt6.QtCore import (
13 pyqtSignal, pyqtSlot, QObject, QCoreApplication, QTimer 11 pyqtSignal, pyqtSlot, QObject, QCoreApplication, QTimer
14 ) 12 )
15 13
16 import paho.mqtt.client as mqtt 14 import paho.mqtt.client as mqtt
17 from paho.mqtt.packettypes import PacketTypes 15 from paho.mqtt.packettypes import PacketTypes
18 from paho.mqtt.properties import Properties 16 from paho.mqtt.properties import Properties
19 17
20 from Utilities.crypto import pwConvert 18 from Utilities.crypto import pwConvert
21 19
22 20 from .MqttProtocols import MqttProtocols
23 class MqttProtocols(enum.IntEnum):
24 """
25 Class defining the supported MQTT protocol versions.
26 """
27 MQTTv31 = mqtt.MQTTv31
28 MQTTv311 = mqtt.MQTTv311
29 MQTTv5 = mqtt.MQTTv5
30 21
31 22
32 class MqttClient(QObject): 23 class MqttClient(QObject):
33 """ 24 """
34 Class implementing a PyQt wrapper around the paho MQTT client. 25 Class implementing a PyQt wrapper around the paho MQTT client.
487 self.connectToServer(host, port=port, 478 self.connectToServer(host, port=port,
488 keepalive=parametersDict["Keepalive"], 479 keepalive=parametersDict["Keepalive"],
489 properties=properties, 480 properties=properties,
490 clearWill=clearWill) 481 clearWill=clearWill)
491 else: 482 else:
492 keepalive = self.defaultConnectionOptions["Keepalive"] 483 keepalive = self.defaultConnectionOptions()["Keepalive"]
493 self.connectToServer(host, port=port, keepalive=keepalive, 484 self.connectToServer(host, port=port, keepalive=keepalive,
494 bindAddress=bindAddress, 485 bindAddress=bindAddress,
495 clearWill=clearWill) 486 clearWill=clearWill)
496 487
497 @classmethod 488 @classmethod
505 "CleanSession", "Username", "Password", "WillTopic", "WillMessage", 496 "CleanSession", "Username", "Password", "WillTopic", "WillMessage",
506 "WillQos", "WillRetain", "WillProperties", "TlsEnable", 497 "WillQos", "WillRetain", "WillProperties", "TlsEnable",
507 "TlsCaCert", "TlsClientCert", "TlsClientKey", "UserProperties". 498 "TlsCaCert", "TlsClientCert", "TlsClientKey", "UserProperties".
508 @rtype dict 499 @rtype dict
509 """ 500 """
501 from PluginMqttMonitor import mqttPluginObject
502
510 return { 503 return {
511 "ClientId": "ERIC7_MQTT_MONITOR_CLIENT", 504 "ClientId": "ERIC7_MQTT_MONITOR_CLIENT",
512 "Protocol": MqttProtocols.MQTTv311, 505 "Protocol": mqttPluginObject.getPreferences("DefaultProtocol"),
513 "ConnectionTimeout": MqttClient.DefaultConnectTimeout, 506 "ConnectionTimeout": MqttClient.DefaultConnectTimeout,
514 "Keepalive": 60, 507 "Keepalive": 60,
515 "CleanSession": True, 508 "CleanSession": True,
516 "Username": "", 509 "Username": "",
517 "Password": "", 510 "Password": "",

eric ide

mercurial