@@ -75,6 +75,7 @@ class MMQTTException(Exception):
75
75
# Legacy ESP32SPI Socket API
76
76
def set_socket (sock , iface = None ):
77
77
"""Legacy API for setting the socket and network interface.
78
+
78
79
:param sock: socket object.
79
80
:param iface: internet interface object
80
81
@@ -116,6 +117,7 @@ def wrap_socket(self, socket, server_hostname=None):
116
117
117
118
class MQTT :
118
119
"""MQTT Client for CircuitPython.
120
+
119
121
:param str broker: MQTT Broker URL or IP Address.
120
122
:param int port: Optional port definition, defaults to 8883.
121
123
:param str username: Username for broker authentication.
@@ -209,6 +211,7 @@ def __init__(
209
211
# pylint: disable=too-many-branches
210
212
def _get_connect_socket (self , host , port , * , timeout = 1 ):
211
213
"""Obtains a new socket and connects to a broker.
214
+
212
215
:param str host: Desired broker hostname
213
216
:param int port: Desired broker port
214
217
:param int timeout: Desired socket timeout
@@ -409,6 +412,7 @@ def _handle_on_message(self, client, topic, message):
409
412
410
413
def username_pw_set (self , username , password = None ):
411
414
"""Set client's username and an optional password.
415
+
412
416
:param str username: Username to use with your MQTT broker.
413
417
:param str password: Password to use with your MQTT broker.
414
418
@@ -422,6 +426,7 @@ def username_pw_set(self, username, password=None):
422
426
# pylint: disable=too-many-branches, too-many-statements, too-many-locals
423
427
def connect (self , clean_session = True , host = None , port = None , keep_alive = None ):
424
428
"""Initiates connection with the MQTT Broker.
429
+
425
430
:param bool clean_session: Establishes a persistent session.
426
431
:param str host: Hostname or IP address of the remote broker.
427
432
:param int port: Network port of the remote broker.
@@ -563,6 +568,7 @@ def ping(self):
563
568
# pylint: disable=too-many-branches, too-many-statements
564
569
def publish (self , topic , msg , retain = False , qos = 0 ):
565
570
"""Publishes a message to a topic provided.
571
+
566
572
:param str topic: Unique topic identifier.
567
573
:param str,int,float,bytes msg: Data to send to the broker.
568
574
:param bool retain: Whether the message is saved by the broker.
@@ -706,6 +712,7 @@ def subscribe(self, topic, qos=0):
706
712
707
713
def unsubscribe (self , topic ):
708
714
"""Unsubscribes from a MQTT topic.
715
+
709
716
:param str,list topic: Unique MQTT topic identifier string or list.
710
717
711
718
"""
@@ -754,6 +761,7 @@ def unsubscribe(self, topic):
754
761
755
762
def reconnect (self , resub_topics = True ):
756
763
"""Attempts to reconnect to the MQTT broker.
764
+
757
765
:param bool resub_topics: Resubscribe to previously subscribed topics.
758
766
759
767
"""
@@ -777,6 +785,7 @@ def loop(self, timeout=1):
777
785
"""Non-blocking message loop. Use this method to
778
786
check incoming subscription messages.
779
787
Returns response codes of any messages received.
788
+
780
789
:param int timeout: Socket timeout, in seconds.
781
790
782
791
"""
@@ -884,6 +893,7 @@ def _sock_exact_recv(self, bufsize):
884
893
terms of the minimum size of the buffer, which could be 1 byte. This is a
885
894
wrapper for socket recv() to ensure that no less than the expected number of
886
895
bytes is returned or trigger a timeout exception.
896
+
887
897
:param int bufsize: number of bytes to receive
888
898
889
899
"""
@@ -920,6 +930,7 @@ def _sock_exact_recv(self, bufsize):
920
930
921
931
def _send_str (self , string ):
922
932
"""Encodes a string and sends it to a socket.
933
+
923
934
:param str string: String to write to the socket.
924
935
925
936
"""
@@ -933,6 +944,7 @@ def _send_str(self, string):
933
944
@staticmethod
934
945
def _valid_topic (topic ):
935
946
"""Validates if topic provided is proper MQTT topic format.
947
+
936
948
:param str topic: Topic identifier
937
949
938
950
"""
@@ -948,6 +960,7 @@ def _valid_topic(topic):
948
960
@staticmethod
949
961
def _valid_qos (qos_level ):
950
962
"""Validates if the QoS level is supported by this library
963
+
951
964
:param int qos_level: Desired QoS level.
952
965
953
966
"""
@@ -968,6 +981,7 @@ def is_connected(self):
968
981
# Logging
969
982
def enable_logger (self , logger , log_level = 20 ):
970
983
"""Enables library logging provided a logger object.
984
+
971
985
:param logger: A python logger pacakge.
972
986
:param log_level: Numeric value of a logging level, defaults to INFO.
973
987
0 commit comments